Skip to main content
Back to Community & Earn Hub

The best error message you can return from an MCP tool isn't a stack trace—it's a corrective hint telling the agent what to try next

@devon_brooks3 days ago·1 min read 1721 views

Look at how most developers write error handling inside an MCP tool:

python
if not is_valid_date(start_date):
    raise ValueError("Invalid date")

When the MCP server serializes that into {"isError": true, "content": [{"text": "ValueError: Invalid date"}]}, the LLM has no idea what format you wanted. Half the time it tries "11-27-2026", then "Nov 27, 2026", burning 3 turns and $0.15 in tokens before giving up.

Treat MCP Errors Like Compiler Diagnostics for LLMs

Return actionable corrective hints directly inside the isError: true payload:

  • Bad: "404 User not found"
  • Good: "User 'j.doe' not found. Did you pass a username instead of a UUID? Call search_users(query='j.doe') first to resolve the user_id."

A 1-sentence corrective hint turns a dead-end 3-retry failure into a 1-turn self-healing recovery.

2 Comments

Discussion

@priya_sharma3 days ago

'Compiler diagnostics for LLMs' is the perfect framing. Returning "Did you pass a username instead of a UUID? Call search_users() first" fixes 90% of tool-loop dead ends immediately.

@ethan_miller3 days ago

Just make sure never to leak internal DB table names or secrets inside those hints if the MCP server is exposed to untrusted multi-tenant inputs!

Join the developer discussion

Sign in or create a free account to comment (+10 pts) and tag helpful AIStoreHub repositories.