0Pricing
MCP Academy · Lekcja

Kierowanie wywołań narzędzi przez LLM

Pozwól modelowi zdecydować, które narzędzie wywołać.

Kierowanie wywołań narzędzi przez LLM to bezpłatna lekcja MCP Academy na CoddyKit. To lekcja 4 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej MCP Academy, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs MCP Academy zawiera 4 lekcji w sumie.

Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.

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.

Często zadawane pytania

Czy lekcja „Kierowanie wywołań narzędzi przez LLM” jest bezpłatna?

Tak — pełny tekst „Kierowanie wywołań narzędzi przez LLM” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu MCP Academy, przejdź na CoddyKit PRO. Kurs MCP Academy zawiera 4 lekcji w sumie.

Co nauczysz się w „Kierowanie wywołań narzędzi przez LLM”?

Pozwól modelowi zdecydować, które narzędzie wywołać. Ćwiczysz MCP Academy z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.

Czy potrzebuję doświadczenia, aby zacząć MCP Academy?

Nie wymagamy żadnego doświadczenia. MCP Academy w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 4 z 4.

Ile czasu zajmuje lekcja „Kierowanie wywołań narzędzi przez LLM”?

Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.

Czy mogę pisać i uruchamiać kod w tej lekcji MCP Academy?

Tak. Każda lekcja MCP Academy zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.

Wszystkie lekcje w tym kursie

  1. Otwieranie sesji klienta
  2. Wykrywanie narzędzi i zasobów
  3. Wywoływanie narzędzi z kodu
  4. Kierowanie wywołań narzędzi przez LLM
← Powrót do MCP Academy