#!/usr/bin/env python3 """ Test script for MCP-LLM Adapter. """ import sys from pathlib import Path # Add current directory to path current_dir = Path(__file__).parent sys.path.insert(0, str(current_dir)) from adapter import MCPAdapter def test_discover_tools(): """Test tool discovery.""" print("Testing tool discovery...") adapter = MCPAdapter() tools = adapter.discover_tools() print(f"✓ Discovered {len(tools)} tools:") for tool in tools: func = tool.get("function", {}) print(f" - {func.get('name')}: {func.get('description', '')[:50]}...") return len(tools) > 0 def test_call_tool(): """Test tool calling.""" print("\nTesting tool calling...") adapter = MCPAdapter() # Test echo tool print(" Testing echo tool...") result = adapter.call_tool({ "name": "echo", "arguments": {"text": "Hello from adapter!"} }) print(f" ✓ Echo result: {result}") # Test weather tool print(" Testing weather tool...") result = adapter.call_tool({ "name": "weather", "arguments": {"location": "New York, NY"} }) print(f" ✓ Weather result: {result[:100]}...") # Test time tool print(" Testing get_current_time tool...") result = adapter.call_tool({ "name": "get_current_time", "arguments": {} }) print(f" ✓ Time result: {result[:100]}...") return True def test_health_check(): """Test health check.""" print("\nTesting health check...") adapter = MCPAdapter() is_healthy = adapter.health_check() if is_healthy: print("✓ MCP server is healthy") else: print("✗ MCP server health check failed") return is_healthy def test_get_tools_for_llm(): """Test getting tools in LLM format.""" print("\nTesting get_tools_for_llm...") adapter = MCPAdapter() tools = adapter.get_tools_for_llm() print(f"✓ Got {len(tools)} tools in LLM format:") for tool in tools[:3]: # Show first 3 print(f" - {tool.get('name')}") return len(tools) > 0 if __name__ == "__main__": print("=" * 50) print("MCP-LLM Adapter Test Suite") print("=" * 50) try: # Test health first if not test_health_check(): print("\n✗ Health check failed - make sure MCP server is running") print(" Run: cd ../mcp-server && ./run.sh") sys.exit(1) # Test discovery if not test_discover_tools(): print("\n✗ Tool discovery failed") sys.exit(1) # Test tool calling if not test_call_tool(): print("\n✗ Tool calling failed") sys.exit(1) # Test LLM format if not test_get_tools_for_llm(): print("\n✗ LLM format conversion failed") sys.exit(1) print("\n" + "=" * 50) print("✓ All tests passed!") print("=" * 50) except Exception as e: print(f"\n✗ Test failed: {e}") import traceback traceback.print_exc() sys.exit(1)