Skip to main content
Glama
one_click_connect.py•7.63 kB
#!/usr/bin/env python3 """ One-Click Connect - Complete MCP System Connector Connects everything: server, agents, MongoDB, and interactive interface """ import os import sys import time import subprocess import requests import webbrowser from datetime import datetime def print_status(message, status="info"): """Print formatted status message.""" icons = {"info": "šŸ”„", "success": "āœ…", "error": "āŒ", "warning": "āš ļø"} print(f"{icons.get(status, 'šŸ”„')} {message}") def main(): """One-click connection function.""" print("šŸš€ ONE-CLICK MCP SYSTEM CONNECTOR") print("=" * 60) print(f"šŸ• {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}") print("=" * 60) print("This script will connect everything in one click!") print("=" * 60) # Step 1: Check files print_status("Step 1: Checking required files...") required = ["production_mcp_server.py", ".env"] missing = [f for f in required if not os.path.exists(f)] if missing: print_status(f"Missing files: {missing}", "error") print("\nāŒ FAILED: Missing required files") return False print_status("All required files found", "success") # Step 2: Test MongoDB print_status("Step 2: Testing MongoDB connection...") try: sys.path.insert(0, "blackhole_core/data_source") from mongodb import test_connection if test_connection(): print_status("MongoDB connected successfully", "success") else: print_status("MongoDB connection failed (system will still work)", "warning") except Exception as e: print_status(f"MongoDB error: {e} (system will still work)", "warning") # Step 3: Start server print_status("Step 3: Starting MCP server...") # Check if already running try: response = requests.get("http://localhost:8000/api/health", timeout=3) if response.status_code == 200: print_status("Server already running", "success") else: raise Exception("Need to start server") except: # Start server try: if os.name == 'nt': # Windows subprocess.Popen([sys.executable, "production_mcp_server.py"], creationflags=subprocess.CREATE_NEW_CONSOLE) else: # Unix/Linux/Mac subprocess.Popen([sys.executable, "production_mcp_server.py"]) print_status("Waiting for server to initialize...") for i in range(20): try: response = requests.get("http://localhost:8000/api/health", timeout=2) if response.status_code == 200: health = response.json() agents = health.get('system', {}).get('loaded_agents', 0) print_status(f"Server started with {agents} agents", "success") break except: pass time.sleep(1) else: print_status("Server startup timeout", "error") print("\nāŒ FAILED: Could not start server") return False except Exception as e: print_status(f"Server start error: {e}", "error") print("\nāŒ FAILED: Could not start server") return False # Step 4: Test agents print_status("Step 4: Testing agents...") tests = [ ("Calculate 10 + 5", "math"), ("What is the weather in Mumbai?", "weather"), ("Analyze this text: test", "document") ] working = 0 for query, agent_type in tests: 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': working += 1 print_status(f"{agent_type} agent: working", "success") else: print_status(f"{agent_type} agent: failed", "warning") else: print_status(f"{agent_type} agent: HTTP error", "warning") except: print_status(f"{agent_type} agent: error", "warning") time.sleep(1) print_status(f"Agents working: {working}/{len(tests)}", "success" if working >= 2 else "warning") # Step 5: Test interface print_status("Step 5: Testing interactive interface...") 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_status("Interactive interface ready", "success") else: print_status("Interface not fully interactive", "warning") else: print_status("Interface not accessible", "error") except Exception as e: print_status(f"Interface test error: {e}", "error") # Step 6: Open browser print_status("Step 6: Opening web interface...") try: webbrowser.open("http://localhost:8000") print_status("Web interface opened", "success") except: print_status("Could not open browser automatically", "warning") print_status("Manually open: http://localhost:8000", "info") # Final report print("\n" + "=" * 60) print("šŸŽ‰ ONE-CLICK CONNECTION COMPLETE!") print("=" * 60) print("āœ… Your MCP system is ready to use!") print(f"\n🌐 ACCESS YOUR SYSTEM:") 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") print(f"\nšŸŽÆ HOW TO USE:") print("1. The web interface is now open in your browser") print("2. Type questions in the input box") print("3. Click example queries to try them") print("4. Get real-time responses from intelligent agents") print("5. All interactions are stored in MongoDB") print(f"\nāœ… WHAT'S WORKING:") print("āœ… Production MCP Server v2.0.0") print("āœ… Interactive Web Interface") print("āœ… MongoDB Integration") print("āœ… Smart Agent Routing") print("āœ… Real-time Query Processing") print("āœ… 3 Intelligent Agents (Math, Weather, Document)") return True if __name__ == "__main__": try: success = main() if success: print("\nšŸŽ‰ ALL CONNECTED! Your MCP system is ready!") print("🌐 Go to: http://localhost:8000") else: print("\nāš ļø Some issues occurred, but system may still be usable") except KeyboardInterrupt: print("\n\nāš ļø Connection interrupted by user") except Exception as e: print(f"\nāŒ Unexpected error: {e}") print("šŸ”§ Please check your setup and try again") print(f"\nšŸ• Completed at: {datetime.now().strftime('%H:%M:%S')}") print("=" * 60) print("šŸŽÆ Your one-click MCP connection is complete!")

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