ChatGPT MCP示例应用

一个使用OpenAI官方SDK的ChatGPT和模型上下文协议(MCP)的入门级示例应用,包含客户端和服务器功能。

  • by VicenteNoriega1
  • HTML
  • 本地部署
  • 更新于
在 GitHub 查看 VicenteNoriega1/hello-world-mcp

使用说明

你好世界mcp

最低限度 ChatGPT+模型上下文协议(MCP) hello world应用程序,适合使用官方OpenAI SDK的初学者。

包含内容

  • app.js –带有设置说明的主要入口点
  • chatgpt-client.js –直接调用OpenAI API的简单ChatGPT客户端
  • mcp-server.js –将ChatGPT作为工具公开的MCP服务器
  • package.json –依赖关系: openai, @modelcontextprotocol/sdk, dotenv
  • .env.example –环境变量模板

快速开始

1.安装依赖项

npm install

2.添加您的OpenAI API密钥

cp .env.example .env
# Edit .env and replace sk-your-api-key-here with your actual key
# Get your key from https://platform.openai.com/api-keys

3.运行应用程序

# Display setup info and available commands
npm start

# Run the ChatGPT client demo
npm run client

# Start the MCP server
npm run mcp-server

运作原理

ChatGPT客户端(chatgpt-client.js)

  • 使用 openai 软件开发工具包
  • 向Claude发送消息并接收回复
  • 有助于学习如何直接使用SDK

MCP服务器(mcp-server.js)

  • 作为模型上下文协议服务器运行
  • 暴露一个 ask_chatgpt 客户可以调用的工具
  • 通过stdio进行通信(非常适合Claude桌面应用程序集成)

后续步骤

  1. 获取API密钥 –注册地址:https://platform.openai.com
  2. 添加到 .env –将您的密钥复制到 OPENAI_API_KEY 变量
  3. 测试客户端 –跑步 npm run client 与ChatGPT聊天
  4. 探索MCP –跑步 npm run mcp-server 启动协议服务器

资源