BluestoneApps MCP Remote Server

#!/usr/bin/env python3 """ Local MCP Server that proxies requests to the remote server """ import sys import json import urllib.request import urllib.error import base64 import traceback from fastmcp import FastMCP # 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()}" # Initialize the FastMCP server mcp = FastMCP("bluestoneapps") def forward_to_remote(method, params=None): """Forward a request to the remote server.""" print(f"Forwarding {method} to remote server", file=sys.stderr) request_data = { "jsonrpc": "2.0", "method": method, "id": 1 } if params: request_data["params"] = params 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_text = response.read().decode('utf-8') print(f"Received response: {response_text[:100]}...", file=sys.stderr) response_data = json.loads(response_text) if "result" in response_data: return response_data["result"] else: print(f"Error in response: {response_data}", file=sys.stderr) return f"Error: {response_data.get('error', {}).get('message', 'Unknown error')}" except Exception as e: print(f"Error forwarding request: {e}", file=sys.stderr) print(traceback.format_exc(), file=sys.stderr) return f"Error: {str(e)}" # Define tools that proxy to the remote server @mcp.tool(name="get_project_structure") def get_project_structure() -> str: """Get project structure standards for React Native development """ print("Tool called: get_project_structure", file=sys.stderr) return forward_to_remote("tools/call", {"name": "get_project_structure"}) @mcp.tool(name="get_api_communication") def get_api_communication() -> str: """Get API communication standards for React Native development """ print("Tool called: get_api_communication", file=sys.stderr) return forward_to_remote("tools/call", {"name": "get_api_communication"}) @mcp.tool(name="get_component_design") def get_component_design() -> str: """Get component design standards for React Native development """ print("Tool called: get_component_design", file=sys.stderr) return forward_to_remote("tools/call", {"name": "get_component_design"}) @mcp.tool(name="get_state_management") def get_state_management() -> str: """Get state management standards for React Native development """ print("Tool called: get_state_management", file=sys.stderr) return forward_to_remote("tools/call", {"name": "get_state_management"}) @mcp.tool(name="get_component_example") def get_component_example(component_name: str) -> str: """Get a React Native component example Args: component_name: Name of the component (e.g., 'Button') """ print(f"Tool called: get_component_example({component_name})", file=sys.stderr) return forward_to_remote("tools/call", {"name": "get_component_example", "args": {"component_name": component_name}}) @mcp.tool(name="get_hook_example") def get_hook_example(hook_name: str) -> str: """Get a React Native hook example Args: hook_name: Name of the hook (e.g., 'useForm') """ print(f"Tool called: get_hook_example({hook_name})", file=sys.stderr) return forward_to_remote("tools/call", {"name": "get_hook_example", "args": {"hook_name": hook_name}}) @mcp.tool(name="get_service_example") def get_service_example(service_name: str) -> str: """Get a React Native service example Args: service_name: Name of the service (e.g., 'apiService') """ print(f"Tool called: get_service_example({service_name})", file=sys.stderr) return forward_to_remote("tools/call", {"name": "get_service_example", "args": {"service_name": service_name}}) @mcp.tool(name="get_screen_example") def get_screen_example(screen_name: str) -> str: """Get a React Native screen example Args: screen_name: Name of the screen (e.g., 'LoginScreen') """ print(f"Tool called: get_screen_example({screen_name})", file=sys.stderr) return forward_to_remote("tools/call", {"name": "get_screen_example", "args": {"screen_name": screen_name}}) @mcp.tool(name="get_theme_example") def get_theme_example(theme_name: str) -> str: """Get a React Native theme example Args: theme_name: Name of the theme file (e.g., 'colors') """ print(f"Tool called: get_theme_example({theme_name})", file=sys.stderr) return forward_to_remote("tools/call", {"name": "get_theme_example", "args": {"theme_name": theme_name}}) @mcp.tool(name="list_available_examples") def list_available_examples() -> str: """List all available code examples by category """ print("Tool called: list_available_examples", file=sys.stderr) return forward_to_remote("tools/call", {"name": "list_available_examples"}) if __name__ == "__main__": print("Starting Local Proxy MCP Server", file=sys.stderr) mcp.run(transport="stdio")