* Assert on structured output in the smoke tests The smoke tests connected to each server, listed its tools and stopped there, so they could not catch a broken structured result. mcp-test-client now calls every tool that declares an outputSchema and checks the answer against it: the result must carry structuredContent, and a tool with an array-rooted schema must return a top-level JSON array rather than an object wrapping one. Tools with no output schema are left alone, so this is not a new requirement on any example. The client negotiates with mode "auto", so it exercises servers of either protocol era. Tool calls reach the live NWS API; an error result is reported as a skip rather than a failure. mock-mcp-server moves to the low-level Server and advertises one array-rooted and one object-rooted tool, with the schemas written out literally. A client that compiles every declared outputSchema at connect time fails against the array-rooted one if it assumes output schemas are always objects. utils.sh no longer swallows build output. A failed build left no binary behind and the test reported a downstream spawn ENOENT instead of the compiler error, which is what makes a broken build hard to diagnose from CI logs; #143 is the current example. check_dependency returns instead of exiting, so a missing toolchain fails its own test and the suite still prints its summary. Binaries resolve through a helper that accounts for the .exe suffix. The test helpers move to the 2.0 MCP SDK packages, where the 2026-07-28 support lives; the examples themselves are untouched. Those require Node 20 or newer, so CI moves off Node 18 to Node 24, the Active LTS - Node 20 reached end of life in April 2026. The Go examples and the Rust client stay uncovered here. Both clients abort when no .env file is present, so that coverage lands with those examples. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * Update to the stable 2.0 SDK packages and address review feedback @modelcontextprotocol/{client,server} 2.0.0 shipped on 2026-07-27, so the helpers move off 2.0.0-beta.5. Review fixes: - strip the UTF-8 BOM that preceded smoke-test.sh's shebang - ensure_built and ensure_helpers_built return rather than exit, so one project failing to build no longer aborts the suite before the summary - engines.node and the documented Node requirement go to 20, matching what the 2.0 SDK packages actually require - close the client on the failure path, so a failing test cannot leave the spawned server running - the README claimed Go and Rust client coverage that did not exist Adds the Go weather server to the smoke test, with the Go toolchain CI was missing. The Go and Rust clients stay uncovered: on main both abort without a .env, so credential-free startup has to land in their own directories. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
120 lines
3.4 KiB
JavaScript
120 lines
3.4 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Mock MCP Server for testing clients
|
|
*
|
|
* Verifies that clients call `tools/list`, and advertises tools whose output
|
|
* schemas cover both shapes a structured result can take: an object root, and
|
|
* an array root (allowed as of protocol revision 2026-07-28).
|
|
*
|
|
* The array-rooted tool is deliberate. Clients that compile every declared
|
|
* `outputSchema` up front — as the Go and Rust quickstart clients do — will
|
|
* fail here if they assume an output schema is always `{"type": "object"}`.
|
|
*
|
|
* This uses the low-level `Server` rather than `McpServer` so the schemas are
|
|
* written out literally, which is the point of a mock: what goes on the wire is
|
|
* exactly what is in this file.
|
|
*/
|
|
|
|
import type { Tool } from "@modelcontextprotocol/server";
|
|
import { Server } from "@modelcontextprotocol/server";
|
|
import { serveStdio } from "@modelcontextprotocol/server/stdio";
|
|
|
|
// Track whether tools/list was called
|
|
let toolsListCalled = false;
|
|
|
|
const TOOLS: Tool[] = [
|
|
{
|
|
name: "get_alerts",
|
|
description: "Mock alerts, returning a top-level array",
|
|
inputSchema: {
|
|
type: "object",
|
|
properties: { state: { type: "string" } },
|
|
required: ["state"],
|
|
},
|
|
// Array root: legal as of 2026-07-28, rejected by older revisions.
|
|
outputSchema: {
|
|
type: "array",
|
|
items: {
|
|
type: "object",
|
|
properties: { event: { type: "string" }, area: { type: "string" } },
|
|
required: ["event", "area"],
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "get_forecast",
|
|
description: "Mock forecast, returning an object",
|
|
inputSchema: {
|
|
type: "object",
|
|
properties: {
|
|
latitude: { type: "number" },
|
|
longitude: { type: "number" },
|
|
},
|
|
required: ["latitude", "longitude"],
|
|
},
|
|
outputSchema: {
|
|
type: "object",
|
|
properties: {
|
|
latitude: { type: "number" },
|
|
longitude: { type: "number" },
|
|
summary: { type: "string" },
|
|
},
|
|
required: ["latitude", "longitude", "summary"],
|
|
},
|
|
},
|
|
];
|
|
|
|
function buildServer(): Server {
|
|
const server = new Server(
|
|
{ name: "mock-test-server", version: "1.0.0" },
|
|
{ capabilities: { tools: {} } },
|
|
);
|
|
|
|
server.setRequestHandler("tools/list", async () => {
|
|
toolsListCalled = true;
|
|
return { tools: TOOLS };
|
|
});
|
|
|
|
server.setRequestHandler("tools/call", async (request) => {
|
|
const { name, arguments: args = {} } = request.params;
|
|
|
|
if (name === "get_alerts") {
|
|
const state = String((args as { state?: unknown }).state ?? "??");
|
|
const alerts = [{ event: "Mock Warning", area: state }];
|
|
return {
|
|
content: [{ type: "text", text: `1 alert for ${state}` }],
|
|
structuredContent: alerts,
|
|
};
|
|
}
|
|
|
|
if (name === "get_forecast") {
|
|
const { latitude = 0, longitude = 0 } = args as {
|
|
latitude?: number;
|
|
longitude?: number;
|
|
};
|
|
const forecast = { latitude, longitude, summary: "Mock conditions" };
|
|
return {
|
|
content: [{ type: "text", text: forecast.summary }],
|
|
structuredContent: forecast,
|
|
};
|
|
}
|
|
|
|
return {
|
|
content: [{ type: "text", text: `Unknown tool: ${name}` }],
|
|
isError: true,
|
|
};
|
|
});
|
|
|
|
return server;
|
|
}
|
|
|
|
serveStdio(buildServer);
|
|
console.error("Mock MCP Server running on stdio");
|
|
|
|
// Verify that tools/list was called when the connection closes
|
|
process.stdin.on("end", () => {
|
|
if (!toolsListCalled) {
|
|
console.error("Error: Client did not call tools/list");
|
|
process.exit(1);
|
|
}
|
|
});
|