Skip to content

Failed API calls should not be failures, not errors #420

Closed

Description

@SamMorrowDrums

An example:

return nil, fmt.Errorf("failed to get user: %w", err)

As discussed here and here in general failures of this kind are not to be returned as errors, but instead returned as failed tool calls.

Activity

  1. KashifManzer commented on Jul 18, 2025

    @KashifManzer

    Can I work on it, if it's still open?

  2. mohamedaminehamdi commented on Aug 4, 2025

    @mohamedaminehamdi

    Can i work on it ??

  3. Abhinav072004 commented on Aug 20, 2025

    @Abhinav072004

    Fix: Return failed tool calls (in-band isError) instead of protocol errors from tool handlers

    Tool-level failures (e.g., GitHub API/user lookup/auth scope issues) should be returned as CallToolResult with isError: true, not as non-nil Go errors. This matches MCP guidance and lets the client/LLM see and handle failures.

    Replace fmt.Errorf("failed to get user: %w", err) with mcp.NewToolResultErrorFromErr(...) and nil error.

    Add tiny helper toolErr(...) for consistency across handlers.

    References: mcp-go docs on CallToolResult error handling; maintainer guidance on when (rarely) to return non-nil errors; tracking issue #420.
    Go Packages
    GitHub
    +1(mark3labs/mcp-go#294)
    Want me to draft a full diff touching other handlers with the same pattern (grep for fmt.Errorf( in tool handlers) and a unit test update block?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions