Skip to main content
Hey — this lesson walks through practical ways to test a local MCP (Model Context Protocol) server. You’ll find quick manual techniques for one-off checks, interactive UIs for exploring tools, and automated patterns for CI/CD-friendly tests that work well with STDIO MCP servers.
A presentation slide titled "Testing a Local MCP Server" with a large stylized "Demo" on a dark curved background to the right. The slide includes a small "© Copyright KodeKloud" note in the bottom-left.
Callouts
Use interactive tools for quick debugging (Postman, MCP Inspector), and automated tests for CI/CD (MCP Tester or language-specific test frameworks).
Why test locally?
  • Validate tool discovery (tools/list) and invocation (tools/call) before deploying.
  • Catch protocol/JSON-RPC issues early.
  • Automate checks to prevent regressions in CI/CD.
Summary of approaches Important: For any table cells or inline examples containing curly braces or angle brackets we use code formatting so MDX doesn’t try to parse them.

1) Quick manual testing with Postman (STDIO)

Postman supports launching a process and communicating over STDIO. This is ideal for ad-hoc verification of JSON-RPC requests/responses. Steps:
  1. Open Postman → New → MCP request.
  2. Select transport type: STDIO.
  3. Set command to node and arguments to the full path of your server.js (e.g., /full/path/to/server.js).
  4. Postman will spawn node /full/path/to/server.js and communicate via STDIO.
  5. Use tools/list to discover tools, and tools/call to invoke them.
Example JSON-RPC request to call the add-integers tool:
Minimal server.js example that exposes a single tool (add-integers):
Once connected in Postman, call the tool with a=3 and b=4 and verify the output ("7").

2) Using MCP Inspector (interactive web UI)

MCP Inspector gives a web UI tailored to MCP servers. It’s excellent for exploring tool metadata, trying inputs, and seeing raw JSON-RPC traffic. Quick start:
What to expect:
  • The inspector prints a local URL and a session token — open that in your browser.
  • Configure transport: STDIO, command: node, arguments: server.js.
  • You can call tools/list, tools/call, fill input fields, and view a history of JSON-RPC messages and raw stdin/stdout.
Inspector highlights:
  • Transport configuration (STDIO)
  • Tool discovery and input fields (e.g., add-integers)
  • JSON-RPC request/response history
  • Convenient manual testing similar to Postman but MCP-focused

3) Automated tests with a Node “MCP Tester”

Automated tests are essential for CI. The pattern below spawns your server, writes JSON-RPC messages to STDIN, captures STDOUT, and asserts correct behavior. Example test helper (compact):
Notes on the example:
  • sendMessage uses a simple polling approach to extract JSON from a mixed stdout buffer. For production, implement a robust framing strategy (newline-delimited JSON, explicit frames, or length-prefix).
  • Add a proper readiness probe (e.g., wait for a specific log line or implement a ready JSON-RPC method) rather than fixed sleep timers.
  • Integrate these tests as part of npm test or your CI job so failures block merges.

4) Crude but fast: echoing JSON into the server (shell)

For one-off checks you can pipe a JSON-RPC request into the server process:
Example console output (startup logs followed by the JSON-RPC response):
Use this approach for quick smoke tests or to write simple shell-based checks and automation.

Recommendations and next steps

  • Use Postman or MCP Inspector for interactive debugging and rapid exploration.
  • Add automated tests (like the MCP Tester example) to CI so regressions are caught early.
  • If your server is implemented in other languages (Python, Java, etc.), implement equivalent tests using that language’s test frameworks:
    • Python: pytest, unittest
    • Java: JUnit
    • Node: mocha, jest
  • For reliable automation:
    • Use a clear STDIO framing protocol (e.g., newline-delimited JSON).
    • Add explicit readiness checks before sending requests.
    • Capture and assert on both structured JSON-RPC responses and important logs.
Automated tests are essential. Manual checks are helpful for debugging, but CI/CD tests prevent regressions and give confidence when deploying changes.
If you want, I can adapt the automated test to use a line-delimited JSON framing strategy or convert the tester into a Jest/Mocha test suite ready for CI.

Watch Video

Practice Lab