Skip to content

Commit 84a2919

Browse files
committed
[1/n] Implement RFC 003
1 parent 8d17d60 commit 84a2919

File tree

17 files changed

+1015
-187
lines changed

17 files changed

+1015
-187
lines changed

examples/echo_mcp_demo.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
"""
2+
Example: Using Echo Environment with MCP
3+
4+
This example demonstrates:
5+
1. Connecting to echo_env server
6+
2. Listing available tools via MCP
7+
3. Calling tools using both step() API and direct tool methods
8+
"""
9+
10+
import asyncio
11+
from envs.echo_env import EchoEnv
12+
13+
14+
async def main():
15+
# Connect to echo_env (assumes server is running on localhost:8000)
16+
# To start the server: uvicorn envs.echo_env.server.app:app
17+
client = EchoEnv(base_url="http://localhost:8000")
18+
19+
print("=== Echo Environment MCP Demo ===\n")
20+
21+
# Reset the environment
22+
print("1. Resetting environment...")
23+
result = client.reset()
24+
print(f" Reset result: {result.observation.metadata}\n")
25+
26+
# List available tools
27+
print("2. Listing available tools...")
28+
tools = client.list_tools()
29+
for tool in tools:
30+
print(f" - {tool['name']}: {tool['description']}")
31+
print()
32+
33+
# Call echo_message tool using convenience method
34+
print("3. Calling echo_message tool...")
35+
result = client.echo_message("Hello from MCP!")
36+
print(f" Result: {result}\n")
37+
38+
# Check environment state
39+
print("4. Checking environment state...")
40+
state = client.state
41+
print(f" Episode ID: {state.episode_id}")
42+
print(f" Step count: {state.step_count}\n")
43+
44+
print("Demo complete!")
45+
46+
47+
if __name__ == "__main__":
48+
asyncio.run(main())

examples/test_mcp_integration.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env python3
2+
"""Quick test script to verify MCP integration works."""
3+
4+
import asyncio
5+
import sys
6+
sys.path.insert(0, 'src')
7+
8+
from envs.echo_env.server.echo_environment import EchoEnvironment
9+
from core.env_server.types import ListToolsAction, CallToolAction
10+
11+
12+
async def main():
13+
print("=" * 60)
14+
print("Testing MCP Integration")
15+
print("=" * 60)
16+
17+
# Create echo environment (MCPEnvironment handles MCP setup automatically)
18+
print("\n1. Creating Echo Environment...")
19+
env = EchoEnvironment()
20+
21+
# Test list tools
22+
print("\n2. Testing ListToolsAction...")
23+
list_action = ListToolsAction()
24+
obs = await env._handle_mcp_action(list_action)
25+
print(f" - Done: {obs.done}")
26+
print(f" - Has 'tools' attribute: {hasattr(obs, 'tools')}")
27+
if hasattr(obs, "tools"):
28+
print(f" - Number of tools: {len(obs.tools)}")
29+
print(f" - Tool names: {[t['name'] for t in obs.tools]}")
30+
else:
31+
print(" - ERROR: No 'tools' attribute!")
32+
return False
33+
34+
# Test call tool
35+
print("\n3. Testing CallToolAction...")
36+
call_action = CallToolAction(
37+
tool_name="echo_message",
38+
parameters={"message": "Hello MCP!"}
39+
)
40+
obs = await env._handle_mcp_action(call_action)
41+
print(f" - Done: {obs.done}")
42+
print(f" - Has 'result' attribute: {hasattr(obs, 'result')}")
43+
print(f" - Error: {obs.error}")
44+
if hasattr(obs, "result") and obs.result is not None:
45+
result = obs.result
46+
print(f" - Result type: {type(result)}")
47+
print(f" - Result: {result}")
48+
else:
49+
print(" - ERROR: No 'result' attribute or result is None!")
50+
return False
51+
52+
print("\n" + "=" * 60)
53+
print("✅ All tests passed!")
54+
print("=" * 60)
55+
return True
56+
57+
58+
if __name__ == "__main__":
59+
success = asyncio.run(main())
60+
sys.exit(0 if success else 1)

0 commit comments

Comments
 (0)