BluestoneApps MCP Remote Server

#!/usr/bin/env python3 """ MCP Bridge - A simple script that acts as a bridge between Windsurf and the remote MCP server. """ import sys import json import urllib.request import urllib.error import base64 import os # Remote server configuration REMOTE_URL = "http://107.191.37.244:5051/jsonrpc" USERNAME = "admin" PASSWORD = "n2hXUijptRwpe9v6wZ37yOgEx4P8w3ofDRO0ko4A" AUTH_HEADER = f"Basic {base64.b64encode(f'{USERNAME}:{PASSWORD}'.encode()).decode()}" # Create a log file LOG_FILE = "/tmp/mcp_bridge.log" with open(LOG_FILE, "a") as f: f.write(f"MCP Bridge started at {os.path.abspath(__file__)}\n") def log(message): """Log a message to the log file.""" with open(LOG_FILE, "a") as f: f.write(f"{message}\n") def forward_request(request_data): """Forward a request to the remote server.""" log(f"Forwarding request: {request_data.get('method')}") headers = { "Content-Type": "application/json", "Authorization": AUTH_HEADER } try: # Prepare the request data = json.dumps(request_data).encode('utf-8') req = urllib.request.Request(REMOTE_URL, data=data, headers=headers, method="POST") # Send the request with urllib.request.urlopen(req) as response: response_data = json.loads(response.read().decode('utf-8')) log(f"Received response: {response_data}") return response_data except Exception as e: log(f"Error: {e}") return { "jsonrpc": "2.0", "error": { "code": -32000, "message": f"Error: {e}" }, "id": request_data.get("id") } # Test the connection test_request = { "jsonrpc": "2.0", "method": "tools/list", "id": 0 } log("Testing connection to remote server...") test_response = forward_request(test_request) if "error" in test_response: log(f"Failed to connect to remote server: {test_response['error']}") sys.exit(1) else: log("Successfully connected to remote server") # Print the test response to stdout print(json.dumps(test_response))