Test an MCP server with MCP Inspector --cli, no client needed
Send initialize, tools/list and tools/call to a stdio MCP server with Inspector --cli and read exit codes. Passing the Inspector is not passing every client.
Before wiring a new MCP server into a client such as Claude Code, check it with the Inspector's CLI mode. It sends one request per command without a browser, prints the result as JSON on stdout and reports the failure class as an exit code. Results below come from a test server with two tools, add and fail.
[1] Pin the version. The docs note that npx @modelcontextprotocol/inspector --cli resolves the latest release on every run, so in CI pin it (@2.12.0) and pass --yes to skip the install prompt. Node 22.19.0 or newer is required.
$ npx --yes @modelcontextprotocol/inspector@2.12.0 --cli node server.mjs --method initialize[2] Check the connection only. --method initialize completes the handshake and calls nothing.
$ npx @modelcontextprotocol/inspector --cli node server.mjs --method initialize --format json 2>/dev/null | jq .{ "result": { "serverInfo": { "name": "demo-server", "version": "0.1.0" }, "protocolVersion": "2025-11-25", "capabilities": { "tools": { "listChanged": true } } }}Without --format json the output is human-oriented text, so always pass it when a script reads the result with jq. The server's diagnostics (demo-server ready on stdio) go to stderr, which 2>/dev/null drops here.
[3] List the tools.
$ npx @modelcontextprotocol/inspector --cli node server.mjs --method tools/list --format json 2>/dev/null | jq -c ".result.tools[] | {name, description}"{"name":"add","description":"Add two integers"}{"name":"fail","description":"Always returns a tool error"}The … | jq pipelines above are for eyeballing. A pipeline's exit status is that of its last command (jq), so if Inspector fails but jq returns 0, CI sees a pass. Even with set -o pipefail, when both sides fail the rightmost (jq) status wins (section 5 of the docs). In CI, capture Inspector's output and exit code first, and parse with jq only on success:
out=$(npx @modelcontextprotocol/inspector --cli node server.mjs --method tools/list --format json 2>/dev/null); rc=$?[ "$rc" -eq 0 ] || { echo "inspector exit $rc" >&2; exit "$rc"; }printf '%s\n' "$out" | jq -e ".result.tools | length > 0"[4] Call a tool. Pass the arguments as one JSON object with --tool-args-json.
$ npx @modelcontextprotocol/inspector --cli node server.mjs --method tools/call --tool-name add --tool-args-json "{\"a\":2,\"b\":3}" --format json 2>/dev/null{"result":{"content":[{"type":"text","text":"5"}]}}[5] Tell failures apart by exit code. The docs' table: 0 success, 1 usage or unexpected error (the catch-all), 2 no MCP App on the tool (--app-info), 3 authentication required (401/403, OAuth), 4 server unreachable, 5 tool error (isError:true or tool not found), 6 schema problem found by --strict. This stdio test produced 0, 1 and 5:
| Situation | Exit code | Last stderr line |
|---|---|---|
| Normal call | 0 | |
Tool returns isError: true (fail) | 5 | tool_is_error (seen in the same case in step 6) |
Unknown tool name (nope) | 5 | {"error":{"code":"tool_not_found","message":"Tool 'nope' not found on server."}} |
| Server file missing | 1 | {"error":{"code":"error","message":"Connection closed"}} |
$ npx @modelcontextprotocol/inspector --cli node server.mjs --method tools/call --tool-name fail --format json 2>/dev/null{"result":{"content":[{"type":"text","text":"something went wrong"}],"isError":true}}(exit=5)(exit=…) is printed by the test script. The result JSON still prints, but the non-zero exit keeps an &&-chained CI step from passing silently. When the server cannot start at all you get Connection closed, the same cause behind a client's MCP error -32000: Connection closed (fixing -32000).
[6] Watch for values the Inspector rewrites. With 2.12.0, the string "2" in --tool-args-json arrived as a number (the result was 5), and "abc" arrived as null and failed the server's input validation:
$ npx @modelcontextprotocol/inspector --cli node server.mjs --method tools/call --tool-name add --tool-args-json "{\"a\":\"abc\",\"b\":3}" --format jsondemo-server ready on stdio{"result":{"content":[{"type":"text","text":"MCP error -32602: Input validation error: Invalid arguments for tool add: Invalid input: expected number, received null at a"}],"isError":true}}{"error":{"code":"tool_is_error","message":"Tool 'add' returned isError:true."}}(exit=5)The docs say --tool-args-json is passed verbatim, which does not match this behaviour. To test whether your server rejects wrong types, do not rely on Inspector results alone.
[7] Passing in the Inspector does not mean passing in every client. A server that prints server starting... to stdout on startup (BROKEN=1) still looked fine in the Inspector:
$ BROKEN=1 npx @modelcontextprotocol/inspector --cli node server.mjs --method tools/call --tool-name add --tool-args-json "{\"a\":2,\"b\":3}" --format jsondemo-server ready on stdio{"result":{"content":[{"type":"text","text":"5"}]}}(exit=0)Over stdio, stdout is reserved for protocol messages, and depending on the client such a line becomes a connection error. Move any stdout logging to stderr even when the Inspector passes.