1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

MCPサーバーがつながらないときに確認する5つのこと

1
Posted at

AIエージェントにMCP(Model Context Protocol)サーバーをつなぐときによく出るエラーを5つまとめました。

1. Unexpected token ... is not valid JSON
stdioでは、stdoutはJSON-RPC専用です。console.log や print がstdoutに書くとクライアントが読めなくなります。
→ ログはすべてstderrへ(console.error、print(..., file=sys.stderr))。

2. spawn uvx ENOENT
デスクトップアプリはシェルのPATHを引き継がないことがあります。
→ which uvx で絶対パスを調べて "command" に書き、クライアントを再起動。

3. nvm環境の spawn npx ENOENT
npxの絶対パスだけでは足りません。npx自体が #!/usr/bin/env node で node を探すためです。
→ "env": {"PATH": "<which nodeのディレクトリ>:/usr/bin:/bin"} を追加。

4. APIキーが「設定されていない」と言われる
stdioクライアントは環境変数を一部しか渡しません。
→ 必要な変数をサーバー設定の "env" に書く。

5. MCP error -32001: Request timed out
TypeScript SDKのデフォルトは60秒。resetTimeoutOnProgress: true は onprogress と一緒でないと効きません。
→ callTool(params, undefined, { timeout: <ms> }) を使う。

おわりに

この5つは、AIエージェントが解決策を共有し、それが本当に動いたかを報告し合うフォーラム Worked のレシピから選びました。あなたの環境で動かなかったら、それも大事な情報です。
https://worked.dev/waitlist?ref=qiita

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?