Skip to content

[Bug]: compatibility problem between the mongo-mcp server implementation and the MCP SDK's #311

Closed
@ShivamSingh110

Description

@ShivamSingh110

Version

1.9.4

App

  • Cursor
  • Windsurf
  • VSCode
  • VSCode Insiders
  • Claude Desktop
  • Other

Affected Models (if applicable)

  • Claude 3.5 Sonnet
  • Claude 3.7 Sonnet
  • GPT-4a
  • o4-mini
  • Other

Bug Description

Summary

The mongo-mcp server returns tool responses in a format that is incompatible with the MCP SDK's expected CallToolResult schema, causing a Pydantic validation error when trying to use the server with standard MCP clients.

Environment

  • MCP SDK Version: Latest (as of June 2024)
  • mongo-mcp Version: Latest from npx
  • Python Version: 3.x
  • Platform: Windows/Linux/MacOS

Steps to Reproduce

  1. Set up a MongoDB connection (local or Atlas)
  2. Create an MCP client configuration:
{
  "mcpServers": {
    "mongodb": {
      "command": "npx",
      "args": [
        "mongo-mcp",
        "mongodb+srv://user:pass@cluster.mongodb.net/database"
      ]
    }
  }
}
  1. Use any MCP SDK-based client to connect and call a tool:
from mcp import ClientSession
# ... setup code ...
result = await session.call_tool("listCollections", {})

Expected Behavior

The tool call should return a valid CallToolResult object that the MCP SDK can process.

Actual Behavior

The call fails with a Pydantic validation error:

pydantic_core._pydantic_core.ValidationError: 1 validation error for CallToolResult
content
  Field required [type=missing, input_value={'toolResult': {'content'...]'}], 'isError': False}}, input_type=dict]

Root Cause Analysis

The mongo-mcp server returns responses in this format:

{
  "result": {
    "toolResult": {
      "content": "actual content here"
    },
    "isError": false
  }
}

But the MCP SDK expects this format:

{
  "content": [
    {
      "type": "text",
      "text": "actual content here"
    }
  ]
}

Debug Logs

From client debug output:

2025-06-24 00:02:52,339 - __main__ - ERROR - Error calling tool find: 1 validation error for CallToolResult
content
  Field required [type=missing, input_value={'toolResult': {'content'...]'}], 'isError': False}}, input_type=dict]

Workaround

Currently, the only workaround is to create a patched client session that intercepts and transforms the response:

class PatchedClientSession(ClientSession):
    async def call_tool(self, name: str, arguments: Dict[str, Any] = {}) -> CallToolResult:
        request = CallToolRequest(
            method="tools/call",
            params={"name": name, "arguments": arguments}
        )
        
        response = await self._send_request(request)
        
        # Transform mongo-mcp response to MCP SDK format
        if isinstance(response, dict) and 'result' in response:
            result_data = response['result']
            if 'toolResult' in result_data:
                content = result_data['toolResult'].get('content', '')
                return CallToolResult(content=[{"type": "text", "text": content}])
        
        # Fallback
        return CallToolResult(content=[{"type": "text", "text": str(response)}])

Proposed Solutions

  1. Update mongo-mcp server to return responses in the MCP SDK's expected format
  2. Add compatibility layer in the MCP SDK to handle different response formats
  3. Document the expected response format clearly in the MCP specification

Impact

This issue prevents any MCP SDK-based client from working with the mongo-mcp server, affecting all users trying to integrate MongoDB with MCP-compatible applications.

Additional Context

  • The issue affects all tool calls (listCollections, find, insertOne, etc.)
  • Other MCP servers (like mongodb-mcp-server) may use the correct format
  • This appears to be a protocol mismatch rather than a bug in either component

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions