如何从 curl / Postman / OpenAI function-calling 调用 MCP 服务器
何时使用: 你选了一个很好的 MCP 服务器,但生产栈是 Python 服务 / OpenAI Assistants API / 需要 HTTP+JSON 的东西。
前置条件
- 一个通常会直接启动的 MCP 命令 — 例如
uvx mcp-server-time或npx -y @modelcontextprotocol/server-fetch
步骤
-
封装Run
uvx mcpo --port 8000 -- uvx mcp-server-timeand confirm /docs is up.✓ 已复制→ Swagger UI 将工具显示为端点 -
用 curl 调用Show me a working curl that calls the time tool with timezone=America/Los_Angeles.✓ 已复制→ 返回当前时间 + 时区信息
-
接入 OpenAIGenerate a function-calling spec from /openapi.json that I can paste into the OpenAI API.✓ 已复制→ spec 已生成;快速测试调用成功
结果: 一个非 MCP 后端可以通过 HTTP 驱动的 MCP 服务器。
注意事项
- 长时间运行的工具在默认 uvicorn 设置下超时 — 向 mcpo 传入
--timeout-keep-alive 600,或在前面加一层超时设置匹配的 nginx