Skip to main content
Glama
check_system_status.pyโ€ข14.2 kB
#!/usr/bin/env python3 """ System Status Checker Comprehensive check of all MCP system components """ import requests import json import sys from datetime import datetime from typing import Dict, Any class SystemStatusChecker: """Check the status of all MCP system components.""" def __init__(self, base_url: str = "http://localhost:8000"): self.base_url = base_url self.results = {} def check_server_health(self) -> Dict[str, Any]: """Check server health.""" print("๐Ÿ” Checking Server Health...") try: response = requests.get(f"{self.base_url}/api/health", timeout=10) if response.status_code == 200: health_data = response.json() print(f" โœ… Server Status: {health_data.get('status', 'unknown')}") print(f" โœ… Server Ready: {health_data.get('ready', False)}") print(f" โœ… MongoDB Connected: {health_data.get('mongodb_connected', False)}") print(f" โœ… Inter-Agent Communication: {health_data.get('inter_agent_communication', False)}") system_info = health_data.get('system', {}) print(f" ๐Ÿ“Š Loaded Agents: {system_info.get('loaded_agents', 0)}") print(f" ๐Ÿ“Š Failed Agents: {system_info.get('failed_agents', 0)}") print(f" ๐Ÿ“Š Total Discovered: {system_info.get('total_discovered', 0)}") return {"status": "healthy", "data": health_data} else: print(f" โŒ Server Health Check Failed: HTTP {response.status_code}") return {"status": "unhealthy", "error": f"HTTP {response.status_code}"} except Exception as e: print(f" โŒ Server Health Check Error: {e}") return {"status": "error", "error": str(e)} def check_agents_status(self) -> Dict[str, Any]: """Check agents status.""" print("\n๐Ÿค– Checking Agents Status...") try: response = requests.get(f"{self.base_url}/api/agents", timeout=10) if response.status_code == 200: agents_data = response.json() agents = agents_data.get('agents', {}) summary = agents_data.get('summary', {}) print(f" ๐Ÿ“Š Total Agents: {summary.get('total_agents', 0)}") print(f" โœ… Loaded Agents: {summary.get('loaded_agents', 0)}") print(f" โŒ Failed Agents: {summary.get('failed_agents', 0)}") print(f" ๐Ÿ” Discovered Agents: {summary.get('discovered_agents', 0)}") print("\n ๐Ÿ“‹ Agent Details:") for agent_id, agent_info in agents.items(): status = agent_info.get('status', 'unknown') if status == 'loaded': print(f" โœ… {agent_id}: {status}") elif status == 'failed': error = agent_info.get('error', 'Unknown error') print(f" โŒ {agent_id}: {status} - {error[:50]}...") else: print(f" โš ๏ธ {agent_id}: {status}") return {"status": "checked", "data": agents_data} else: print(f" โŒ Agents Check Failed: HTTP {response.status_code}") return {"status": "error", "error": f"HTTP {response.status_code}"} except Exception as e: print(f" โŒ Agents Check Error: {e}") return {"status": "error", "error": str(e)} def test_command_processing(self) -> Dict[str, Any]: """Test command processing.""" print("\n๐Ÿงช Testing Command Processing...") test_commands = [ {"command": "Calculate 25 * 4", "expected_agent": "math_agent"}, {"command": "What is the weather in Mumbai?", "expected_agent": "weather_agent"}, {"command": "Analyze this text: Hello world", "expected_agent": "document_agent"} ] results = [] for test in test_commands: print(f"\n ๐Ÿ“ค Testing: {test['command']}") try: response = requests.post( f"{self.base_url}/api/mcp/command", json={"command": test['command']}, timeout=15 ) if response.status_code == 200: result = response.json() status = result.get('status', 'unknown') agent_used = result.get('agent_used', 'unknown') stored = result.get('stored_in_mongodb', False) print(f" โœ… Status: {status}") print(f" ๐Ÿค– Agent Used: {agent_used}") print(f" ๐Ÿ’พ MongoDB Stored: {stored}") if 'result' in result: print(f" ๐Ÿ“Š Result: {result['result']}") elif 'city' in result: print(f" ๐ŸŒ City: {result['city']}") elif 'message' in result: print(f" ๐Ÿ’ฌ Message: {result['message'][:50]}...") results.append({ "command": test['command'], "status": status, "agent_used": agent_used, "stored": stored, "success": status == "success" }) else: print(f" โŒ HTTP Error: {response.status_code}") results.append({ "command": test['command'], "status": "http_error", "error": response.status_code, "success": False }) except Exception as e: print(f" โŒ Error: {e}") results.append({ "command": test['command'], "status": "error", "error": str(e), "success": False }) successful_tests = sum(1 for r in results if r.get('success', False)) print(f"\n ๐Ÿ“Š Command Processing Results: {successful_tests}/{len(results)} successful") return {"status": "tested", "results": results, "success_rate": successful_tests / len(results)} def check_mongodb_storage(self) -> Dict[str, Any]: """Check MongoDB storage functionality.""" print("\n๐Ÿ’พ Checking MongoDB Storage...") # Test with a simple command that should store data try: response = requests.post( f"{self.base_url}/api/mcp/command", json={"command": "Calculate 10 + 5"}, timeout=10 ) if response.status_code == 200: result = response.json() stored = result.get('stored_in_mongodb', False) mongodb_id = result.get('mongodb_id', None) storage_method = result.get('storage_method', 'unknown') print(f" ๐Ÿ’พ Storage Status: {'โœ… Stored' if stored else 'โŒ Not Stored'}") print(f" ๐Ÿ†” MongoDB ID: {mongodb_id if mongodb_id else 'None'}") print(f" ๐Ÿ”ง Storage Method: {storage_method}") return { "status": "checked", "stored": stored, "mongodb_id": mongodb_id, "storage_method": storage_method } else: print(f" โŒ Storage Test Failed: HTTP {response.status_code}") return {"status": "error", "error": f"HTTP {response.status_code}"} except Exception as e: print(f" โŒ Storage Test Error: {e}") return {"status": "error", "error": str(e)} def check_agent_discovery(self) -> Dict[str, Any]: """Check agent discovery functionality.""" print("\n๐Ÿ” Checking Agent Discovery...") try: response = requests.get(f"{self.base_url}/api/agents/discover", timeout=10) if response.status_code == 200: discovery_data = response.json() discovered = discovery_data.get('discovered', {}) print(f" ๐Ÿ“‚ Live Agents: {len(discovered.get('live', []))}") print(f" ๐Ÿ“‚ Inactive Agents: {len(discovered.get('inactive', []))}") print(f" ๐Ÿ“‚ Future Agents: {len(discovered.get('future', []))}") print(f" ๐Ÿ“‚ Template Agents: {len(discovered.get('templates', []))}") for folder, agents in discovered.items(): if agents: print(f" {folder}: {', '.join(agents)}") return {"status": "checked", "data": discovery_data} else: print(f" โŒ Discovery Check Failed: HTTP {response.status_code}") return {"status": "error", "error": f"HTTP {response.status_code}"} except Exception as e: print(f" โŒ Discovery Check Error: {e}") return {"status": "error", "error": str(e)} def generate_summary(self) -> Dict[str, Any]: """Generate comprehensive system summary.""" print("\n" + "="*80) print("๐Ÿ“Š COMPREHENSIVE SYSTEM STATUS SUMMARY") print("="*80) # Calculate overall health health_checks = [ self.results.get('server_health', {}).get('status') == 'healthy', self.results.get('agents_status', {}).get('status') == 'checked', self.results.get('command_processing', {}).get('success_rate', 0) > 0.5, self.results.get('mongodb_storage', {}).get('stored', False), self.results.get('agent_discovery', {}).get('status') == 'checked' ] healthy_components = sum(health_checks) total_components = len(health_checks) overall_health = (healthy_components / total_components) * 100 print(f"๐ŸŽฏ Overall System Health: {overall_health:.1f}% ({healthy_components}/{total_components} components healthy)") # Component status print(f"\n๐Ÿ“‹ Component Status:") print(f" ๐Ÿš€ Server: {'โœ… Healthy' if health_checks[0] else 'โŒ Unhealthy'}") print(f" ๐Ÿค– Agents: {'โœ… Working' if health_checks[1] else 'โŒ Issues'}") print(f" ๐Ÿงช Command Processing: {'โœ… Working' if health_checks[2] else 'โŒ Issues'}") print(f" ๐Ÿ’พ MongoDB Storage: {'โœ… Working' if health_checks[3] else 'โŒ Issues'}") print(f" ๐Ÿ” Agent Discovery: {'โœ… Working' if health_checks[4] else 'โŒ Issues'}") # Recommendations print(f"\n๐Ÿ’ก Recommendations:") if overall_health >= 90: print(" ๐ŸŽ‰ Excellent! System is running optimally.") elif overall_health >= 70: print(" ๐Ÿ‘ Good! System is mostly functional with minor issues.") elif overall_health >= 50: print(" โš ๏ธ Fair! System has some issues that need attention.") else: print(" ๐Ÿ”ง Poor! System needs significant attention.") # Specific issues if not health_checks[0]: print(" ๐Ÿ”ง Fix server health issues") if not health_checks[1]: print(" ๐Ÿ”ง Resolve agent loading problems") if not health_checks[2]: print(" ๐Ÿ”ง Debug command processing failures") if not health_checks[3]: print(" ๐Ÿ”ง Fix MongoDB storage connectivity") if not health_checks[4]: print(" ๐Ÿ”ง Resolve agent discovery issues") return { "overall_health_percent": overall_health, "healthy_components": healthy_components, "total_components": total_components, "component_status": { "server": health_checks[0], "agents": health_checks[1], "command_processing": health_checks[2], "mongodb_storage": health_checks[3], "agent_discovery": health_checks[4] }, "timestamp": datetime.now().isoformat() } def run_full_check(self) -> Dict[str, Any]: """Run comprehensive system check.""" print("๐Ÿงช COMPREHENSIVE MCP SYSTEM STATUS CHECK") print("="*80) print(f"๐Ÿ• Started at: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}") print("="*80) # Run all checks self.results['server_health'] = self.check_server_health() self.results['agents_status'] = self.check_agents_status() self.results['command_processing'] = self.test_command_processing() self.results['mongodb_storage'] = self.check_mongodb_storage() self.results['agent_discovery'] = self.check_agent_discovery() # Generate summary self.results['summary'] = self.generate_summary() print(f"\n๐Ÿ• Completed at: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}") print("="*80) return self.results def main(): """Main function.""" checker = SystemStatusChecker() results = checker.run_full_check() # Save results to file with open('system_status_report.json', 'w') as f: json.dump(results, f, indent=2, default=str) print(f"\n๐Ÿ“„ Detailed report saved to: system_status_report.json") # Return exit code based on overall health overall_health = results['summary']['overall_health_percent'] if overall_health >= 70: sys.exit(0) # Success else: sys.exit(1) # Issues detected if __name__ == "__main__": main()

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/tensorwhiz141/MCP2'

If you have feedback or need assistance with the MCP directory API, please join our Discord server