Skip to content

Attach tool annotations on mcp 1.x, not just mcp 2.x - #189

Merged
rajeeja merged 1 commit into
mainfrom
fix-annotations-at-mcp-floor
Oct 20, 2026
Merged

rajeeja merged 1 commit into
mainfrom
fix-annotations-at-mcp-floor

Conversation

@rajeeja

@rajeeja rajeeja commented Oct 19, 2026

Copy link
Copy Markdown
Collaborator

Fixes the Upstream Compatibility / declared floor versions job, which has
been red on tests/test_mcp_protocol.py::TestToolAnnotations::test_a_pure_query_is_marked_read_only
with KeyError: 'annotations'.

The test was right. At our declared floor of mcp 1.27, the annotation shim
from #178 attached nothing at all, so every tool was served with no annotations.
Normal CI resolves to mcp 2.3 and never saw it. This is the bad direction for
this particular feature: readOnlyHint is what a client reads to decide what it
can auto-approve, and it was missing exactly where we document it as present.

Three SDK differences, each independently fatal

mcp 1.x (our floor) mcp 2.x (what CI resolves)
handler dict key ListToolsRequest (the type) "tools/list" (a string)
handler return ServerResult envelope, tools under .root the result directly
dict attribute request_handlers _request_handlers

We looked up only the string key, so on the floor the shim found nothing and
returned the server untouched. Fixing just that got the handler wrapped but
still annotated nothing, because iterating .tools on the envelope yields
nothing — it looked like it had worked. The third was already handled.

Tests

TestTheShimFindsTheHandlerOnEitherSDK drives the shim with a string key, a
type key, and an envelope result, using stand-in objects so both branches are
exercised whichever SDK is installed — the type-keyed path is otherwise only
reachable in the weekly floor job. They assert on the by-alias dump, since the
Python attribute is readOnlyHint on one SDK and read_only_hint on the other
while the wire name is the same either way.

Reverting any one of the two fixes fails at least one of them (verified).

Results

Floor environment, resolved exactly as the workflow does
(uv sync --dev --resolution lowest-direct → mcp 1.27.0, toolregistry 0.18.0):

1508 passed, 1 skipped, 44 deselected, 1 xfailed    # was 1 failed

Current resolve: 1546 passed, 7 skipped, 1 xfailed.

Branches off main, independent of #188.

The weekly floor job has been failing on
`test_a_pure_query_is_marked_read_only` with `KeyError: 'annotations'`.
It was right: at our declared floor of mcp 1.27 the annotation shim
attached nothing, so every tool went out with no hints at all. Normal CI
resolves to mcp 2.3 and never saw it. The hints a client reads to decide
what it may auto-approve were absent exactly where we document them as
present, which is the failure direction that matters.

Three differences between the SDKs, each of which alone was enough:

- mcp 2.x keys the handler dict by method string, `"tools/list"`; mcp 1.x
  keys it by request type, `ListToolsRequest`. We looked up only the
  string, found nothing, and returned the server untouched.
- mcp 1.x returns a `ServerResult` envelope whose `.root` holds the
  `ListToolsResult`; mcp 2.x returns the result directly. Iterating
  `.tools` on the envelope yields nothing, so even once the handler was
  wrapped it annotated no tool while looking like it had worked.
- The attribute holding the dict is public `request_handlers` on 1.x and
  `_request_handlers` on 2.x. That one was already handled.

The regression tests drive the shim with both keying schemes and with an
envelope result, so neither branch depends on which SDK happens to be
installed; they assert on the by-alias dump because the Python attribute
is `readOnlyHint` on one SDK and `read_only_hint` on the other, while the
wire name a client sees is the same either way. Reverting any single fix
above fails at least one of them.

Floor suite, resolved as the workflow does with
`--resolution lowest-direct` (mcp 1.27.0, toolregistry 0.18.0):
1508 passed, 1 skipped, 44 deselected, 1 xfailed. Was 1 failed.
Current resolve: 1546 passed, 7 skipped, 1 xfailed.
@rajeeja

rajeeja commented Oct 20, 2026

Copy link
Copy Markdown
Collaborator Author

Confirmed on CI, not just locally.

Dispatched Upstream Compatibility against this branch (run 39345440005):

  • declared floor versions: green. That is the job this PR fixes; it had been failing on KeyError: 'annotations' since the annotations shim landed.
  • latest all: fails, but on test_the_installed_uxarray_meets_the_declared_floor — the guard correctly objecting that this branch still carries <2026.10 while the job installs uxarray 2026.10.0. That is Move the uxarray floor to 2026.10.0 #188's job, not this one.

The mirror run on #188 (39346277461) shows the complement: every latest * job green, declared floor versions still red on the annotations KeyError.

So the two PRs fix disjoint halves of the same red workflow and neither is sufficient alone. With both applied, the floor environment resolved as the workflow does (mcp 1.27.0, toolregistry 0.18.0, uxarray 2026.10.0) gives 1508 passed, 1 skipped, 44 deselected, 1 xfailed.

@rajeeja
rajeeja merged commit ae61752 into main Oct 20, 2026
17 of 19 checks passed
@rajeeja
rajeeja deleted the fix-annotations-at-mcp-floor branch October 20, 2026 00:18
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.

1 participant