Package org.mockserver.netty.mcp
Class McpContractTest
java.lang.Object
org.mockserver.netty.mcp.McpContractTest
Deterministic conformance / contract tester for a target MCP (Model Context Protocol)
server reachable over Streamable HTTP.
It exercises the required JSON-RPC handshake and core methods — initialize,
notifications/initialized, ping, tools/list, unknown-method
rejection, and optionally a single tools/call — and reports per-check conformance.
This validates only the shape of responses (the JSON-RPC 2.0 envelope and the required result fields of each method), never the semantics of any tool. No LLM and no MockServer state are involved, so the outcome is fully deterministic.
The HTTP transport is injected as a McpContractTest.JsonRpcExchange so the orchestration is unit
testable without a network, mirroring org.mockserver.openapi.OpenApiContractTest.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classOutcome of a single named conformance check.static classResult of a single JSON-RPC exchange.static interfaceOne JSON-RPC exchange against the target server.static classFull conformance report. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDefault MCP protocol version advertised by the client when the caller supplies none. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionrun(String protocolVersion, String toolName, McpContractTest.JsonRpcExchange exchange) Run the conformance suite against the target server.
-
Field Details
-
DEFAULT_PROTOCOL_VERSION
Default MCP protocol version advertised by the client when the caller supplies none. Corresponds to the 2025-03-26 MCP specification; callers can override it via theprotocolVersionargument to test a server against a newer or older revision.- See Also:
-
-
Constructor Details
-
McpContractTest
public McpContractTest(com.fasterxml.jackson.databind.ObjectMapper mapper)
-
-
Method Details
-
run
public McpContractTest.Report run(String protocolVersion, String toolName, McpContractTest.JsonRpcExchange exchange) Run the conformance suite against the target server.- Parameters:
protocolVersion- protocol version to advertise (null/blank →DEFAULT_PROTOCOL_VERSION)toolName- optional tool to exercise via atools/callshape check (null/blank → skipped)exchange- the JSON-RPC transport- Returns:
- the conformance report
-