Learn proven patterns and anti-patterns for testing MCP servers and agents. Write maintainable, reliable, and efficient tests that scale with your project.
🌟 Test like a pro! These best practices come from real-world experience testing MCP servers and agents at scale. Follow these guidelines to build a robust, maintainable test suite.
Testing | Use These Assertions | Avoid |
---|---|---|
Correctness | contains , regex | LLM judges for exact values |
Tool Usage | was_called , called_with , sequence | Content checks for tool behavior |
Performance | response_time_under , max_iterations | Exact timing matches |
Quality | judge.llm , multi_criteria | Brittle string matching |
Error Handling | judge.llm with error rubric | Expecting exact error text |
Flakiness Source | Solution |
---|---|
Network issues | Add retries, increase timeouts |
Race conditions | Use explicit waits, not sleep |
Random data | Use fixed seeds or deterministic data |
External services | Mock or use test instances |
LLM variation | Lower temperature, use flexible assertions |