Skip to main content
Glama

MCP Learning Project

by BerdTan
restart_server.pyโ€ข4.28 kB
#!/usr/bin/env python3 """ Restart MCP Server Script Stops existing servers and starts the enhanced MCP harness """ import os import sys import subprocess import time import signal from pathlib import Path def find_and_kill_processes(): """Find and kill Python processes that might be running our servers.""" print("๐Ÿ” Looking for running MCP server processes...") try: # Find Python processes that might be our servers result = subprocess.run(['netstat', '-ano'], capture_output=True, text=True) if result.returncode == 0: lines = result.stdout.split('\n') python_processes = [] for line in lines: if '8000' in line or '3001' in line or '3002' in line or '3003' in line: print(f"๐Ÿ“ Found process using port: {line.strip()}") # Extract PID from the last column parts = line.strip().split() if len(parts) > 4: try: pid = int(parts[-1]) python_processes.append(pid) except ValueError: pass # Kill the processes for pid in python_processes: try: print(f"๐Ÿ›‘ Stopping process {pid}...") os.kill(pid, signal.SIGTERM) time.sleep(1) except ProcessLookupError: print(f"โš ๏ธ Process {pid} already stopped") except PermissionError: print(f"โš ๏ธ No permission to stop process {pid}") print("โœ… Process cleanup completed") except FileNotFoundError: print("โš ๏ธ netstat not available, trying alternative method...") # Alternative: try to kill common Python processes try: subprocess.run(['taskkill', '/f', '/im', 'python.exe'], capture_output=True, text=True) subprocess.run(['taskkill', '/f', '/im', 'py.exe'], capture_output=True, text=True) print("โœ… Alternative cleanup completed") except FileNotFoundError: print("โš ๏ธ taskkill not available") def start_enhanced_harness(): """Start the enhanced MCP harness.""" print("\n๐Ÿš€ Starting Enhanced MCP Harness...") print("=" * 40) try: # Start the enhanced harness subprocess.Popen([sys.executable, 'enhanced_mcp_harness.py']) print("โœ… Enhanced MCP Harness started on localhost:8000") # Wait a moment for server to start time.sleep(2) # Start the enhanced web interface print("\n๐ŸŒ Starting Enhanced Web Interface...") subprocess.Popen([sys.executable, 'enhanced_web_interface.py']) print("โœ… Enhanced Web Interface started on localhost:3003") print("\n๐ŸŽ‰ All servers started successfully!") print("\n๐Ÿ“‹ Available URLs:") print(" โ€ข Enhanced Web Interface: http://localhost:3003") print(" โ€ข MCP Server: localhost:8000") print("\n๐Ÿ’ก You can now:") print(" โ€ข Open http://localhost:3003 in your browser") print(" โ€ข Test with: py -3 test_client.py") print(" โ€ข Use any MCP client to connect to localhost:8000") except Exception as e: print(f"โŒ Error starting servers: {e}") def main(): """Main function to restart servers.""" print("๐Ÿ”„ MCP Server Restart Script") print("=" * 30) # Step 1: Stop existing processes print("\n1๏ธโƒฃ Stopping existing servers...") find_and_kill_processes() # Step 2: Wait a moment print("\n2๏ธโƒฃ Waiting for cleanup...") time.sleep(3) # Step 3: Start enhanced harness print("\n3๏ธโƒฃ Starting enhanced servers...") start_enhanced_harness() print("\nโœ… Restart completed!") print("๐Ÿ›‘ Press Ctrl+C in the server windows to stop them") if __name__ == "__main__": main()

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/BerdTan/mcpharness'

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