Retornar resultados úteis
Envie de volta um texto que o modelo e o usuário possam usar.
Retornar resultados úteis é uma aula grátis de MCP Academy no CoddyKit. Esta é a aula 3 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.
The Result Goes Back to the Model
Whatever your tool returns is fed back to the AI as context, so it shapes the model's next answer to the user. 🔁
Return a String
The simplest useful result is a plain string. FastMCP wraps it as text content the model reads directly.
@mcp.tool()
def greet(name: str) -> str:
return "Hello, " + nameMake Text Self-Explaining
The model has no other context, so your text should explain itself. Return The total is 42, not just 42.
Numbers Are Stringified
If you return an int or float, FastMCP converts it to text for you, but adding a label makes the value clearer to the model.
@mcp.tool()
def add(a: int, b: int) -> int:
return a + bReturn Structured Data
Return a dict or list and FastMCP serializes it to JSON, giving the model clean, parseable fields instead of loose prose.
@mcp.tool()
def stats() -> dict:
return {"users": 12, "active": 9}Keep Results Concise
Every returned token costs the model context budget, so trim your result to what actually answers the request. Less noise, sharper replies.
Format for Reading
When a result has parts, a little structure helps. Short labeled lines beat one long sentence the model has to untangle.
Return Errors as Text
When something goes wrong, returning a clear message lets the model explain the problem and try a fix, instead of guessing.
if not city:
return "Error: city is required."Don't Return Secrets
The result reaches the model and often the user, so never include secrets like API keys or raw passwords in what you return.
Consistent Shapes Help
Return the same shape every call so the model learns what to expect. Surprises in structure lead to misread answers.
Match the Tool's Promise
Your result should deliver exactly what the description promised. If you said it returns the price, return the price, not a whole report.
Quick Check
What happens when your tool returns a Python dict?
Recap
Your result becomes the model's context: return clear, concise, self-explaining text or JSON, keep shapes consistent, and never leak secrets. ✅
Perguntas Frequentes
A aula “Retornar resultados úteis” é grátis?
Sim — o texto completo de “Retornar resultados úteis” é 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 “Retornar resultados úteis”?
Envie de volta um texto que o modelo e o usuário possam usar. 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 3 de 4.
Quanto tempo leva a aula “Retornar resultados úteis”?
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
- Dê um bom nome e uma boa descrição à ferramenta
- Declarar parâmetros com dicas de tipo
- Retornar resultados úteis
- Uma ferramenta de calculadora, do início ao fim