MCP servers have a specific surface — JSON-RPC messages over a chosen transport. Testing them well means covering the protocol, the tool implementations, and the agent-facing behaviors. The patterns are similar to API testing with some MCP twists.
Unit tests on tool handlers
Each tool is a function with structured input and output. Test it like any other function: inputs, expected outputs, edge cases. Don't go through MCP transport for unit tests; call the handler directly. Fast feedback.
Protocol-level integration tests
Spin up the server in test mode (stdio for tests is easiest). Send JSON-RPC messages. Verify responses. Catches schema mismatches, transport bugs, framing issues. Run these as part of CI.
Mock LLM clients
Don't need a real LLM to test the server. Mock the agent: send the JSON-RPC messages an agent would, with realistic argument variations. Run model-generated arguments through the server in a stress-test mode.
Schema validation contracts
Tool schemas are contracts. Test that schemas are valid JSON Schema. Test that example arguments validate against schema. Test that descriptions are present and meaningful (catches the empty-description bug).
End-to-end with a real LLM
Final-stage: real LLM, real MCP server, simulated user requests. Catches 'model gets confused by description' bugs that nothing else catches. Slow; run on a smaller suite, not every commit. CI nightly or pre-release.