Skip to main content
Glama
ChatGPT Orchestrator MCP Server

ChatGPT Orchestrator MCP Server

by vadimsey

ChatGPT Orchestrator MCP Server

用于以下架构的 Python 最小化远程 MCP 服务器:

ChatGPT -> MCP server -> main orchestrator -> helper agents

在第一阶段,服务器包含一个工具:

  • run_orchestrator

  • 输入:goal: string

  • 输出:简单的 JSON

目前内部是一个存根。稍后可以将其替换为您实际的主代理调用。

为什么选择 FastMCP

选择 FastMCP 是因为它允许使用普通的 Python 函数描述 MCP 工具,并立即通过 HTTP 启动远程 MCP 端点。要连接到 ChatGPT,需要一个类似 /mcp 的公共 HTTPS 端点。

Related MCP server: native-agent-router

项目结构

.
├── .gitignore
├── server.py
├── requirements.txt
├── Procfile
├── render.yaml
└── README.md

本地运行

要求:

  • Python 3.11+

  • pip

1. 创建虚拟环境

PowerShell:

python -m venv .venv
.\.venv\Scripts\Activate.ps1

如果 Windows 上的 python 命令打开 Microsoft Store 或未显示版本,请使用:

py -3.11 -m venv .venv
.\.venv\Scripts\Activate.ps1

macOS/Linux:

python3 -m venv .venv
source .venv/bin/activate

2. 安装依赖

pip install -r requirements.txt

3. 启动服务器

python server.py

本地 MCP 端点:

http://localhost:8000/mcp

检查服务器是否存活的常规检查:

http://localhost:8000/health

如果客户端要求末尾带有斜杠的端点,请使用:

http://localhost:8000/mcp/

本地测试

保持 python server.py 运行。在第二个终端中执行:

Invoke-RestMethod http://localhost:8000/health

预期响应:

{
  "status": "ok"
}

重要提示:如果在浏览器中打开 http://localhost:8000/mcp 或在没有 MCP 标头的情况下使用常规 curl 请求它,可能会看到错误:

{
  "error": {
    "message": "Not Acceptable: Client must accept text/event-stream"
  }
}

这对于 MCP 端点是正常的。请使用常规浏览器检查 /health,并使用 MCP 客户端检查 /mcp。

@'
import asyncio
from fastmcp import Client

async def main():
    async with Client("http://localhost:8000/mcp") as client:
        tools = await client.list_tools()
        print("TOOLS:")
        for tool in tools:
            print("-", tool.name)

        result = await client.call_tool(
            "run_orchestrator",
            {"goal": "Create an MVP launch plan"}
        )
        print("RESULT:")
        print(result)

asyncio.run(main())
'@ | python

预期的响应含义:服务器将显示 run_orchestrator 工具,并返回一个包含存根已接收任务文本的 JSON。

也可以通过 MCP Inspector 进行检查:

npx @modelcontextprotocol/inspector

在 UI 中选择传输方式 Streamable HTTP 和 URL:

http://localhost:8000/mcp

部署到 Render

通过 GitHub 部署

  1. 创建一个新的 GitHub 仓库。

  2. 将这些文件上传到那里。

  3. 打开 Render。

  4. 点击 New -> Web Service。

  5. 连接 GitHub 仓库。

  6. Render 通常会自动读取 render.yaml。

  7. 如果手动配置:

    • Runtime: Python

    • Build Command: pip install -r requirements.txt

    • Start Command: python server.py

  8. 点击 Deploy。

部署后,Render 将提供类似以下的 URL:

https://chatgpt-orchestrator-mcp.onrender.com

生产环境 MCP 端点将是:

https://chatgpt-orchestrator-mcp.onrender.com/mcp

用于浏览器检查的生产环境健康检查端点:

https://chatgpt-orchestrator-mcp.onrender.com/health

正是这个 URL 需要填入 ChatGPT。

如何连接到 ChatGPT

  1. 在浏览器中打开 ChatGPT。

  2. 进入 Settings。

  3. 打开 Apps & Connectors 或 Connectors。

  4. 如果尚未开启,请启用 Developer Mode:

    • Advanced settings

    • Developer mode

  5. 点击 Create 或 Create connector。

  6. 填写:

    • Name: Orchestrator

    • Description: Runs my main orchestrator agent through MCP.

    • Connector URL: https://YOUR-RENDER-SERVICE.onrender.com/mcp

  7. 保存。

  8. 在新聊天中选择此 connector/tool 并要求 ChatGPT 调用编排器。

ChatGPT 中的测试请求示例

Используй Orchestrator и вызови run_orchestrator с goal:
"Составь пошаговый план запуска MVP моего продукта"

工具目前的预期响应大约是:

{
  "status": "ok",
  "message": "Stub orchestrator accepted the goal.",
  "goal": "Составь пошаговый план запуска MVP моего продукта",
  "next_step": "Replace call_real_orchestrator() in server.py with your real agent call."
}

在何处将存根替换为真实代理

打开 server.py 并找到函数:

def call_real_orchestrator(goal: str) -> dict[str, Any]:

目前它返回测试 JSON。稍后将其主体替换为您主代理的实际调用。

未来替换示例:

def call_real_orchestrator(goal: str) -> dict[str, Any]:
    result = my_main_agent.run(goal)
    return {
        "status": "ok",
        "goal": goal,
        "result": result,
    }

重要提示:在第一阶段,不要为每个辅助代理创建单独的 MCP 服务器。让 ChatGPT 只看到一个 run_orchestrator 工具,而由您内部的主代理决定调用哪些辅助代理。

最终 URL

本地:

http://localhost:8000/mcp

生产环境 URL 模板:

https://YOUR-RENDER-SERVICE.onrender.com/mcp

ChatGPT 使用的 URL:

https://YOUR-RENDER-SERVICE.onrender.com/mcp

有用的官方文档

Related MCP Connectors

Related MCP Servers