0Pricing
MCP Academy · Урок

Маршрутизация вызовов инструментов через LLM

Позвольте модели решать, какой инструмент вызвать.

«Маршрутизация вызовов инструментов через LLM» — бесплатный урок MCP Academy на CoddyKit. Это урок 4 из 4. Ты можешь прочитать весь урок бесплатно ниже — а потом практиковать его прямо в браузере с встроенным редактором кода и ИИ-репетитором 24/7. Это часть пути обучения 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/7) и разблокировать остальной курс MCP Academy, подпишись на CoddyKit PRO. Курс MCP Academy содержит 4 уроков всего.

Чему я научусь в уроке «Маршрутизация вызовов инструментов через LLM»?

Позвольте модели решать, какой инструмент вызвать. Ты практикуешь MCP Academy с помощью реального кода, который запускаешь прямо в браузере, и ИИ-репетитор 24/7 отвечает на твои вопросы во время урока.

Нужен ли мне опыт, чтобы начать MCP Academy?

Предыдущий опыт не требуется. MCP Academy на CoddyKit структурирован для всех уровней — от новичков до продвинутых, поэтому ты можешь начать отсюда или с самого начала и учиться в своем темпе. Это урок 4 из 4.

Сколько времени занимает урок «Маршрутизация вызовов инструментов через LLM»?

Большинство уроков CoddyKit занимают около 5–10 минут. Каждый из них компактный и интерактивный, поэтому ты постоянно делаешь прогресс и продолжаешь с того же места в веб-версии и приложении.

Можно ли писать и запускать код в этом уроке MCP Academy?

Да. Каждый урок MCP Academy включает встроенный редактор кода, поэтому ты пишешь и запускаешь реальный код прямо в браузере и получаешь моментальную обратную связь от AI — локальная установка не требуется.

Все уроки этого курса

  1. Открытие сеанса клиента
  2. Обнаружение инструментов и ресурсов
  3. Вызов инструментов из кода
  4. Маршрутизация вызовов инструментов через LLM
← Назад к MCP Academy