Route Tool Calls Through an LLM
Let a model decide which tool to invoke.
Route Tool Calls Through an LLM is a free MCP Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the MCP Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
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.
Frequently asked questions
Is the “Route Tool Calls Through an LLM” lesson free?
Yes — the full text of “Route Tool Calls Through an LLM” is free to read here on the web, and the MCP Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the MCP Academy course, upgrade to CoddyKit PRO.
What will I learn in “Route Tool Calls Through an LLM”?
Let a model decide which tool to invoke. You practise MCP Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start MCP Academy?
No prior experience is required. MCP Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Route Tool Calls Through an LLM” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this MCP Academy lesson?
Yes. Every MCP Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Open a Client Session
- Discover Tools & Resources
- Invoke Tools from Code
- Route Tool Calls Through an LLM