fix(mcp): treat empty capability objects as present; declare keyring - #960
Merged
agentforce314 merged 1 commit intoOct 4, 2026
Merged
Conversation
`initialize` results are parsed with `bool(caps.get("tools"))`, but the MCP
spec models capability members as *objects* whose presence signals support
and whose contents are optional. A server advertising `{"tools": {}}` is
therefore read as having no tools, and `list_tools()` returns `[]` — hiding
every tool the server actually exposes. Verified against a live server that
advertises 89 tools and exposed none.
Test the presence of the member rather than its truthiness, for `tools`,
`prompts` and `resources` alike. The nested `listChanged` sub-flag keeps its
existing `isinstance` guard, so the refresh wiring is unaffected.
Also declares two runtime dependencies that were being imported without
being listed:
- `keyring`, the OS keychain backing `McpTokenStore` in
`services/mcp/auth.py`. `auth.py`'s backend allowlist is already written
against keyring 25.x class names, but the package was absent from
`dependencies`, so token storage failed closed and 27 MCP tests errored.
Backends resolve at runtime and `PlaintextKeyring` is explicitly rejected,
so the package alone degrades to "no secure storage", not to leaking.
- `exceptiongroup`, on Python < 3.11 only. anyio raises this backport rather
than the 3.11 builtin, so `_unwrap_exception_group_message` guarded only
with `except NameError` returned `str(exc)` — i.e. exactly the opaque
"unhandled errors in a TaskGroup" text the function exists to strip.
Adds a regression test covering the empty-capability case, and updates the
adjacent comment that documented the old behaviour as a known quirk.
Test Results 5 files 1 021 suites 21m 59s ⏱️ For more details on these failures, see this check. Results for commit 796aa32. |
Owner
|
LGTM. Thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
An MCP server that advertises
{"tools": {}}is silently reported as having no tools, andlist_tools()returns[]— every tool the server exposes is hidden.The MCP spec models capability members as objects whose presence signals support and whose contents are optional.
_parse_server_capabilitiescollapsed them withbool(), andbool({})isFalse.Observed against a live server advertising 89 tools, of which ClawCodex surfaced 0. A sibling server advertising
{"tools": {"listChanged": false}}worked purely because that dict happens to be truthy.Root cause
Fix
Test presence, not truthiness, for all three capabilities. The nested
listChangedsub-flag keeps its existingisinstance(tools_cap, dict)guard, so the ch15 refresh wiring is unchanged.Second issue: undeclared runtime dependencies
Two packages were imported by
src/but missing fromdependencies:keyring— the OS keychain backingMcpTokenStoreinservices/mcp/auth.py. The backend allowlist inauth.pyis already written against keyring 25.x class names, so the dependency was clearly intended; without it, token storage failed closed and 27 MCP tests errored at collection.exceptiongroup(Python < 3.11) — anyio raises this backport, not the 3.11 builtin._unwrap_exception_group_messageguarded only withexcept NameError, so on 3.10 it returnedstr(exc)— literally the opaque"unhandled errors in a TaskGroup (1 sub-exception)"text the function exists to strip.Verification
AssertionError: False is not true), passes on the new.Behavioural note for reviewers
This changes how every MCP server is interpreted: a server advertising
{"tools": {}}now loads its tools instead of none. That is the spec-correct reading, but it is a deliberate behaviour change, hence the explicit call-out rather than a silent fix.Note on Python 3.10
requires-python = ">=3.10"but CI only runs 3.11, so 3.10 is effectively unverified today. Theexceptiongroupfix above matters specifically on 3.10. Worth considering a 3.10 CI leg or narrowing the floor — happy to follow up separately.