-
Notifications
You must be signed in to change notification settings - Fork 115
[RFC 003] [1/n] Implement basic local MCP server & add MCP client #224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Darktex
wants to merge
1
commit into
main
Choose a base branch
from
rfc-003-first-pr
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| """ | ||
| Example: Using Echo Environment with MCP | ||
|
|
||
| This example demonstrates: | ||
| 1. Connecting to echo_env server | ||
| 2. Listing available tools via MCP | ||
| 3. Calling tools using both step() API and direct tool methods | ||
| """ | ||
|
|
||
| import asyncio | ||
| from envs.echo_env import EchoEnv | ||
|
|
||
|
|
||
| async def main(): | ||
| # Connect to echo_env (assumes server is running on localhost:8000) | ||
| # To start the server: uvicorn envs.echo_env.server.app:app | ||
| client = EchoEnv(base_url="http://localhost:8000") | ||
|
|
||
| print("=== Echo Environment MCP Demo ===\n") | ||
|
|
||
| # Reset the environment | ||
| print("1. Resetting environment...") | ||
| result = client.reset() | ||
| print(f" Reset result: {result.observation.metadata}\n") | ||
|
|
||
| # List available tools | ||
| print("2. Listing available tools...") | ||
| tools = client.list_tools() | ||
| for tool in tools: | ||
| print(f" - {tool['name']}: {tool['description']}") | ||
| print() | ||
|
|
||
| # Call echo_message tool using convenience method | ||
| print("3. Calling echo_message tool...") | ||
| result = client.echo_message("Hello from MCP!") | ||
|
||
| print(f" Result: {result}\n") | ||
|
|
||
| # Check environment state | ||
| print("4. Checking environment state...") | ||
| state = client.state | ||
| print(f" Episode ID: {state.episode_id}") | ||
| print(f" Step count: {state.step_count}\n") | ||
|
|
||
| print("Demo complete!") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| asyncio.run(main()) | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| #!/usr/bin/env python3 | ||
| """Quick test script to verify MCP integration works.""" | ||
|
|
||
| import asyncio | ||
| import sys | ||
| sys.path.insert(0, 'src') | ||
|
|
||
| from envs.echo_env.server.echo_environment import EchoEnvironment | ||
| from core.env_server.types import ListToolsAction, CallToolAction | ||
|
|
||
|
|
||
| async def main(): | ||
| print("=" * 60) | ||
| print("Testing MCP Integration") | ||
| print("=" * 60) | ||
|
|
||
| # Create echo environment (MCPEnvironment handles MCP setup automatically) | ||
| print("\n1. Creating Echo Environment...") | ||
| env = EchoEnvironment() | ||
|
|
||
| # Test list tools | ||
| print("\n2. Testing ListToolsAction...") | ||
| list_action = ListToolsAction() | ||
| obs = await env._handle_mcp_action(list_action) | ||
| print(f" - Done: {obs.done}") | ||
| print(f" - Has 'tools' attribute: {hasattr(obs, 'tools')}") | ||
| if hasattr(obs, "tools"): | ||
| print(f" - Number of tools: {len(obs.tools)}") | ||
| print(f" - Tool names: {[t['name'] for t in obs.tools]}") | ||
| else: | ||
| print(" - ERROR: No 'tools' attribute!") | ||
| return False | ||
|
|
||
| # Test call tool | ||
| print("\n3. Testing CallToolAction...") | ||
| call_action = CallToolAction( | ||
| tool_name="echo_message", | ||
| parameters={"message": "Hello MCP!"} | ||
| ) | ||
| obs = await env._handle_mcp_action(call_action) | ||
| print(f" - Done: {obs.done}") | ||
| print(f" - Has 'result' attribute: {hasattr(obs, 'result')}") | ||
| print(f" - Error: {obs.error}") | ||
| if hasattr(obs, "result") and obs.result is not None: | ||
| result = obs.result | ||
| print(f" - Result type: {type(result)}") | ||
| print(f" - Result: {result}") | ||
| else: | ||
| print(" - ERROR: No 'result' attribute or result is None!") | ||
| return False | ||
|
|
||
| print("\n" + "=" * 60) | ||
| print("✅ All tests passed!") | ||
| print("=" * 60) | ||
| return True | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| success = asyncio.run(main()) | ||
| sys.exit(0 if success else 1) |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
list_tools()method is not implemented in theEchoEnvclient class (see client.py). This call will fail with anAttributeError. Either implement the method in the client or use thestep()method with aListToolsAction.