mcp服务器gpt聊天
用于OpenAI ChatGPT API的MCP(模型上下文协议)服务器。内置Rust,将聊天完成、视觉、嵌入和模型列表作为MCP工具公开。
与所有MCP服务器一样,使用JSON-RPC 2.0通过stdio进行通信。
工具
| 工具 | 说明 |
|---|---|
chat | 向ChatGPT发送聊天完成请求,其中包含可选的多回合历史记录、系统提示、结构化输出(JSON模式)和模型选择 |
chat_with_vision | 在给定图像URL和文本提示的情况下,使用ChatGPT的视觉功能分析图像 |
embedding | 使用OpenAI的嵌入模型生成文本嵌入 |
list_models | 列出所有可用的OpenAI模型及其ID |
聊天
发送聊天完成请求。通过JSON消息历史数组、系统提示、JSON模式的结构化输出、温度控制和模型选择支持多回合对话。
参数:
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
prompt | string | yes | 要发送的用户消息 |
model | string | no | 要使用的模型(默认值: gpt-4o) |
system_prompt | string | no | 设置上下文的系统提示 |
messages | string | no | 完整的对话历史记录为JSON数组 {role, content} 物体 |
temperature | 浮子 | 否 | 取样温度(0.0-2.0) |
max_tokens | integer | 否 | 要生成的最大令牌数 |
response_schema | string | no | 用于强制结构化输出的JSON模式字符串 |
聊天与视觉
使用ChatGPT的视觉功能分析图像。
参数:
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
prompt | string | yes | 描述要分析内容的文本提示 |
image_url | string | yes | 图像的URL(必须是http://或https://) |
model | string | no | 要使用的模型(默认值: gpt-4o) |
detail | string | no | 图像细节级别: low 或 high (默认值: high) |
temperature | 浮子 | 否 | 取样温度(0.0-2.0) |
max_tokens | integer | 否 | 要生成的最大令牌数 |
嵌入
生成文本嵌入。
参数:
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
input | string | yes | 要嵌入为JSON的文本:单个字符串或字符串数组 |
model | string | no | 要使用的嵌入模型(默认值: text-embedding-3-small) |
list_models
列出所有可用的OpenAI模型。没有参数。
先决条件
- 铁锈(2024年版)
- 来自的OpenAI API密钥 platform.openai.com
设置
创建配置文件:
mkdir -p ~/.config/mcp-server-gpt-chat创建 ~/.config/mcp-server-gpt-chat/config.toml:
api_key = "sk-..."构建
cargo build --release这产生 target/release/gpt-chat.
发展:
cargo build # debug build
cargo run # run in dev mode
RUST_LOG=debug cargo run # run with debug loggingMCP配置
添加到您的Claude桌面配置(~/.config/Claude/claude_desktop_config.json):
{
"mcpServers": {
"gpt-chat": {
"command": "/path/to/gpt-chat"
}
}
}项目结构
src/
main.rs - entry point, config loading, stdio transport setup
server.rs - MCP tool definitions (chat, chat_with_vision, embedding, list_models)
api.rs - OpenAI HTTP client, request/response types, response formatters
params.rs - tool parameter types with serde and JSON Schema derives
config.rs - TOML config loading许可证
麻省理工学院
