Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions agentenv-mcp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# AgentEnv-MCP

**Bidirectional MCP (Model Context Protocol) wrapper for AgentGym environments.**

This package provides two complementary wrappers:

1. **AgentEnvToMCP**: Expose any AgentGym environment as an MCP server
2. **MCPToAgentEnv**: Adapt any MCP server into an AgentGym-compatible environment

## Installation

```bash
pip install -e ".[dev,sciworld]"
```

## Architecture

```
┌─────────────────────────────────────────────────────────────────────────────┐
│ AgentEnv-MCP Wrappers │
├─────────────────────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────────────┐ ┌─────────────────────┐ │
│ │ AgentEnvToMCP │ │ MCPToAgentEnv │ │
│ │ (Export) │ │ (Import) │ │
│ ├─────────────────────┤ ├─────────────────────┤ │
│ │ BaseEnvClient ──────┼──► MCP │ MCP Server ─────────┼──► BaseEnvClient│
│ │ │ Server │ │ │
│ │ • reset() │ Tools: │ MCP Tools become: │ │
│ │ • step() │ • reset │ • FUNCTION_DESC │ │
│ │ • observe() │ • step │ • ActionFormat │ │
│ │ │ • observe│ • step() mapping │ │
│ └─────────────────────┘ └─────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────────────┘
```

## Usage

### Export: AgentEnv as MCP Server

```python
from agentenv_mcp import AgentEnvMCPServer
from agentenv.envs.sciworld import SciworldEnvClient

# Create MCP server from any BaseEnvClient
server = AgentEnvMCPServer(
env_client_cls=SciworldEnvClient,
client_args={"env_server_base": "http://localhost:8000", "data_len": 100},
)

# Run as MCP server (stdio transport)
server.run()
```

### Import: MCP Server as AgentEnv

```python
from agentenv_mcp import MCPEnvClient, MCPTask

# Connect to any MCP server and use as AgentEnv
client = MCPEnvClient(
mcp_server_command=["python", "-m", "my_mcp_server"],
action_format="function_calling",
)

# Use with standard AgentGym evaluation
task = MCPTask(client_args={...})
```

## Examples

See `examples/` for complete demonstrations:

- `sciworld_mcp_server.py` - SciWorld exposed as MCP server
- `mcp_client_demo.py` - Using an MCP server as AgentEnv

## Testing

```bash
pytest tests/ -v
```

## Compatibility

This wrapper is designed to be fully compatible with:

- `BaseEnvClient` interface from `agentenv.controller`
- `BaseTask` for experience generation
- All `ActionFormat` types (REACT, FUNCTION_CALLING, CODE_AS_ACTION)
- `Agent` and `APIAgent` for evaluation
42 changes: 42 additions & 0 deletions agentenv-mcp/agentenv_mcp/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""
AgentEnv-MCP: Bidirectional MCP wrapper for AgentGym environments.

This package provides:
- AgentEnvMCPServer: Expose any AgentEnv as an MCP server
- MCPEnvClient: Adapt any MCP server into an AgentEnv client
- MCPTask: Task wrapper for MCP-based environments
"""

__version__ = "0.1.0"

# Lazy imports to avoid requiring all dependencies at import time
def __getattr__(name):
if name == "AgentEnvMCPServer":
from agentenv_mcp.agentenv_to_mcp import AgentEnvMCPServer
return AgentEnvMCPServer
elif name == "MCPEnvClient":
from agentenv_mcp.mcp_to_agentenv import MCPEnvClient
return MCPEnvClient
elif name == "MCPAdapter":
from agentenv_mcp.mcp_to_agentenv import MCPAdapter
return MCPAdapter
elif name == "MCPTask":
from agentenv_mcp.mcp_to_agentenv import MCPTask
return MCPTask
elif name == "function_desc_to_mcp_tool":
from agentenv_mcp.schema_utils import function_desc_to_mcp_tool
return function_desc_to_mcp_tool
elif name == "mcp_tool_to_function_desc":
from agentenv_mcp.schema_utils import mcp_tool_to_function_desc
return mcp_tool_to_function_desc
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")


__all__ = [
"AgentEnvMCPServer",
"MCPEnvClient",
"MCPAdapter",
"MCPTask",
"function_desc_to_mcp_tool",
"mcp_tool_to_function_desc",
]
Loading