|
| 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