mcp server for querying chatgpt (chatgpt.com) via webui session token (the image above was generated with this!)
______________________________________________________________________
快速开始
从npm安装:
npm i -g chatgpt-webui-mcp手动运行:
CHATGPT_SESSION_TOKEN="your_token_here" chatgpt-webui-mcp来源:
npm install
npm run build
CHATGPT_SESSION_TOKEN="your_token_here" node dist/index.js重要提示:这使用了chatgpt的内部webuiapi和会话cookie。仅用于个人/本地修补-与openai无关。
______________________________________________________________________
概述
chatgpt-webui-mcp是一个独立的mcp服务器,通过以下方式驱动chatgpt.com camofox (UI自动化)。
它是为长时间运行的任务(gpt-5.2pro运行需要1小时以上)、深入研究和图像生成模式而构建的。
______________________________________________________________________
获取会话令牌
- 打开https://chatgpt.com并登录
- 打开开发工具
- 应用程序->Cookie->
https://chatgpt.com - 复制值
__Secure-next-auth.session-token
______________________________________________________________________
配置
因为此服务器使用 stdio 或 sse,将其配置为本地命令(或远程url),并通过env传递令牌。
mcp客户端配置(claude桌面、opencode等)
{
"mcpServers": {
"chatgpt-webui": {
"command": "node",
"args": ["/absolute/path/to/chatgpt-webui-mcp/dist/index.js"],
"timeout": 7200000,
"env": {
"CHATGPT_SESSION_TOKEN_FILE": "/path/to/session-token.txt",
"CHATGPT_BROWSER_BASE_URL": "http://127.0.0.1:9377",
"CHATGPT_WAIT_TIMEOUT_MS": "7200000"
}
}
}
}遗产 CHATGPT_CAMOFOX_* 为了兼容性,仍然支持env-vars。 CHATGPT_TRANSPORT=httpcloak 故意不受支持(使用camofox)。 当省略模型/思维时,请求默认为 gpt-5-2 (自动),不是专业。
______________________________________________________________________
开放代码工作流(自然语言风格)
如果你想键入以下命令:
- `with chatgpt webui on gpt 5.2 pro extended thinking:
`
do deepresearch with chatgpt webui on
使用此工具:
| 工具 | 它做什么 |
|---|---|
chatgpt_webui_command | 将句子解析为正确的调用并运行它 |
例子:
{
"name": "chatgpt_webui_command",
"arguments": {
"command": "with chatgpt webui on gpt 5.2 pro extended thinking: write a 1-page memo about X",
"mode": "auto"
}
}______________________________________________________________________
长跑(推荐)
使用统一的工具:
| 工具 | 描述 |
|---|---|
chatgpt_webui_prompt | 主要工具。 mode=auto 选择等待与背景 |
chatgpt_webui_run | 检查/等待后台运行(run_id) |
原因:深入研究和gpt-5.2pro可能需要很长时间,甚至可能超过一个客户端超时。 mode=auto 返回a run_id 长期工作。
______________________________________________________________________
图像生成
集 create_image=true 在发送提示之前,将chatgpt切换到图像生成模式。
笔记:
image_urls是尽力而为(来自页面链接+访问过的url),根据chatgpt在webui中呈现图像的方式,可能为空。- 回退屏幕截图输出在中返回
image_data_url(不是image_urls)启用并限制大小时。 - 启用回退
CHATGPT_IMAGE_SCREENSHOT_FALLBACK=1. - 上限回退大小
CHATGPT_IMAGE_SCREENSHOT_MAX_BYTES(默认值2097152,2 MiB)。 - 为了获得可靠的检索,您还可以使用convention_id并打开chatgpt UI。
______________________________________________________________________
自检
# env
CHATGPT_SESSION_TOKEN="your_token_here" npm run self-test
# cli flag
npm run self-test -- --token "your_token_here"
# file
echo "your_token_here" > ~/.config/chatgpt-webui-mcp/session-token.txt
npm run self-test -- --token-file ~/.config/chatgpt-webui-mcp/session-token.txt______________________________________________________________________
尾秤远程部署(可选)
如果您希望后台运行能够长时间运行,请将此服务器作为始终在线的SSE服务运行。
- 从该仓库复制模板:
deploy/systemd/chatgpt-webui-mcp.env.exampledeploy/systemd/chatgpt-webui-mcp-sse.shdeploy/systemd/chatgpt-webui-mcp.service
- 安装并启用服务(用户服务):
mkdir -p ~/.config ~/.config/systemd/user ~/.local/bin ~/.local/share/chatgpt-webui-mcp
cp deploy/systemd/chatgpt-webui-mcp.env.example ~/.config/chatgpt-webui-mcp.env
cp deploy/systemd/chatgpt-webui-mcp-sse.sh ~/.local/bin/chatgpt-webui-mcp-sse.sh
cp deploy/systemd/chatgpt-webui-mcp.service ~/.config/systemd/user/chatgpt-webui-mcp.service
chmod 600 ~/.config/chatgpt-webui-mcp.env
chmod 755 ~/.local/bin/chatgpt-webui-mcp-sse.sh
systemctl --user daemon-reload
systemctl --user enable --now chatgpt-webui-mcp.service- 将opencode(云主机)指向端点:
{
"mcp": {
"chatgpt-webui": {
"type": "remote",
"url": "http://:8791/sse",
"enabled": true,
"timeout": 7200000,
"oauth": false
}
}
}______________________________________________________________________
工具
| 工具 | 描述 |
|---|---|
chatgpt_webui_session | 验证令牌并返回会话有效负载 |
chatgpt_webui_models | 列出可用型号 |
chatgpt_webui_command | 自然语言命令包装器 |
chatgpt_webui_prompt | 统一提示工具(等待/后台) |
chatgpt_webui_run | 检查/等待后台运行 |
chatgpt_webui_ask | 直接等待式提示工具(传统/简单) |
______________________________________________________________________
项目结构
chatgpt-webui-mcp/
├── deploy/
│ └── systemd/
│ ├── chatgpt-webui-mcp.env.example
│ ├── chatgpt-webui-mcp-sse.sh
│ └── chatgpt-webui-mcp.service
├── src/
│ ├── index.ts # MCP server
│ └── chatgpt-webui-client.ts # WebUI automation client
├── package.json
├── tsconfig.json
├── .env.example
├── .gitignore
├── LICENSE
├── INSTALL.md
└── README.md______________________________________________________________________
许可证
麻省理工学院
______________________________________________________________________
