mcp_http_wrapper.py•2.12 kB
#!/usr/bin/env python3
"""
MCP HTTP Wrapper for Claude Desktop
Wraps our HTTP MCP server to work with Claude Desktop's stdio interface
"""
import sys
import json
import requests
import asyncio
MCP_SERVER_URL = "http://44.206.235.28:8000/mcp"
async def main():
"""Main stdio loop for MCP communication"""
while True:
try:
# Read from stdin
line = sys.stdin.readline()
if not line:
break
line = line.strip()
if not line:
continue
# Parse JSON-RPC request
request = json.loads(line)
# Forward to HTTP MCP server
response = requests.post(
MCP_SERVER_URL,
json=request,
headers={"Content-Type": "application/json"},
timeout=30
)
if response.status_code == 200:
result = response.json()
else:
result = {
"jsonrpc": "2.0",
"id": request.get("id", 0),
"error": {
"code": -32000,
"message": f"HTTP error: {response.status_code}"
}
}
# Send response to stdout
print(json.dumps(result))
sys.stdout.flush()
except json.JSONDecodeError:
error_response = {
"jsonrpc": "2.0",
"id": 0,
"error": {
"code": -32700,
"message": "Parse error"
}
}
print(json.dumps(error_response))
sys.stdout.flush()
except Exception as e:
error_response = {
"jsonrpc": "2.0",
"id": 0,
"error": {
"code": -32000,
"message": f"Wrapper error: {str(e)}"
}
}
print(json.dumps(error_response))
sys.stdout.flush()
if __name__ == "__main__":
asyncio.run(main())