[RFC 003] Add MCP (Model Context Protocol) support - Phase 1#290
Closed
Darktex wants to merge 2 commits into
Closed
[RFC 003] Add MCP (Model Context Protocol) support - Phase 1#290Darktex wants to merge 2 commits into
Darktex wants to merge 2 commits into
Conversation
Implements RFC 003 for MCP integration in OpenEnv: Core MCP Infrastructure: - Add mcp_types.py with Tool, ToolError, ListToolsAction, CallToolAction, and corresponding observations - Add MCPEnvironment base class with reserved tool name validation, timeout handling, and proper error categorization - Add WebSocket MCP message handler for JSON-RPC via "type: mcp" messages Echo Environment Reference Implementation: - Add mcp_server.py with echo_message and echo_with_length tools - Update echo_environment.py with MCP action support while maintaining backwards compatibility with EchoAction Design decisions: - WebSocket-only for MCP (no HTTP /mcp endpoint) - Per-environment MCP client lifecycle - Both step() and WebSocket /mcp paths supported - reset() NOT required for list_tools() - Reserved tool names (reset, step, state, close) raise hard error Adds fastmcp>=2.0.0 dependency and comprehensive tests.
The directory name 'mcp' was shadowing the external mcp package during pytest collection, causing 'No module named mcp.types' errors.
Collaborator
Author
|
Closing in favor of updating PR #224 |
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.
Summary
This PR implements RFC 003: MCP (Model Context Protocol) support for OpenEnv - Phase 1.
Tool,ToolError,ListToolsAction,CallToolAction,ListToolsObservation,CallToolObservationMCPEnvironmentbase class for MCP-enabled environments with reserved tool name validationtools/list,tools/call)Key Design Decisions
type: "mcp"WebSocket messages (no HTTP/mcpendpoint)step(ListToolsAction/CallToolAction)for training, WebSocket/mcpfor productionreset,step,state, orcloseare registered (protects dual API boundary)Files Changed
Core MCP Infrastructure:
src/openenv/core/env_server/mcp_types.py- Tool, ToolError, actions/observations, WS message typessrc/openenv/core/env_server/mcp_environment.py- MCPEnvironment base classsrc/openenv/core/env_server/http_server.py- WebSocket MCP handlersrc/openenv/core/env_server/__init__.py- ExportsEcho Environment Reference:
envs/echo_env/server/mcp_server.py- FastMCP tool definitionsenvs/echo_env/server/echo_environment.py- MCP action supportTests:
tests/core/test_mcp/test_mcp_types.py- 18 teststests/core/test_mcp/test_mcp_environment.py- 12 testsTest plan
PYTHONPATH=src:envs pytest tests/core/test_mcp/ -v