MCPEnv integration allows you to connect to MCP (Model Context Protocol) servers and expose their tools to language models in Verifiers environments.
MCP provides a standardized way to connect AI models to external data sources and tools via a simple protocol.
Features
- Multiple MCP servers - Connect to multiple servers simultaneously
- Automatic tool discovery - Tools from servers are automatically exposed to models
- stdio transport - Communicates via standard input/output
- Type-safe - Preserves tool schemas and parameter types
- Built on ToolEnv - Inherits all ToolEnv features
Installation
MCP support is included in core Verifiers:Quick Start
1
Create an environment
Create a basic MCP environment:
2
Evaluate
Run an evaluation:
MCP Server Configuration
Configure MCP servers using theMCPServerConfig format:
name- Identifier for the servercommand- Command to launch the serverargs- List of command argumentsenv- Environment variables (optional)description- Human-readable description (optional)
With Environment Variables
For servers requiring API keys:Available MCP Servers
Common MCP servers you can use:Web & Search
Fetch - Retrieve web contentFile System
Filesystem - Read/write filesDatabases
PostgreSQL - Query databasesDevelopment Tools
Git - Repository operationsFull Example
Here’s a complete example using multiple MCP servers:Error Handling
Configure error handling behavior:Architecture Notes
MCPEnv is designed for globally available, read-only MCP servers where the same toolset can be shared across all rollouts. For servers requiring per-rollout state or mutable task-specific data, consider implementing a custom StatefulToolEnv subclass.Connection Management
MCP servers are connected once during environment initialization and shared across all rollouts:- Environment starts background event loop
- Connects to all configured MCP servers
- Discovers available tools via
tools/list - Exposes tools to rollouts
- Cleanup on environment shutdown
Tool Execution
When a model calls an MCP tool:- Tool call is intercepted by
MCPEnv - Request is sent to appropriate MCP server
- Response is returned as tool message
- Errors are formatted via
error_formatter
Best Practices
- Validate API keys - Use
vf.ensure_keys()to fail fast if keys are missing - Document requirements - List required environment variables in README
- Test servers locally - Verify MCP servers work before using in environments
- Handle errors gracefully - Provide clear error messages via
error_formatter - Limit tool calls - Set reasonable
max_turnsto prevent infinite loops
Limitations
- MCP servers must support stdio transport
- Servers are started once per environment, not per rollout
- No support for resources or prompts (tools only)
- Limited to read-only operations (no per-rollout state)