Skip to content

MCP middleware swallows tool errors — outputSchema validation hides real error messages #459

@mrjasonroy

Description

@mrjasonroy

Problem

When a tool throws an exception, the middleware in databricks-mcp-server/databricks_mcp_server/middleware.py catches it and returns a ToolResult without structured_content. Because the tool has an outputSchema (auto-generated by FastMCP from return type annotations), the MCP SDK validation rejects the response with:

Output validation error: outputSchema defined but no structured output returned

This replaces the actual error message with a generic validation error, making debugging impossible. The user never sees the real exception.

Example

# execute_sql with a SQL syntax the Databricks API doesn't support
SELECT name FROM (LIST 's3://bucket/prefix/') WHERE name LIKE '%2026%'

Instead of seeing the actual SQL error, we get:

Output validation error: outputSchema defined but no structured output returned

Root Cause

PR #411 (beb7be5) attempted to fix this but hit a circular problem:

  1. Adding structured_content to error responses → MCP SDK validates the error dict against the tool's outputSchema → fails because error shape doesn't match return type
  2. Omitting structured_content from error responses → MCP SDK rejects because outputSchema exists but no structured output → generic error shown

The current code (v0.1.9) takes approach #2, which avoids crashes but swallows the real error.

Suggested Fix

Option A: Remove outputSchema from tool definitions entirely (tools can still return structured data without declaring a schema).

Option B: Define an error-aware outputSchema that accepts either the success type OR an error envelope via anyOf/oneOf.

Option C: Use isError=True on the ToolResult to signal the MCP SDK to skip outputSchema validation for error responses (if supported).

Impact

This affects every tool in the MCP server that has a return type annotation. Any exception is silently swallowed and replaced with the generic validation error. We've been debugging SQL queries, S3 operations, and job runs with zero visibility into actual failures.

Environment

  • ai-dev-kit: v0.1.9
  • fastmcp: 3.1.1 (also tested 3.2.3)
  • mcp: 1.26.0 (also tested 1.27.0)
  • Python: 3.11.14
  • Claude Code (CLI)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions