Skip to content

[BUG]: outputSchema validation not skipped for isError:true tool results, hiding actual error messages #4135

@kimsehwan96

Description

@kimsehwan96

🐞 Bug Summary

When an upstream MCP server returns a tool execution error (isError: true), the gateway still attempts to validate the error response against the tool's outputSchema. Since error responses naturally don't conform to the success schema, the original error message (e.g., "Workflow is not available in MCP") is replaced with a generic "Output validation error: outputSchema defined but no structured output returned", hiding the actual error cause from the user.


🧩 Affected Component

Select the area of the project impacted:

  • mcpgateway - API
  • mcpgateway - UI (admin panel)
  • mcpgateway.wrapper - stdio wrapper
  • Federation or Transports
  • CLI, Makefiles, or shell scripts
  • Container setup (Docker/Podman/Compose)
  • Other (explain below)

🔁 Steps to Reproduce

  1. Register an upstream MCP server that defines outputSchema on its tools (e.g., n8n Instance-level MCP server)
  2. Call a tool that returns an error response with isError: true and a text content error message — for example, calling get_workflow_details on a workflow that has MCP access disabled
  3. The upstream server responds with:
  {
    "result": {
      "content": [{"type": "text", "text": "Workflow is not available in MCP. Enable MCP access in workflow settings."}],
      "isError": true
    }
  }
  1. Instead of passing through this error message, the gateway returns: "Output validation error: outputSchema defined but no structured output returned"

🤔 Expected Behavior

When isError: true is set in the tool result, outputSchema validation should be skipped entirely and the original error content should be passed through to the client as-is. Per the MCP spec, outputSchema defines the expected structure for successful tool results, not error responses.


📓 Logs / Error Output

  # Gateway logs show MCP call succeeds but tool invocation is marked as failed:
  [tool_service] MCP tool call completed: get_workflow_details  (success: true)
  [tool_service] Tool 'n8n-get-workflow-details' invocation failed  (error_message: null)

The issue is in mcpgateway/services/tool_service.py, method _extract_and_validate_structured_content() (around line 1111). The method checks for output_schema presence but does not check tool_result.is_error before proceeding with validation.


🧠 Environment Info

You can retrieve most of this from the /version endpoint.

Key Value
Version or commit latest main
Runtime Python3.12
Platform / OS Linux
Container Docker

🧩 Additional Context (optional)

  • This affects any upstream MCP server that defines outputSchema and can return tool execution errors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtriageIssues / Features awaiting triage

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions