Skip to main content
Glama

MCP Learning Project

by BerdTan
web_interface.pyโ€ข5.97 kB
#!/usr/bin/env python3 """ Simple web interface for the MCP Testing Harness """ import asyncio import json import logging import sys from pathlib import Path from datetime import datetime # Add src to path sys.path.insert(0, str(Path(__file__).parent / "src")) from core.server import MCPServer, MCPServerInfo from core.testing import MCPServerTester # Set up logging logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) class MCPWebInterface: """Simple web interface for MCP server management.""" def __init__(self): self.server = MCPServer(host="localhost", port=8000, debug=True) self.tester = MCPServerTester() def generate_html(self): """Generate the HTML interface.""" return """ <!DOCTYPE html> <html> <head> <title>MCP Testing Harness</title> <style> body { font-family: Arial, sans-serif; margin: 20px; background: #f5f5f5; } .container { max-width: 1200px; margin: 0 auto; background: white; padding: 20px; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); } h1 { color: #333; text-align: center; } .status { padding: 10px; margin: 10px 0; border-radius: 4px; } .status.running { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; } .status.stopped { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; } .card { background: #f8f9fa; border: 1px solid #dee2e6; border-radius: 4px; padding: 15px; margin: 10px 0; } .tool { background: #e9ecef; padding: 8px; margin: 5px 0; border-radius: 4px; } button { background: #007bff; color: white; border: none; padding: 8px 16px; border-radius: 4px; cursor: pointer; margin: 5px; } button:hover { background: #0056b3; } .grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; } pre { background: #f8f9fa; padding: 10px; border-radius: 4px; overflow-x: auto; } </style> </head> <body> <div class="container"> <h1>๐Ÿš€ MCP Testing Harness</h1> <div class="status running"> โœ… MCP Server is running on localhost:8000 </div> <div class="grid"> <div class="card"> <h3>๐Ÿ”ง Built-in Tools</h3> <div class="tool"> <strong>list_servers</strong> - List all hosted MCP servers </div> <div class="tool"> <strong>register_server</strong> - Register a new MCP server </div> <div class="tool"> <strong>test_server</strong> - Test an MCP server connection </div> </div> <div class="card"> <h3>๐Ÿ“Š Server Status</h3> <p><strong>Host:</strong> localhost</p> <p><strong>Port:</strong> 8000</p> <p><strong>Status:</strong> Running</p> <p><strong>Protocol:</strong> JSON-RPC 2.0</p> </div> </div> <div class="card"> <h3>๐Ÿงช How to Test</h3> <p>Your MCP server is ready for testing! You can:</p> <ul> <li>Connect with any MCP client to <code>localhost:8000</code></li> <li>Use Claude Desktop and add this server</li> <li>Test with our Python client: <code>py -3 test_client.py</code></li> <li>Use any MCP-compatible AI client</li> </ul> </div> <div class="card"> <h3>๐Ÿ“ Example MCP Client Request</h3> <pre>{ "jsonrpc": "2.0", "id": 1, "method": "initialize", "params": { "protocolVersion": "2024-11-05", "capabilities": {}, "clientInfo": { "name": "Test Client", "version": "1.0.0" } } }</pre> </div> <div class="card"> <h3>๐ŸŽฏ Next Steps</h3> <p>Your MCP Testing Harness is fully functional! Next steps:</p> <ol> <li>Test with an MCP client</li> <li>Register other MCP servers for testing</li> <li>Add custom tools and modules</li> <li>Continue with Phase 2 (advanced features)</li> </ol> </div> </div> </body> </html> """ async def start_web_server(self): """Start a simple web server to show the interface.""" import http.server import socketserver class MCPHandler(http.server.SimpleHTTPRequestHandler): def do_GET(self): if self.path == '/': self.send_response(200) self.send_header('Content-type', 'text/html') self.end_headers() self.wfile.write(self.server.mcp_interface.generate_html().encode()) else: super().do_GET() # Create server handler = MCPHandler handler.server = type('Server', (), {'mcp_interface': self})() with socketserver.TCPServer(("", 3000), handler) as httpd: print("๐ŸŒ Web interface available at: http://localhost:3000") print("๐Ÿ“ก MCP server running at: localhost:8000") print("๐Ÿ›‘ Press Ctrl+C to stop") httpd.serve_forever() async def main(): """Start the web interface.""" print("๐Ÿš€ Starting MCP Testing Harness Web Interface") print("=" * 50) try: interface = MCPWebInterface() await interface.start_web_server() except KeyboardInterrupt: print("\n๐Ÿ›‘ Web interface stopped") except Exception as e: print(f"โŒ Error: {e}") if __name__ == "__main__": asyncio.run(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