feat(agentenv-mcp): Bidirectional MCP wrapper for AgentGym environments#69
Closed
supmo668 wants to merge 6 commits into
Closed
feat(agentenv-mcp): Bidirectional MCP wrapper for AgentGym environments#69supmo668 wants to merge 6 commits into
supmo668 wants to merge 6 commits into
Conversation
Add new agentenv-mcp package for MCP (Model Context Protocol) integration: - pyproject.toml: Package configuration with dependencies - README.md: Documentation with architecture overview - __init__.py: Lazy imports for optional dependencies This package provides bidirectional wrappers between AgentGym environments and MCP servers.
Add schema_utils.py with functions to convert between formats: - function_desc_to_mcp_tool(): AgentEnv → MCP tool schema - mcp_tool_to_function_desc(): MCP tool → AgentEnv function desc - Batch conversion helpers for tool lists These utilities enable seamless conversion between AgentGym's function description format and MCP's tool schema format.
Add AgentEnvMCPServer class that wraps any BaseEnvClient as MCP server:
- Exposes environment actions as MCP tools (action_*)
- Provides management tools: env_reset, env_step, env_observe, env_info
- Supports both ReAct and function_calling action formats
- Lazy client creation for efficient resource usage
- Async handlers for all MCP tool calls
Usage:
server = AgentEnvMCPServer(
env_client_cls=SciworldEnvClient,
client_args={...},
function_descriptions=SCIWORLD_FUNCTION_DESCRIPTION,
)
server.run()
Add classes to wrap MCP servers as AgentGym-compatible clients: MCPAdapter: - Parses actions in REACT, FUNCTION_CALLING, CODE_AS_ACTION formats - Generates conversation_start prompts from function descriptions - Converts parsed actions to MCP tool calls MCPEnvClient (implements BaseEnvClient interface): - Connects to MCP servers via stdio transport - Auto-discovers tools and generates function descriptions - Maps step() calls to MCP tool invocations - Full compatibility with AgentGym evaluation pipeline MCPTask: - Task wrapper for experience generation - Compatible with Agent and APIAgent classes
Add proof-of-concept examples using SciWorld environment: sciworld_mcp_server.py: - Wraps SciWorld as an MCP server - Includes full SCIWORLD_FUNCTION_DESCRIPTION - Demonstrates AgentEnvMCPServer usage mcp_client_demo.py: - Shows how to use MCP server as AgentEnv client - Demonstrates reset, observe, step operations - Example of function_calling format actions Usage: # Start SciWorld env server first uvicorn agentenv_sciworld.server:app --port 8000 # Run MCP server python -m agentenv_mcp.examples.sciworld_mcp_server
Add tests for all wrapper components: test_schema_utils.py (9 tests): - Schema conversion functions - Round-trip conversion verification - SciWorld function description handling test_agentenv_to_mcp.py (9 tests): - AgentEnvMCPServer initialization - Handler methods (reset, step, observe, info, action) - ReAct formatting test_mcp_to_agentenv.py (8 tests): - Action parsing (ReAct, function_calling) - Tool call conversion - Interface compatibility checks test_sciworld_integration.py (7 tests): - Integration tests with SciWorld environment - End-to-end workflow verification - Skipped by default (requires running server) Run tests: pytest tests/ -v
Author
|
Closing to rewrite using FastMCP (the standard MCP framework). The initial implementation used low-level mcp library but FastMCP provides better patterns including:
Will reopen with FastMCP-based implementation that better integrates with the existing AgentGym architecture. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
Bidirectional MCP wrappers for AgentGym environments. Addresses feedback from PR #68.
Architecture
flowchart LR subgraph AgentEnvToMCP["AgentEnv → MCP"] A[BaseEnvClient] --> B[AgentEnvMCPServer] B --> C[MCP Tools] end subgraph MCPToAgentEnv["MCP → AgentEnv"] D[MCP Server] --> E[MCPEnvClient] E --> F[BaseEnvClient API] endComponents
schema_utils.pyAgentEnvMCPServerBaseEnvClientas MCP serverMCPEnvClientBaseEnvClientfor MCP serversMCPAdapterActionFormattypesMCPTaskCompatibility
BaseEnvClient,BaseTask,BaseAdapterActionFormattypes (REACT, FUNCTION_CALLING, CODE_AS_ACTION)Tests
Commits