Encaminhar chamadas de ferramentas por um LLM
Permita que um modelo decida qual ferramenta invocar.
Encaminhar chamadas de ferramentas por um LLM é uma aula grátis de MCP Academy no CoddyKit. Esta é a aula 4 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de MCP Academy, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de MCP Academy inclui 4 aulas no total.
Partes desta aula ainda não foram traduzidas e aparecem em inglês.
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.
Perguntas Frequentes
A aula “Encaminhar chamadas de ferramentas por um LLM” é grátis?
Sim — o texto completo de “Encaminhar chamadas de ferramentas por um LLM” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de MCP Academy, atualize para CoddyKit PRO. O curso de MCP Academy inclui 4 aulas no total.
O que vou aprender em “Encaminhar chamadas de ferramentas por um LLM”?
Permita que um modelo decida qual ferramenta invocar. Você pratica MCP Academy com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.
Preciso ter experiência prévia para começar MCP Academy?
Nenhuma experiência prévia é necessária. MCP Academy no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 4 de 4.
Quanto tempo leva a aula “Encaminhar chamadas de ferramentas por um LLM”?
A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.
Posso escrever e executar código nesta aula de MCP Academy?
Sim. Cada aula de MCP Academy inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.
Todas as aulas deste curso
- Abrir uma sessão de cliente
- Descobrir ferramentas e recursos
- Invocar ferramentas pelo código
- Encaminhar chamadas de ferramentas por um LLM