0Pricing
MCP Academy · Lektion

Tool-Aufrufe über ein LLM weiterleiten

Lassen Sie ein Modell entscheiden, welches Tool aufgerufen wird.

Tool-Aufrufe über ein LLM weiterleiten ist eine kostenlose MCP Academy-Lektion auf CoddyKit. Dies ist Lektion 4 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des MCP Academy-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der MCP Academy-Kurs umfasst insgesamt 4 Lektionen.

Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.

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.

Häufig gestellte Fragen

Ist die Lektion „Tool-Aufrufe über ein LLM weiterleiten“ kostenlos?

Ja — der vollständige Text von „Tool-Aufrufe über ein LLM weiterleiten“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des MCP Academy-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der MCP Academy-Kurs umfasst insgesamt 4 Lektionen.

Was lerne ich in „Tool-Aufrufe über ein LLM weiterleiten“?

Lassen Sie ein Modell entscheiden, welches Tool aufgerufen wird. Du übst MCP Academy mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.

Brauche ich Erfahrung, um MCP Academy zu starten?

Keine Vorkenntnisse erforderlich. MCP Academy auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 4 von 4.

Wie lange dauert die Lektion „Tool-Aufrufe über ein LLM weiterleiten“?

Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.

Kann ich in dieser MCP Academy-Lektion Code schreiben und ausführen?

Ja. Jede MCP Academy-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.

Alle Lektionen in diesem Kurs

  1. Eine Clientsitzung öffnen
  2. Tools und Ressourcen entdecken
  3. Tools aus Code aufrufen
  4. Tool-Aufrufe über ein LLM weiterleiten
← Zurück zu MCP Academy