MCP Server Tester
Test an MCP server end to end. First detect its protocol era (stateless 2026-07-28, or a session-based 2025-era server with the initialize handshake), then drive it with the MCP Inspector v2 CLI using --format json and exit codes: tools/list with --strict schema checks, one safe tools/call, and an error-path call that must come back as isError. Then write automated tests with the official v2 SDK clients for TypeScript or Python. Use after changing a server's tools, before connecting a server to a client, or when adding MCP tests to CI.
This skill tests an MCP server the way a client will use it. It works out whether the server speaks the stateless 2026-07-28 protocol or the older session-based one, runs Inspector v2 CLI checks whose exit codes mean pass or fail (tool listing, strict schema checks, a safe call, an error-path call), and turns them into TypeScript or Python tests for CI.
Install to ~/.claude/skills/mcp-server-tester/SKILL.md
npx agentscamp add skills/mcp-server-testerThe Model Context Protocol changed shape in 2026. The current revision, 2026-07-28, is stateless: it removes the initialize handshake, protocol sessions and the Mcp-Session-Id header, drops ping and logging/setLevel, and adds a server/discover method that every server must implement. Servers built on the 2025 revisions still use sessions. The MCP Inspector moved to v2 with a scriptable CLI and stable exit codes, and both official SDKs shipped v2 clients. This skill tests a server in that world: it works out which era the server speaks, runs a fixed set of Inspector CLI checks, and then turns the same checks into tests that run in CI.
When to use this skill
- You renamed a tool, rewrote its description, or changed its input schema, and want proof the server still lists and runs it.
- Before connecting a server to Claude Code or handing it to teammates.
- A client says a tool "fails" and you need to know whether it is a tool error or a protocol error.
- The server has no automated tests, or its tests use the v1 SDK and you are moving to v2.
When NOT to use this skill
- Starting a server from nothing: the mcp-server-scaffolder skill.
- Reviewing tool descriptions and results for injection risk: the mcp-security-reviewer agent.
- Auditing which servers a project's config enables: the mcp-config-auditor skill.
- A quick pass or fail from inside a session, with no test files written: the /test-mcp-server command.
Instructions
-
Find how the server starts and which SDK it uses. For stdio, find the launch command (
node build/index.js, abinentry,uv run server.py). For a remote server, get the URL. Then read the manifest or lockfile:Signal SDK line Era to expect @modelcontextprotocol/server2.xTypeScript SDK v2 implements the 2026-07-28 spec @modelcontextprotocol/sdk1.xTypeScript SDK v1 (legacy, still patched) 2025-era sessions Python mcp2.x,from mcp.server import MCPServerPython SDK v2 confirm with the probe in step 2 Python mcp1.x,from mcp.server.fastmcp import FastMCPPython SDK v1 (legacy) 2025-era sessions Inspector v2 needs Node
^22.23.4 || ^24.22.1 || >=26.12.1. Checknode --versionfirst; an older Node fails before any test runs. -
Detect the protocol era on the wire. The Inspector's
initializemethod is a connect-only probe that returnsserverInfo,protocolVersion,capabilities, andinstructions:npx @modelcontextprotocol/inspector --cli node build/index.js --method initialize --format json \ | jq '.result | {protocolVersion, serverInfo, capabilities}'2026-07-28means the stateless era.2025-11-25,2025-06-18,2025-03-26, or2024-11-05means the session-based era. If the probe and the code disagree, or the server is meant to serve both eras, pin each run with--protocol-era modernand again with--protocol-era legacy(autois the third value) and test both. Record the era next to every result. What changes between them:Behavior 2026-07-28 (stateless) 2025-era (sessions) Handshake none; server/discoveradvertises versions, capabilities, and identityinitialize, thennotifications/initializedSessions none; no Mcp-Session-IdheaderMcp-Session-Idon Streamable HTTPping,logging/setLevelremoved: do not test them present Resource not found error -32602error -32002tools/listorderservers SHOULD return a deterministic order no rule Results every result carries a required resultTypefieldno such field -
List the tools and check the schemas. The mode flag (
--cli) must come first, right after the package name:npx @modelcontextprotocol/inspector --cli node build/index.js --method tools/list --format json > tools.json; rc=$? echo "exit=$rc" jq -r '.result.tools[] | [.name, (.description // "MISSING")] | @tsv' tools.json jq -e '.result.tools | map(.name) | index("get_temp")' tools.json # non-zero exit if absent npx @modelcontextprotocol/inspector --cli node build/index.js --method tools/list --strict--strictreports tool-schema portability problems (path, issue, suggested fix) on stderr and exits6if any is error-severity; without it you get a one-line count. Then review each tool by hand: the name matches what clients expect, the description says when to use the tool, every argument the handler needs is in the schema'srequiredlist, and enum values match what the handler accepts. On a 2026-07-28 server, runtools/listtwice and compare the name order; a difference is a warning against the spec's SHOULD.For a remote server, the transport is inferred from a URL path ending in
/mcpor/sse; any other path needs--transport httpor--transport sse, because there is no default:npx @modelcontextprotocol/inspector --cli https://mcp.example.com/mcp --method tools/list --format json npx @modelcontextprotocol/inspector --cli https://mcp.example.com/api --transport http \ --method tools/list --header "X-API-Key: $MCP_TEST_KEY" --stored-auth-only--stored-auth-onlynever starts interactive OAuth, so it is the safe choice in CI. A stdio server that needs environment variables gets them with-e KEY=value(repeatable). -
Happy path: call one safe tool. Pick a tool that is safe to call repeatedly: read-only, idempotent, and cheap. Never call a tool that sends, deletes, pays, or writes to real data; if every tool has side effects, run against a test instance or ask the user.
npx @modelcontextprotocol/inspector --cli node build/index.js --method tools/call \ --tool-name get_temp --tool-args-json '{"city":"Paris","units":"C"}' --format json > call.json; rc=$? [ "$rc" -eq 0 ] && jq -e '.result.isError != true and (.result.content | length > 0)' call.json--tool-arg key=valueis repeatable and JSON-parses values (count=1becomes a number);--tool-args-jsonpasses the object verbatim. The two are mutually exclusive, so use--tool-args-jsonwhen types matter. If the tool returnsstructuredContent, check its fields as well. -
Error path: the failure must come back inside the result. Call the same tool with arguments its schema rejects, such as a missing required field:
npx @modelcontextprotocol/inspector --cli node build/index.js --method tools/call \ --tool-name get_temp --tool-args-json '{"units":"C"}' --format json > bad.json; rc=$? echo "exit=$rc" # expect 5 jq '.result.isError, .result.content' bad.jsonExpect exit
5withisError: trueand a message a model could act on. The spec says errors that originate from the tool, including invalid arguments, belong inside the result withisErrorset, "not as an MCP protocol-level error response. Otherwise, the LLM would not be able to see that an error occurred and self-correct." Any other non-zero exit means the call did not come back as a tool result; read the error envelope on stderr and report it as a finding. Then call a tool name that does not exist. The spec treats an unknown tool as a protocol error; the TypeScript SDK'sMcpServerreturns that JSON-RPC error, while the Python SDK'sMCPServerreturns anisErrorresult. The Inspector exits5for a tool that was not found, so accept both shapes.Capture exit codes with
rc=$?, notstatus=$?: in zshstatusis a read-only variable and the assignment fails. -
Resources and prompts, if the server advertises them. Check
capabilitiesfrom step 2, then run--method resources/list,--method resources/read --uri <uri>,--method prompts/list, and--method prompts/get --prompt-name <name> --prompt-args key=value. Read a URI that does not exist and check the error on stderr:-32602is correct for a 2026-07-28 server, and-32002was the 2025-era code. A 2026-07-28 server still returning-32002is a finding. -
Read the exit code before the output.
Exit Meaning 0 success 1 usage or unexpected error 3 auth failed or required 4 server unreachable 5 tool error: tools/callreturnedisError: true, or the tool was not found6 --strictfound an error-severity schema problem11 rate limited (HTTP 429) 12 OAuth destination guard refusal 130 a --loadrun interrupted (Ctrl+C or SIGTERM)Codes 2, 7 to 9, and 10 belong to
--app-info,--verify, and--load. On any non-zero exit the CLI also writes one JSON line to stderr, the error envelope{"error":{"code":…,"message":…}}. -
Write automated tests with the v2 SDK clients. TypeScript servers built on
@modelcontextprotocol/servercan be tested in-process:createMcpHandlerserves requests throughhandler.fetch, which is the in-process path for 2026-07-28 coverage (InMemoryTransport.createLinkedPair()connects 2025-era instances only):// test/mcp.test.ts: node:test with node:assert; swap in your runner's expect if you prefer import { test, after } from 'node:test'; import assert from 'node:assert/strict'; import { Client, StreamableHTTPClientTransport } from '@modelcontextprotocol/client'; import { createMcpHandler } from '@modelcontextprotocol/server'; import { createServer } from '../src/server.js'; // the factory you deploy const handler = createMcpHandler(createServer); const client = new Client({ name: 'test-harness', version: '1.0.0' }, { versionNegotiation: { mode: 'auto' } }); await client.connect(new StreamableHTTPClientTransport(new URL('http://test.local/mcp'), { fetch: (url, init) => handler.fetch(new Request(url, init)), })); after(async () => { await client.close(); await handler.close(); }); test('tools/list exposes get_temp with a required city', async () => { const { tools } = await client.listTools(); const tool = tools.find((t) => t.name === 'get_temp'); assert.ok(tool?.description); assert.deepEqual(tool.inputSchema.required, ['city']); }); test('happy path returns a result, not an error', async () => { const result = await client.callTool({ name: 'get_temp', arguments: { city: 'Paris', units: 'C' } }); assert.notEqual(result.isError, true); }); test('schema-rejected arguments come back as isError, not a throw', async () => { const failed = await client.callTool({ name: 'get_temp', arguments: { units: 'C' } }); assert.equal(failed.isError, true); });To test the built binary instead, connect over stdio with
StdioClientTransportfrom@modelcontextprotocol/client/stdio:await client.connect(new StdioClientTransport({ command: 'node', args: ['dist/server.js'] })).Python servers on
mcp2.x connect in-process by passing the server object toClient:# tests/test_mcp.py (uv add --dev pytest) import pytest from mcp import Client from server import mcp # your MCPServer instance @pytest.fixture def anyio_backend(): return "asyncio" @pytest.fixture async def client(): async with Client(mcp, raise_exceptions=True) as c: yield c @pytest.mark.anyio async def test_lists_get_temp(client: Client): tools = (await client.list_tools()).tools tool = next(t for t in tools if t.name == "get_temp") assert tool.description assert tool.input_schema["required"] == ["city"] @pytest.mark.anyio async def test_happy_path(client: Client): result = await client.call_tool("get_temp", {"city": "Paris", "units": "C"}) assert not result.is_error @pytest.mark.anyio async def test_bad_arguments_and_unknown_tool_return_is_error(client: Client): assert (await client.call_tool("get_temp", {"units": "C"})).is_error assert (await client.call_tool("does_not_exist", {})).is_errorA tool that raises comes back as a result with
is_error=True; aClientmethod raisesMCPErroronly when the server answers with a JSON-RPC error.Client(mcp)is era-neutral in-process. Against a running server,Client("http://localhost:8000/mcp")uses the defaultmode="auto", which probesserver/discoverand falls back to the initialize handshake; passmode="2026-07-28"ormode="legacy"to test one era on purpose, and dropraise_exceptions=Truewhen you pinlegacy.Legacy v1 code, labelled as such. Repos still pinned to
@modelcontextprotocol/sdk1.x (patched for at least six months after the v2 release on 2026-07-27) use the old import paths. Keep them only until you migrate:// LEGACY v1 API (@modelcontextprotocol/sdk 1.x). New tests use @modelcontextprotocol/client. import { Client } from '@modelcontextprotocol/sdk/client/index.js'; import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js'; const transport = new StdioClientTransport({ command: 'node', args: ['build/index.js'] }); const client = new Client({ name: 'my-client', version: '1.0.0' }); await client.connect(transport);In Python, v1 tests built on
ClientSessionwithstdio_client, or onmcp.server.fastmcp, are legacy too: v2 renamedFastMCPtoMCPServerand removedstreamablehttp_client(usestreamable_http_client). -
Gate CI on the exit codes. A smoke script that fails the job on any unexpected code:
#!/usr/bin/env bash # scripts/mcp-smoke.sh: run after the server is built set -u inspect() { npx -y @modelcontextprotocol/inspector --cli node build/index.js "$@" --format json; } inspect --method tools/list --strict > /dev/null || { echo "FAIL tools/list (exit $?)"; exit 1; } inspect --method tools/call --tool-name get_temp --tool-args-json '{"city":"Paris","units":"C"}' > /dev/null \ || { echo "FAIL happy path (exit $?)"; exit 1; } inspect --method tools/call --tool-name get_temp --tool-args-json '{"units":"C"}' > /dev/null; rc=$? [ "$rc" -eq 5 ] || { echo "FAIL error path: expected exit 5, got $rc"; exit 1; } echo "MCP smoke checks passed"
WARNING
Do not assert on initialize, ping, logging/setLevel, or Mcp-Session-Id for a 2026-07-28 server; those exist only in the 2025-era protocol. A test suite written against the old handshake passes against old servers and fails, or tests nothing, against current ones. Write down the era you tested.
NOTE
The Inspector's --protocol-era flag sets which era an ad-hoc run negotiates. A server that claims to serve both eras needs both runs in CI, or one of them is untested.
Output
The test report, the new or updated test files, and the smoke script. The report states the era, then one row per check:
## MCP server test: weather-server (stdio: node build/index.js)
Era tested: 2026-07-28 (probe protocolVersion; @modelcontextprotocol/server 2.x)
| Check | Expected | Got | Verdict |
| --- | --- | --- | --- |
| tools/list --strict | exit 0, get_temp listed | exit 0, 3 tools | PASS |
| tools/list order (x2) | same order | same order | PASS |
| tools/call get_temp (valid) | exit 0, isError not true | exit 0 | PASS |
| tools/call get_temp (missing city) | exit 5, isError true | exit 1, error envelope on stderr | FAIL: tool error reported as a protocol error |
| tools/call does_not_exist | exit 5 | exit 5 | PASS |
| resources/read (missing URI) | -32602 | -32002 | FAIL: 2025-era error code |
Tests written: test/mcp.test.ts (3 tests, passing), scripts/mcp-smoke.shFor the server-building side, the mcp-server-engineer agent and Building an MCP server cover the fixes these findings usually lead to; the MCP development skills roundup shows where testing sits in the full build.
Filed under
claude · mcp · mcp-inspector · testing · ci · developers
Related
- Test MCP ServerRun MCP Inspector CLI checks against an MCP server given as a launch command or URL: detect its protocol era, list tools with --strict, call one safe tool, call it with bad arguments, and report pass or fail per check with exit codes.
- 7 Best Claude Skills for MCP Server DevelopmentClaude skills, commands, and agents for building MCP servers: scaffolding, tool schemas, Inspector testing, safe registration, config audits, code review, and plugins.
- MCP Config AuditorAudit the MCP server configuration files a repository or machine actually loads (.mcp.json, any mcpServers block in .claude/settings*.json or managed settings, claude_desktop_config.json, .cursor/mcp.json, .vscode/mcp.json, Codex config.toml) for packages pulled without a pinned version, secrets written inline in env or headers, filesystem servers rooted too high, remote servers reached over plain HTTP or without auth, tool names that duplicate or shadow each other across servers, and tool descriptions that carry instructions to the model, then report each finding with the file, the line, and the fix. Read-only. Use before approving a repository's checked-in servers or after adding one.
- MCP (Model Context Protocol)MCP is the open standard for connecting AI models to external tools and data: write one server, and any MCP client — Claude Code, IDEs, agents — can use it.
- Building an MCP ServerAn accurate introduction to the Model Context Protocol: server anatomy, transports, and connecting a tool to Claude Code.
- MCP InspectorThe official open-source visual tool for testing and debugging Model Context Protocol servers — connect, list, and call tools, resources, and prompts.
- MCP Security ReviewerUse this agent to review an MCP server's source code and tool definitions, not just its config, for prompt-injection and tool-poisoning risk: instructions to the model hidden in tool or parameter descriptions, tool results that pass untrusted content (web pages, emails, database rows) to the model unlabeled, file, shell, and network scope wider than the tools need, HTTP transports with no authentication or origin checks, secrets handling, and rug-pull risk where descriptions or the tool list can change after approval. Read-only; it reports each finding with a severity and a fix and ends with a connect or do-not-connect verdict. Examples: "review this MCP server before we add it to the team config", "is this community server safe to connect", "check our own server's tool descriptions for injection surface".
- MCP Server EngineerUse this agent to build, harden, or productionize a Model Context Protocol (MCP) server — designing tools/resources/prompts, choosing stdio vs. Streamable HTTP, taking a server remote with OAuth and stateless scaling, and testing it with the MCP Inspector. Examples — "wrap our internal API as an MCP server with three tools", "take our stdio server remote so the team can share it", "our tools confuse the model — fix the names, schemas, and descriptions".