Applied AI School
v0 · 規劃中
AnthropicOpenAI

Debug 技巧

MCP server / client 開發常見問題與排錯方法。

用 MCP Inspector

Anthropic 提供官方 inspector,可以直接連到你的 server,看 capabilities 與互動:

npx @modelcontextprotocol/inspector node ./ping-server.js

Inspector 會開一個瀏覽器視窗,列出所有 tools / resources / prompts,還能手動觸發呼叫。

觀察 stdio 訊息

stdio transport 的訊息是 JSON-RPC,可以加一層 wrapper 把進出訊息印到 stderr:

process.stderr.write(`>>> ${JSON.stringify(req)}\n`);

注意:千萬不要寫到 stdout,會破壞通訊。

常見錯誤

症狀可能原因
Server 啟動但 host 看不到stdout 有額外輸出汙染 protocol
Tool call 沒回應handler 沒回 content 欄位
Schema 錯誤inputSchema 不是合法 JSON Schema

(mock 內容)