"""SLYD's stdio bridge for clients that cannot use remote HTTP MCP directly.""" import http.client import json import sys HOST = "rent.slyd.ai" LIMIT = 2 * 1024 * 1024 def forward(message, version): data = json.dumps(message, separators=(",", ":")).encode() headers = {"Content-Type": "application/json", "Accept": "application/json, text/event-stream", "User-Agent": "SLYD-MCP-stdio/1.0", "MCP-Protocol-Version": version} connection = http.client.HTTPSConnection(HOST, timeout=135) try: connection.request("POST", "/mcp", data, headers) reply = connection.getresponse() body = reply.read(LIMIT + 1) if reply.status == 202 and "id" not in message: return None if reply.status != 200 or len(body) > LIMIT: raise ValueError("MCP transport failed (HTTP %d)" % reply.status) result = json.loads(body) if result.get("jsonrpc") != "2.0" or result.get("id") != message.get("id"): raise ValueError("Invalid MCP reply") return result finally: connection.close() def main(): version = "2025-03-26" while line := sys.stdin.buffer.readline(LIMIT + 1): if len(line) > LIMIT: return 1 message = {} try: message = json.loads(line) if not isinstance(message, dict): raise ValueError("Expected a JSON-RPC message") result = forward(message, version) if message.get("method") == "initialize" and result and "result" in result: version = result["result"]["protocolVersion"] except (ValueError, OSError, http.client.HTTPException, KeyError): if not isinstance(message, dict) or "id" not in message: continue result = {"jsonrpc":"2.0", "id":message["id"], "error":{ "code":-32000, "message":"SLYD MCP request failed. Reconcile pending rental orders before retrying."}} if result is not None: print(json.dumps(result, separators=(",", ":")), flush=True) return 0 if __name__ == "__main__": sys.exit(main())