Skip to content

fix: return capabilities.tools as object in MCP initialize response#3501

Merged
springfall2008 merged 1 commit intomainfrom
fix/mcp-initialize-capabilities-tools
Mar 5, 2026
Merged

fix: return capabilities.tools as object in MCP initialize response#3501
springfall2008 merged 1 commit intomainfrom
fix/mcp-initialize-capabilities-tools

Conversation

@springfall2008
Copy link
Owner

Summary

Fixes #3496

The MCP initialize response was returning capabilities.tools as an array of tool objects (the result of tools/list) instead of an empty object {} as required by the MCP specification.

Strict MCP clients (e.g. Claude Desktop via mcp-remote using @modelcontextprotocol/sdk) validate against the spec and fail immediately with:

Connection error: $ZodError: [
  {
    "expected": "object",
    "code": "invalid_type",
    "path": ["capabilities", "tools"],
    "message": "Invalid input: expected object, received array"
  }
]

Fix

In _handle_initialize, removed the call to _handle_tools_list() and changed capabilities.tools to an empty object {}:

# Before
async def _handle_initialize(self, params):
    tools = await self._handle_tools_list(params)
    return {"protocolVersion": "2024-11-05", "capabilities": {"tools": tools["tools"]}, ...}

# After
async def _handle_initialize(self, params):
    return {"protocolVersion": "2024-11-05", "capabilities": {"tools": {}}, ...}

The tool list is correctly returned in response to tools/list requests — it does not belong in the initialize capabilities field.

The MCP specification requires capabilities.tools to be an object (e.g. {})
in the initialize response, not an array of tool objects. Strict MCP clients
such as Claude Desktop via mcp-remote validate against the spec and fail with:

  ZodError: expected object, received array (path: capabilities.tools)

Fix: remove the call to _handle_tools_list() from _handle_initialize() and
return capabilities.tools as an empty object {}. The tool list is correctly
returned in response to tools/list requests, not initialize.

Fixes #3496
Copilot AI review requested due to automatic review settings March 5, 2026 19:08
@springfall2008 springfall2008 merged commit 8cc474e into main Mar 5, 2026
1 check passed
@springfall2008 springfall2008 deleted the fix/mcp-initialize-capabilities-tools branch March 5, 2026 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP: initialize response returns capabilities.tools as array instead of object

1 participant