Skip to main content
Testing MCP integrations often requires running external server processes. Mock servers let you test your agent’s MCP behavior without any external dependencies.

Why Mock?

  • Fast — No subprocess or network overhead
  • Deterministic — Predictable responses for every test
  • Isolated — No external dependencies or credentials
  • CI-friendly — Works in any environment

Basic Mock Server

Create a mock by defining the tools, resources, and prompts you want to simulate:

Testing Agent with MCP Tools

Combine MockModel with a mock MCP server to test the full agent-MCP integration:

Writing a Mock MCP Server

Create a simple Python script that implements the MCP protocol over stdio:

Testing Tips

Use MockModel

Combine mock MCP servers with MockModel to test the full pipeline without any real API calls.

Test Tool Filtering

Verify that allowed_tools and blocked_tools configuration works correctly with your mock server.

Test Error Paths

Make your mock server return errors to verify your agent handles MCP failures gracefully.

Test Reconnection

Simulate connection drops to verify the reconnection logic works.
For simple unit tests, you may not need a full mock server. You can test agent logic with MockModel alone and test MCP integration separately with real or mock servers in integration tests.