MCP Proxy Tool

February 4, 2026 ยท View on GitHub

Dynamically register tools from any MCP (Model Context Protocol) server as native EnvironmentTool instances. Each tool manages its own session to the MCP server.

ComponentDescription
MCPToolTool that manages its own MCP session
discover_mcp_tools()Discovers and creates tools from an MCP server

Usage

Add MCP servers to your experiment config:

mcp_servers:
  # SSE transport (default) - for servers with /sse endpoints
  my-server:
    url: "http://localhost:8000/sse"
    tool_prefix: "mcp_"
    tools:  # optional: list of tool names to include (omit to include all)
      - query
      - search
    # transport defaults to "sse"

  # Streamable HTTP transport - for REST-style MCP endpoints
  rest-api:
    url: "https://api.example.com/mcp"
    tool_prefix: "api_"
    transport: "streamable_http"

  # Long-running operations with custom timeout
  slow-server:
    url: "http://localhost:9000/sse"
    tool_prefix: "slow_"
    timeout: 300  # 5 minutes for long-running operations

tools:
  - bash
  - view
  - edit
  # MCP tools are added automatically from mcp_servers config

Config Options

OptionRequiredDefaultDescription
urlYes-The MCP endpoint URL
transportNosseTransport type: sse or streamable_http
tool_prefixNo""Prefix to add to tool names (e.g., mcp_ โ†’ mcp_query)
headersNo{}HTTP headers for authentication
toolsNoallList of tool names to include. If omitted, all tools from the server are registered
timeoutNo60Timeout in seconds for MCP operations

Transport Types

  • sse (default): Server-Sent Events transport. Use for servers with /sse endpoints.
  • streamable_http: HTTP-based transport. Use for REST-style MCP APIs.

Programmatic Registration

from debug_gym.gym.tools.mcp_proxy import discover_mcp_tools

# SSE transport (default)
tools = discover_mcp_tools(
    url="http://localhost:8000/sse",
    tool_prefix="mcp_",
)

# Streamable HTTP transport
tools = discover_mcp_tools(
    url="https://api.example.com/mcp",
    tool_prefix="api_",
    transport="streamable_http",
)

# Long-running operations with custom timeout
tools = discover_mcp_tools(
    url="http://localhost:9000/sse",
    tool_prefix="slow_",
    timeout=300,  # 5 minutes for long-running operations
)

for tool in tools:
    env.add_tool(tool)
    print(f"  - {tool.name}: {tool.description}")

# Filter specific tools
tools = discover_mcp_tools(
    url="http://localhost:8000/sse",
    tool_filter=["query", "search"],
)

Direct Tool Creation

from debug_gym.gym.tools.mcp_proxy import MCPTool

# Create a single tool directly
tool = MCPTool(
    url="http://localhost:8000/sse",
    mcp_tool_name="query",
    tool_name="my_query",  # optional custom name
    description="Query the database",
    input_schema={
        "properties": {"sql": {"type": "string"}},
        "required": ["sql"],
    },
    transport="sse",  # or "streamable_http"
    timeout=120,  # optional: custom timeout in seconds (default: 60)
)
env.add_tool(tool)

Security Considerations

MCP tools connect to external servers and execute operations based on their responses. Only connect to MCP servers you control or explicitly trust.

Resources