#!/usr/bin/env python3
"""
Test Current MCP System
Simple tests to verify what's working
"""
import requests
import json
from datetime import datetime
def test_server_health():
"""Test if server is running."""
print("π TESTING SERVER HEALTH")
print("=" * 50)
try:
response = requests.get("http://localhost:8000/api/health", timeout=5)
if response.status_code == 200:
result = response.json()
print(f"β
Server Status: {result.get('status', 'unknown')}")
return True
else:
print(f"β Server error: {response.status_code}")
return False
except Exception as e:
print(f"β Cannot connect to server: {e}")
print("π‘ Make sure to run: python core/mcp_server.py")
return False
def test_simple_weather():
"""Test simple weather query."""
print("\nπ€οΈ TESTING SIMPLE WEATHER QUERY")
print("=" * 50)
try:
response = requests.post(
"http://localhost:8000/api/mcp/command",
json={"command": "What is the weather in Mumbai?"},
timeout=15
)
if response.status_code == 200:
result = response.json()
print(f"Status: {result.get('status', 'unknown')}")
print(f"Message: {result.get('message', 'No message')}")
print(f"Agent: {result.get('agent_used', 'unknown')}")
if result.get('status') == 'success':
print("β
Weather query successful!")
return True
else:
print("β Weather query failed")
return False
else:
print(f"β HTTP Error: {response.status_code}")
return False
except Exception as e:
print(f"β Weather test error: {e}")
return False
def test_simple_math():
"""Test simple math query."""
print("\nπ’ TESTING SIMPLE MATH QUERY")
print("=" * 50)
try:
response = requests.post(
"http://localhost:8000/api/mcp/command",
json={"command": "Calculate 20% of 500"},
timeout=10
)
if response.status_code == 200:
result = response.json()
print(f"Status: {result.get('status', 'unknown')}")
print(f"Message: {result.get('message', 'No message')}")
print(f"Agent: {result.get('agent_used', 'unknown')}")
if result.get('status') == 'success':
print("β
Math query successful!")
return True
else:
print("β Math query failed")
return False
else:
print(f"β HTTP Error: {response.status_code}")
return False
except Exception as e:
print(f"β Math test error: {e}")
return False
def test_available_agents():
"""Test what agents are available."""
print("\nπ€ TESTING AVAILABLE AGENTS")
print("=" * 50)
try:
response = requests.get("http://localhost:8000/api/mcp/agents", timeout=5)
if response.status_code == 200:
result = response.json()
agents = result.get("agents", {})
print(f"Total agents: {len(agents)}")
for name, info in agents.items():
desc = info.get("description", "No description")
print(f" β’ {name}: {desc}")
return len(agents) > 0
else:
print(f"β HTTP Error: {response.status_code}")
return False
except Exception as e:
print(f"β Agent list error: {e}")
return False
def test_conversation_engine():
"""Test if conversation engine is working."""
print("\nπ£οΈ TESTING CONVERSATION ENGINE")
print("=" * 50)
try:
# Test with a simple query
response = requests.post(
"http://localhost:8000/api/mcp/command",
json={"command": "Hello, are you working?"},
timeout=10
)
if response.status_code == 200:
result = response.json()
print(f"Status: {result.get('status', 'unknown')}")
print(f"Message: {result.get('message', 'No message')[:100]}...")
return result.get('status') == 'success'
else:
print(f"β HTTP Error: {response.status_code}")
return False
except Exception as e:
print(f"β Conversation test error: {e}")
return False
def main():
"""Main test function."""
print("π§ͺ CURRENT SYSTEM TEST")
print("=" * 80)
print("π― Testing what's currently working in your MCP system")
print("=" * 80)
tests = [
("Server Health", test_server_health),
("Available Agents", test_available_agents),
("Simple Weather", test_simple_weather),
("Simple Math", test_simple_math),
("Conversation Engine", test_conversation_engine)
]
passed_tests = 0
for test_name, test_function in tests:
try:
if test_function():
passed_tests += 1
print(f"β
{test_name} PASSED")
else:
print(f"β {test_name} FAILED")
except Exception as e:
print(f"β {test_name} ERROR: {e}")
print()
print("=" * 80)
print("π TEST RESULTS")
print("=" * 80)
print(f"β
Passed: {passed_tests}/{len(tests)}")
print(f"π Success rate: {(passed_tests/len(tests))*100:.1f}%")
if passed_tests >= 3:
print("\nπ SYSTEM IS MOSTLY WORKING!")
print("π‘ Try these working commands:")
print(" π€οΈ MCP> What is the weather in Mumbai?")
print(" π’ MCP> Calculate 20% of 500")
print(" π£οΈ MCP> Hello, how are you?")
print("\nπ§ FOR COMPLEX QUERIES:")
print(" Break them into separate commands:")
print(" 1. MCP> What is the weather in Mumbai?")
print(" 2. MCP> Calculate 20% discount on 500 rupees")
print(" 3. MCP> Extract text from image")
print(" 4. MCP> Create a story about weather and savings")
else:
print("\nπ§ SYSTEM NEEDS ATTENTION")
print("π‘ Check if the MCP server is running:")
print(" python core/mcp_server.py")
return passed_tests >= 3
if __name__ == "__main__":
try:
success = main()
if success:
print("\nπ System test completed!")
else:
print("\nπ§ System needs fixes.")
except Exception as e:
print(f"\nβ Test failed: {e}")