0Pricing
MCP Academy · レッスン

プロトコルエラーとツールの失敗

トランスポートの障害とビジネスロジックのエラーを区別します。

「プロトコルエラーとツールの失敗」はCoddyKit上の無料MCP Academyレッスンです。 これはレッスン2/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはMCP Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 MCP Academyコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

Two Very Different Failures

MCP has two kinds of failure: a protocol error in the wire itself, and a tool failure inside your business logic. They are handled differently.

Protocol Errors Live in JSON-RPC

A protocol error means the message could not be processed at all, like an unknown method or malformed params. It rides in the JSON-RPC error field.

{"jsonrpc": "2.0", "id": 7,
 "error": {"code": -32601,
           "message": "Method not found"}}

Tool Failures Live in the Result

A tool failure means the call reached your function but the work went wrong. It returns a normal result marked with isError true.

Why the Split Matters

The model should see and react to tool failures, but protocol errors usually signal a bug the client must handle, not something the AI can retry.

Standard JSON-RPC Codes

Protocol codes are negative and standardized: -32601 is method not found, -32602 is invalid params, -32700 is a parse error.

Tool Failures Reach the Model

Because a tool failure is just a result, the model reads it as context and can decide to retry, adjust input, or explain it. 🔁

Raising Inside a Tool

When you raise an exception in a tool, FastMCP turns it into a tool failure result, not a protocol error. Your server keeps running.

@mcp.tool()
def fetch(url: str) -> str:
    if not url.startswith("http"):
        raise ValueError("url must be http")

Unknown Tool Is Protocol-Level

If a client asks for a tool that does not exist, that is a protocol error. The request never reaches any function of yours.

Bad Arguments Can Be Either

Schema-level type mismatches surface as a protocol invalid-params error, while a valid type with a bad value is best a tool failure.

Match Failure to Audience

Ask who should react. If the model can fix it, make it a tool failure. If only the developer can, a protocol error is right.

Keep Transport Healthy

Never let business problems leak out as protocol errors. Doing so confuses clients and can tear down a session that should keep going.

Quick Check

Where does a failure inside your tool function get reported?

Recap

Protocol errors mean the message itself failed; tool failures mean your logic failed. Route each to who can act on it and keep transport healthy. ✅

よくある質問

「プロトコルエラーとツールの失敗」レッスンは無料ですか?

はい。「プロトコルエラーとツールの失敗」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、MCP Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 MCP Academyコースには全4レッスンが含まれています。

「プロトコルエラーとツールの失敗」で何を学びますか?

トランスポートの障害とビジネスロジックのエラーを区別します。 ブラウザで直接実行するハンズオンコードでMCP Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

MCP Academyを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのMCP Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン2/4です。

「プロトコルエラーとツールの失敗」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このMCP Academyレッスンでコードを書いて実行できますか?

はい。すべてのMCP Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. モデルが認識できるツールエラー
  2. プロトコルエラーとツールの失敗
  3. 実行前に入力を検証する
  4. 安全に失敗させ、ハングさせない
← MCP Academyに戻る