Skip to main content
The 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:
The MCP SDK is automatically installed as a dependency.

Quick Start

1

Create an environment

Create a basic MCP environment:
2

Evaluate

Run an evaluation:

MCP Server Configuration

Configure MCP servers using the MCPServerConfig format:
Configuration fields:
  • name - Identifier for the server
  • command - Command to launch the server
  • args - List of command arguments
  • env - 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: Fetch - Retrieve web content
Exa - AI-powered search
Brave Search - Web search

File System

Filesystem - Read/write files

Databases

PostgreSQL - Query databases
SQLite - Local database access

Development Tools

Git - Repository operations
GitHub - GitHub API access
See MCP servers directory for more servers.

Full 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:
  1. Environment starts background event loop
  2. Connects to all configured MCP servers
  3. Discovers available tools via tools/list
  4. Exposes tools to rollouts
  5. Cleanup on environment shutdown

Tool Execution

When a model calls an MCP tool:
  1. Tool call is intercepted by MCPEnv
  2. Request is sent to appropriate MCP server
  3. Response is returned as tool message
  4. 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_turns to 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)

Examples

See the mcp-search-env example in the Verifiers repository for a complete implementation.

Further Reading