Skip to content

fix(mcp): connect to servers without tool capabilities - #6019

Merged
Re-bin merged 1 commit into
HKUDS:mainfrom
pei711:fix/mcp-optional-tools
Oct 18, 2026
Merged

Re-bin merged 1 commit into
HKUDS:mainfrom
pei711:fix/mcp-optional-tools

Conversation

@pei711

@pei711 pei711 commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

connect_mcp_servers() always calls tools/list after initialization. A valid server that exposes only resources or prompts advertises no tools capability and can reject that request with Method not found, aborting the connection before its resources or prompts are discovered.

Only request tool discovery when the initialize result advertises the tools capability. Existing tool pagination and advertised-tool failure handling remain intact, while resource-only and prompt-only servers can reach their existing discovery paths.

Validation:

  • Both new regression scenarios failed on the original implementation.
  • MCP test module: 116 passed.
  • uv run --no-sync pytest tests/tools tests/agent/test_mcp_connection.py tests/agent/test_mcp_reconnect_crash.py tests/agent/test_mcp_transient_retry.py -q: 1140 passed, 66 skipped on Windows / Python 3.13.
  • Ruff, strict BasedPyright for the production module, and git diff --check passed.
  • A separate offline protocol check used MCP SDK 1.30.0's real Server and ClientSession over in-memory streams. Resource-only and prompt-only servers both failed to connect before the fix; afterward both connected and their registered wrappers executed successfully. Only the stdio transport factory was replaced.

AI assistance: Codex assisted with implementation, regression tests, and local verification.

@chengyongru chengyongru added bug Something isn't working fix priority: p2 Normal backlog: minor bug, enhancement, docs, cleanup, edge case, or unvalidated proposal. test labels Oct 3, 2026
@Re-bin
Re-bin force-pushed the fix/mcp-optional-tools branch from fd4da3c to 99c6770 Compare October 3, 2026 15:12
@Re-bin
Re-bin force-pushed the fix/mcp-optional-tools branch from 99c6770 to ca3c855 Compare October 18, 2026 05:46
@Re-bin
Re-bin force-pushed the fix/mcp-optional-tools branch from ca3c855 to db5839e Compare October 18, 2026 12:55

@Re-bin Re-bin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resource-only and prompt-only MCP servers can now connect without an unsupported tools/list call. Initialization capabilities are authoritative; servers advertising tools retain the existing pagination and registration path. Protocol-shaped fixtures and the real-SDK combined checks cover the capability boundary. Existing toolsets and schemas are unchanged, but newly usable catalogs necessarily add tools when connected, so zero cache impact is not claimed for that first expansion. No configuration or stored-data migration.

Fresh final-base MCP/connection/tool-validation tests: 294 passed; exact-head CI passed on its first execution. Independent main Windows timeout observations are retained in the review record and are not claimed fixed by this MCP change; merge remains gated on green main checks as well.

@Re-bin
Re-bin merged commit a377a8e into HKUDS:main Oct 18, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working fix priority: p2 Normal backlog: minor bug, enhancement, docs, cleanup, edge case, or unvalidated proposal. test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants