#!/usr/bin/env python3
"""
Connection Status Summary
Quick summary of all MCP system connections
"""
import requests
import sys
from datetime import datetime
def check_connection_status():
"""Check and display connection status."""
print("π MCP SYSTEM CONNECTION STATUS")
print("=" * 60)
print(f"π {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
print("=" * 60)
# 1. Server Health
print("\nπ SERVER STATUS:")
try:
response = requests.get("http://localhost:8000/api/health", timeout=5)
if response.status_code == 200:
health = response.json()
print(f" β
Status: {health.get('status', 'unknown').upper()}")
print(f" β
Ready: {health.get('ready', False)}")
print(f" β
Agents Loaded: {health.get('system', {}).get('loaded_agents', 0)}")
print(f" β
MongoDB Connected: {health.get('mongodb_connected', False)}")
server_ok = True
else:
print(f" β Server Error: HTTP {response.status_code}")
server_ok = False
except Exception as e:
print(f" β Server Not Running: {e}")
server_ok = False
# 2. MongoDB Connection
print("\nπΎ MONGODB STATUS:")
try:
sys.path.insert(0, "blackhole_core/data_source")
from mongodb import test_connection, get_agent_outputs_collection
if test_connection():
collection = get_agent_outputs_collection()
doc_count = collection.count_documents({})
print(f" β
Connection: Working")
print(f" β
Documents Stored: {doc_count}")
mongodb_ok = True
else:
print(f" β Connection: Failed")
mongodb_ok = False
except Exception as e:
print(f" β MongoDB Error: {e}")
mongodb_ok = False
# 3. Agent Functionality
print("\nπ€ AGENT FUNCTIONALITY:")
if server_ok:
test_queries = [
("Calculate 5 + 5", "Math Agent"),
("What is the weather in Mumbai?", "Weather Agent"),
("Analyze this text: test", "Document Agent")
]
working_agents = 0
for query, agent_name in test_queries:
try:
response = requests.post(
"http://localhost:8000/api/mcp/command",
json={"command": query},
timeout=15
)
if response.status_code == 200:
result = response.json()
if result.get('status') == 'success':
print(f" β
{agent_name}: Working")
working_agents += 1
else:
print(f" β {agent_name}: Failed")
else:
print(f" β {agent_name}: HTTP Error")
except Exception as e:
print(f" β {agent_name}: Error")
agents_ok = working_agents >= 2
print(f" π Working Agents: {working_agents}/3")
else:
print(" β οΈ Cannot test agents - server not running")
agents_ok = False
# 4. Web Interface
print("\nπ WEB INTERFACE:")
if server_ok:
try:
response = requests.get("http://localhost:8000", timeout=5)
if response.status_code == 200:
content = response.text
interactive = all(element in content for element in [
'id="queryInput"', 'sendQuery()', 'class="example"'
])
if interactive:
print(" β
Interactive Interface: Working")
print(" β
All Elements: Present")
interface_ok = True
else:
print(" β οΈ Interface: Partially Working")
interface_ok = False
else:
print(f" β Interface: HTTP {response.status_code}")
interface_ok = False
except Exception as e:
print(f" β Interface Error: {e}")
interface_ok = False
else:
print(" β οΈ Cannot test interface - server not running")
interface_ok = False
# 5. Overall Status
print("\n" + "=" * 60)
print("π OVERALL CONNECTION STATUS")
print("=" * 60)
components = [
("Server", server_ok),
("MongoDB", mongodb_ok),
("Agents", agents_ok),
("Web Interface", interface_ok)
]
working = sum(1 for _, status in components if status)
total = len(components)
health_score = (working / total) * 100
for name, status in components:
icon = "β
" if status else "β"
print(f"{icon} {name}: {'Working' if status else 'Issues'}")
print(f"\nπ― System Health: {health_score:.0f}% ({working}/{total} components)")
if health_score >= 90:
print("π EXCELLENT! All connections working perfectly!")
status_msg = "PERFECT"
elif health_score >= 75:
print("π GOOD! Most connections working well!")
status_msg = "GOOD"
elif health_score >= 50:
print("β οΈ FAIR! System partially functional!")
status_msg = "PARTIAL"
else:
print("β POOR! Major connection issues!")
status_msg = "ISSUES"
print(f"\nπ ACCESS YOUR SYSTEM:")
if server_ok:
print("π Web Interface: http://localhost:8000")
print("π Health Check: http://localhost:8000/api/health")
print("π€ Agent Status: http://localhost:8000/api/agents")
print(f"\n㪠TRY THESE QUERIES:")
print("π’ Calculate 25 * 4")
print("π€οΈ What is the weather in Mumbai?")
print("π Analyze this text: Hello world")
else:
print("β οΈ Start server first: python production_mcp_server.py")
return status_msg, health_score
def main():
"""Main function."""
try:
status, score = check_connection_status()
print(f"\nπ― FINAL STATUS: {status} ({score:.0f}%)")
if score >= 75:
print("β
Your MCP system connections are working fine!")
return True
else:
print("β οΈ Some connection issues detected - check details above")
return False
except Exception as e:
print(f"\nβ Connection check failed: {e}")
return False
if __name__ == "__main__":
success = main()
if success:
print("\nπ Connection check completed - all good!")
else:
print("\nπ§ Connection check completed - some issues found")