0Pricing
MCP Academy · Aula

Erros de ferramentas visíveis para o modelo

Retorne erros que a IA possa ler e dos quais possa se recuperar.

Erros de ferramentas visíveis para o modelo é uma aula grátis de MCP Academy no CoddyKit. Esta é a aula 1 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.

Errors Are Just More Context

When a tool fails, the AI does not crash. It simply reads your error as context and decides what to do next, just like any result.

A Good Error Is Actionable

Write the error for a reader who can act on it. City not found beats Exception, because the model can ask the user to fix the city.

Return an Error String

The simplest pattern is returning a clear message string when something is wrong, so the model reads exactly what failed.

@mcp.tool()
def get_user(uid: int) -> str:
    if uid < 1:
        return "Error: uid must be positive."

Raise to Flag a Tool Error

You can also raise a normal Python exception. FastMCP catches it and reports a tool error back to the model, not a server crash.

@mcp.tool()
def divide(a: float, b: float) -> float:
    if b == 0:
        raise ValueError("b cannot be zero")
    return a / b

isError Marks the Result

Under the hood, a failed tool call returns content with isError set true. That flag tells the client this result describes a failure.

The Model Can Recover

A readable error lets the AI retry with better input or explain the issue to the user, turning a failure into a helpful next step. 🔁

Say What and Why

Good errors name what failed and why. File missing: report.csv is far more useful to the model than a bare Not found.

Suggest a Fix

When you can, hint at the remedy inside the error. Date must be YYYY-MM-DD lets the model correct itself on the very next call.

if not iso_date:
    raise ValueError("Date must be in YYYY-MM-DD format")

Never Leak Internals

Errors reach the model and often the user, so keep secrets, raw stack traces, and connection strings out of the message you return.

Validate, Then Error Early

Check arguments first and return the error before doing real work. Failing fast keeps your tool predictable and easy to reason about.

Errors Are Part of the Contract

Treat failures as designed output. A tool that names its likely errors is as useful to the model as one that documents its success.

Quick Check

Why write tool errors as clear, readable messages?

Recap

Tool errors are context the model reads: make them clear, say what and why, suggest a fix, and never leak internals. ✅

Perguntas Frequentes

A aula “Erros de ferramentas visíveis para o modelo” é grátis?

Sim — o texto completo de “Erros de ferramentas visíveis para o modelo” é 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 “Erros de ferramentas visíveis para o modelo”?

Retorne erros que a IA possa ler e dos quais possa se recuperar. 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 1 de 4.

Quanto tempo leva a aula “Erros de ferramentas visíveis para o modelo”?

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

  1. Erros de ferramentas visíveis para o modelo
  2. Erros de protocolo e falhas de ferramentas
  3. Validar entradas antes de agir
  4. Falhar com segurança, sem nunca travar
← Voltar para MCP Academy