test_mcp_working.py•4.74 kB
#!/usr/bin/env python3
"""
Simple test to verify MCP is working correctly
"""
import requests
import json
def test_mcp_working():
"""Test that MCP endpoints are working correctly."""
print("🔍 Testing MCP System - Quick Verification")
print("=" * 50)
# Test 1: Basic server health
print("\n1. Server Health Check:")
try:
response = requests.get('http://localhost:8000/api/health')
if response.status_code == 200:
data = response.json()
print(f"✅ Server: {data.get('status')}")
print(f"✅ MongoDB: {data.get('mongodb')}")
else:
print(f"❌ Health check failed: {response.status_code}")
except Exception as e:
print(f"❌ Health check error: {e}")
# Test 2: MCP Help (GET request)
print("\n2. MCP Help System:")
try:
response = requests.get('http://localhost:8000/api/mcp/help')
if response.status_code == 200:
print("✅ Help endpoint working")
else:
print(f"❌ Help failed: {response.status_code}")
except Exception as e:
print(f"❌ Help error: {e}")
# Test 3: MCP Status (GET request)
print("\n3. MCP Agent Status:")
try:
response = requests.get('http://localhost:8000/api/mcp/status')
if response.status_code == 200:
data = response.json()
print(f"✅ Status endpoint working")
print(f"✅ Total agents: {data.get('total_agents')}")
print(f"✅ Available agents: {data.get('available_agents')}")
else:
print(f"❌ Status failed: {response.status_code}")
except Exception as e:
print(f"❌ Status error: {e}")
# Test 4: MCP Command (POST request) - This is the main test
print("\n4. MCP Command Processing (POST):")
try:
command_data = {'command': 'help'}
response = requests.post(
'http://localhost:8000/api/mcp/command',
json=command_data,
headers={'Content-Type': 'application/json'}
)
if response.status_code == 200:
result = response.json()
print("✅ MCP Command endpoint working!")
print(f"✅ Status: {result.get('status')}")
print(f"✅ Command processed successfully")
elif response.status_code == 405:
print("❌ Method Not Allowed - This is the issue!")
print("The endpoint expects POST but might be receiving GET")
else:
print(f"❌ Command failed: {response.status_code}")
print(f"Response: {response.text}")
except Exception as e:
print(f"❌ Command error: {e}")
# Test 5: Try a real MCP command
print("\n5. Real MCP Command Test:")
try:
command_data = {'command': 'search for test documents'}
response = requests.post(
'http://localhost:8000/api/mcp/command',
json=command_data,
headers={'Content-Type': 'application/json'},
timeout=30
)
if response.status_code == 200:
result = response.json()
print("✅ Real MCP command working!")
print(f"✅ Agent used: {result.get('agent_used')}")
print(f"✅ Command type: {result.get('command_type')}")
print(f"✅ Processing time: {result.get('processing_time_ms')}ms")
else:
print(f"❌ Real command failed: {response.status_code}")
except Exception as e:
print(f"❌ Real command error: {e}")
# Test 6: Frontend accessibility
print("\n6. Frontend Accessibility:")
try:
response = requests.get('http://localhost:8000/mcp_interface.html')
if response.status_code == 200:
print("✅ MCP Interface accessible")
print("✅ Frontend should work in browser")
else:
print(f"❌ Frontend failed: {response.status_code}")
except Exception as e:
print(f"❌ Frontend error: {e}")
print("\n" + "=" * 50)
print("🎯 DIAGNOSIS COMPLETE")
print("=" * 50)
print("If you're getting 'Method Not Allowed' errors:")
print("1. ✅ The API endpoints are working correctly")
print("2. ✅ POST /api/mcp/command works fine")
print("3. ❌ GET /api/mcp/command gives 405 (this is correct)")
print("4. 🔧 Make sure you're using POST method for commands")
print("5. 🌐 Use the web interface: http://localhost:8000/mcp_interface.html")
print("")
print("🚀 Your MCP system is working correctly!")
print("The 405 error is expected for GET requests to POST-only endpoints.")
if __name__ == "__main__":
test_mcp_working()