0Pricing
MCP Academy · レッスン

LLM経由でツール呼び出しをルーティングする

モデルに呼び出すツールを判断させます。

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

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

Let the Model Decide

So far you chose which tool to call. The real power comes when you hand the decision to an LLM, letting the model pick the right tool for a request.

The Bridge Pattern

Your client becomes a bridge: it discovers MCP tools, describes them to the model, and runs whatever tool the model asks for.

Translate the Schemas

You convert each MCP tool name, description, and inputSchema into the tool format the model API expects, so the model can see its options.

tools = [
  {"name": t.name, "description": t.description,
   "input_schema": t.inputSchema}
  for t in listed.tools
]

Send Tools with the Prompt

You pass that tool list alongside the user message when you call the model. The model now knows exactly what actions are on the table.

msg = client.messages.create(
    model="claude-opus-4-8",
    max_tokens=1024,
    tools=tools,
    messages=messages,
)

The Model Requests a Tool

When the model wants an action, its reply contains a tool_use block with the tool name and the arguments it chose.

for block in msg.content:
    if block.type == "tool_use":
        ...

Run It Over MCP

You take that requested name and input and forward them to the server with call_tool, the same invocation you already know.

result = await session.call_tool(
    block.name, block.input)

Return the Result

Send the tool output back to the model as a tool_result so it can read what happened and continue reasoning.

tool_result = {"type": "tool_result",
  "tool_use_id": block.id,
  "content": result.content[0].text}

Loop Until Done

The model may call several tools in a row. You keep the loop running until it stops requesting tools and gives a final answer.

Two Protocols Meet

Your bridge speaks two languages: the model API for reasoning and MCP for tools. The client quietly translates between them.

Why Not Hardcode

Hardcoding tool choice does not scale. Letting the model route means new MCP servers add new abilities with no change to your logic.

Keep a Human in the Loop

For risky actions, pause before running the tool the model picked and ask the user to approve it first. Routing should not mean blind trust.

Quick Check

What does the model send when it wants your client to run a tool?

Recap: The Model in Charge

You wired up the full loop: describe MCP tools to an LLM, run the tool it picks via call_tool, return the result, and repeat until the answer is ready.

よくある質問

「LLM経由でツール呼び出しをルーティングする」レッスンは無料ですか?

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

「LLM経由でツール呼び出しをルーティングする」で何を学びますか?

モデルに呼び出すツールを判断させます。 ブラウザで直接実行するハンズオンコードでMCP Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

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

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

「LLM経由でツール呼び出しをルーティングする」レッスンにはどのくらい時間がかかりますか?

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

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

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

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

  1. クライアントセッションを開始する
  2. ツールとリソースを検出する
  3. コードからツールを呼び出す
  4. LLM経由でツール呼び出しをルーティングする
← MCP Academyに戻る