test_current_system.pyโข6.81 kB
#!/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}")