如何從 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.✓ 已複製→ 規格已輸出;快速測試呼叫成功
結果: 一個非 MCP 後端可以透過 HTTP 驅動的 MCP 伺服器。
注意事項
- 長時間執行的工具在預設 uvicorn 設定下逾時 — 傳入
--timeout-keep-alive 600給 mcpo,或使用具備相符逾時設定的 nginx 前端