Skip to content

Test the server over the MCP wire, not just under it - #174

Merged
rajeeja merged 1 commit into
mainfrom
mcp-protocol-tests
Oct 13, 2026
Merged

rajeeja merged 1 commit into
mainfrom
mcp-protocol-tests

Conversation

@rajeeja

@rajeeja rajeeja commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator

All 1374 existing tests call a tool function directly or inspect a registry object. That is a layer below where clients live, so it cannot see a response that fails to serialise, a schema the SDK rejects, a capability we forgot to advertise, or a field that quietly became empty.

The official reference servers (modelcontextprotocol/servers) test through an in-process ClientSession for exactly this reason. We had nothing equivalent.

The harness

tests/mcp_harness.py runs make_mcp_server() — the same builder the CLI serves — against create_client_server_memory_streams and yields an initialised ClientSession. No subprocess, no stdio, no network, but the bytes still go through the SDK's framing, validation and error mapping.

Assertions use wire JSON (model_dump(by_alias=True)) rather than Python attributes wherever shape is what matters. Not pedantry — serverInfo became server_info in mcp 2.x. An attribute-name assertion would break on an SDK upgrade that changed nothing a client sees, while the JSON key stayed serverInfo throughout.

Three findings, pinned as characterisation tests

Writing the harness immediately surfaced three real gaps. Each is asserted as it behaves today, so the test turns red the moment someone fixes it — with a message saying what to assert instead.

Finding Detail
Server version is "" UXARRAY_IDENTITY.version is 2026.9.1 and the SDK's Server accepts version=, but neither route_table_to_mcp_server nor MCPAdapter.__init__ upstream takes one. Nothing forwards it, so every client is told "" — which breaks the usual way a bug report establishes what was running.
Zero tool annotations readOnlyHint/destructiveHint are how a client decides what to auto-approve. With none set, get_capabilities is indistinguishable from a tool that moves data between machines. 0 of 33.
outputSchema on 1 of 33 tools The machinery (registry._apply_output_schema, typed_results.output_schema_for) exists and is wired to run_analysis only.

Fixing those belongs in its own change. This PR establishes the vantage point from which they are visible at all.

What is covered

15 tests across: the handshake and advertised capabilities; every tool surviving serialisation; unique names; every inputSchema validated as real JSON Schema (via jsonschema, an explicit dev dep so it cannot silently skip); JSON round-tripping; tool errors arriving as isError rather than session-killing exceptions; the missing-file case a first-run user hits; unknown tools; and resources/list answering, since resource_link results are only honest if it does.

Verified non-vacuous

Tests that pass no matter what are worse than no tests, so I checked both directions by mutation:

  • Renaming the server to "MUTATED NAME" → identity test fails. ✓
  • Actually setting srv.version = __version__ → the version characterisation fails, with a message telling the fixer to assert equality instead. ✓

Both mutations reverted; git diff on src/ is empty.

Independence

Based on main, not stacked on #173. Confirmed passing against both the pre-security lockfile (xarray 2026.4.0) and the upgraded one, so the two can merge in either order.

new tests 15 passed
full core suite 1389 passed (1374 + 15)
pre-commit (ruff, mypy, zizmor) all passed

Every one of the 1374 tests here calls a tool function directly or
inspects a registry object. That is a layer below where clients live, and
it cannot see a response that fails to serialise, a schema the SDK
rejects, a capability we forgot to advertise, or a field that quietly
became empty. The official reference servers test through an in-process
ClientSession for exactly this reason; we had nothing equivalent.

tests/mcp_harness.py runs make_mcp_server() -- the same builder the CLI
serves -- against create_client_server_memory_streams and hands back an
initialised ClientSession. No subprocess, no stdio, no network, but the
bytes still go through the SDK's framing, validation and error mapping.

Assertions are on wire JSON (model_dump(by_alias=True)) rather than on
Python attributes wherever shape is what matters. This is not pedantry:
serverInfo became server_info in mcp 2.x, so an attribute-name assertion
would break on an SDK upgrade that changed nothing a client sees, while
the JSON key stayed serverInfo throughout.

Three findings came straight out of writing it, all pinned as
characterisation tests that fail the moment someone fixes them:

  - The advertised server version is the empty string. The identity
    carries 2026.9.1 and the SDK's Server takes version=, but neither
    route_table_to_mcp_server nor MCPAdapter.__init__ upstream accepts
    one, so nothing forwards it. Every client is told "".
  - No tool declares MCP annotations. readOnlyHint/destructiveHint are
    how a client decides what to auto-approve; with none set, a pure
    capability query is indistinguishable from a tool that moves data
    between machines.
  - outputSchema is published by 1 tool of 33. The machinery
    (registry._apply_output_schema, typed_results.output_schema_for)
    exists and is wired to almost nothing.

Fixing those belongs in its own change. This one establishes the vantage
point from which they are visible at all.

Verified the tests fail for the right reasons rather than passing
vacuously: renaming the server breaks the identity test, and setting the
version makes the version characterisation fail with a message telling
the fixer what to assert instead.
@rajeeja
rajeeja merged commit 774b79d into main Oct 13, 2026
13 checks passed
@rajeeja
rajeeja deleted the mcp-protocol-tests branch October 13, 2026 01:00
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