Use an MCP testing pyramid
Keep most tests at the lower layers. They are faster and make failures easier to diagnose.
1. Test business logic
Test handlers without starting a transport when possible. For each tool, resource, and prompt, cover:- Valid input
- Missing required fields
- Wrong types and invalid formats
- Boundary values and oversized input
- Authorized and unauthorized callers
- Empty upstream results
- Rate limits, timeouts, and upstream failures
- Safe output filtering
2. Test the MCP contract
Verify that the published interface matches the implementation:- Every capability is declared during initialization.
tools/list,resources/list, andprompts/listreturn valid metadata.- Input and output schemas are valid JSON Schema.
- Tool names are unique and stable.
- Required fields match the handler requirements.
- Pagination and change notifications work when supported.
- Tool results conform to their declared
outputSchema.
3. Test with MCP Inspector
Run the official Inspector against a local command:- Confirm initialization and capability negotiation.
- Inspect tool, resource, and prompt metadata.
- Call every tool with valid and invalid arguments.
- Read resources and test subscriptions.
- Render prompts with different arguments.
- Watch log messages and notifications.
- Reconnect after restarting the server.
4. Test transport behavior
Forstdio:
- Confirm that only MCP messages appear on
stdout. - Confirm that logs go to
stderr. - Test startup with absolute executable and file paths.
- Test shutdown and child-process cleanup.
- Test POST requests and optional GET-based SSE streams.
- Validate the
Originheader. - Verify authentication and session handling.
- Test disconnects, reconnection, and resumability when implemented.
- Test concurrent requests, timeouts, and request-size limits.
5. Test errors and recovery
Create tests for both:- Protocol errors: malformed JSON-RPC, unknown methods, and invalid protocol parameters.
- Tool execution errors: invalid business input, missing records, rate limits, and upstream failures.
6. Test model behavior
Protocol correctness does not guarantee that an AI model will use your server correctly. Create a small evaluation set of realistic user requests. Measure whether the client:- Chooses the correct tool
- Avoids irrelevant or overlapping tools
- Supplies valid arguments
- Interprets empty and partial results correctly
- Requests confirmation before sensitive actions
- Recovers from a correctable tool error
7. Test security
Test the controls described in MCP server security:- Authentication and token validation
- Object-level authorization
- Least-privilege scopes
- Prompt injection in inputs and upstream content
- Path, command, query, and URL injection
- SSRF and redirect handling
- Secret redaction
- Rate and concurrency limits
- Confirmation for destructive operations
8. Test performance
Measure:- Initialization time
- Tool discovery time
- p50, p95, and p99 call latency
- Maximum concurrent requests
- Memory and CPU under load
- Large result behavior
- Upstream timeout and retry behavior
Add tests to CI
A practical pipeline is:Test a 0mcp server
Use the 0mcp Playground to inspect and call generated tools before publishing. Test servers created from OpenAPI, Swagger, direct REST API, and GraphQL sources with the same core checklist:- Review generated names, descriptions, and schemas.
- Test valid, invalid, empty, and unauthorized requests.
- Confirm upstream authentication behavior.
- Check activity logs.
- Publish a version only after the intended tools pass.
Release checklist
- Initialization succeeds in supported clients
- All published capabilities have tests
- Schemas and results match
- Auth and object-level permissions are covered
- Error messages are safe and actionable
- Model-behavior evaluations pass
- Transport reconnect and shutdown behavior works
- Performance meets the defined budget
- A previous version is available for rollback