Repository navigation
Test the server over the MCP wire, not just under it - #174
Merged
Merged
Conversation
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.
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.
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-processClientSessionfor exactly this reason. We had nothing equivalent.The harness
tests/mcp_harness.pyrunsmake_mcp_server()— the same builder the CLI serves — againstcreate_client_server_memory_streamsand yields an initialisedClientSession. 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 —serverInfobecameserver_infoin mcp 2.x. An attribute-name assertion would break on an SDK upgrade that changed nothing a client sees, while the JSON key stayedserverInfothroughout.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.
""UXARRAY_IDENTITY.versionis2026.9.1and the SDK'sServeracceptsversion=, but neitherroute_table_to_mcp_servernorMCPAdapter.__init__upstream takes one. Nothing forwards it, so every client is told""— which breaks the usual way a bug report establishes what was running.readOnlyHint/destructiveHintare how a client decides what to auto-approve. With none set,get_capabilitiesis indistinguishable from a tool that moves data between machines. 0 of 33.outputSchemaon 1 of 33 toolsregistry._apply_output_schema,typed_results.output_schema_for) exists and is wired torun_analysisonly.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
inputSchemavalidated as real JSON Schema (viajsonschema, an explicit dev dep so it cannot silently skip); JSON round-tripping; tool errors arriving asisErrorrather than session-killing exceptions; the missing-file case a first-run user hits; unknown tools; andresources/listanswering, sinceresource_linkresults 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:
"MUTATED NAME"→ identity test fails. ✓srv.version = __version__→ the version characterisation fails, with a message telling the fixer to assert equality instead. ✓Both mutations reverted;
git diffonsrc/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.