Connection to MCP server failed: Connection closed
logs запуска облака:
[ERROR] WebSocket handshake failed
[ERROR] MCP server connection timeout after 60 seconds
среда:
- local: python 3.11, Windows (Working)
- Cloud Run: python 3.11, Containing Environmenting (Failing) pship) run: python 3.11, containing contairing constroning) />
- библиотеки: Streamlit, Asyncio, WebSockets (укажите точные версии)
- mcp-серверы: @openbnb/mcp-server-airbnb, mcp: @openbnb/mcp-server-airbnb, @openbnb/mcp-server- @gongrzhe/server-travelplanner-mcp
URL: https://travel-planner-809145899609.us-central1.run.app
Ingress: all
Traffic:
100% LATEST (currently travel-planner-00009-zvv)
Scaling: Auto (Min: 0)
Last updated on 2025-09-12T13:28:38.830709Z by xyz@123gmail.com:
Revision travel-planner-00009-zvv
Container None
Image: gcr.io/ai-agent-travel-planner/travel-planner
Port: 8080
Memory: 2Gi
CPU: 1000m
Secrets:
GEMINI_API_KEY GEMINI_API_KEY:latest
GOOGLE_MAPS_API_KEY GOOGLE_MAPS_API_KEY:latest
Startup Probe:
TCP every 240s
Port: 8080
Initial delay: 0s
Timeout: 240s
Failure threshold: 1
Type: Default
Service account: 809145899609-compute@developer.gserviceaccount.com
Concurrency: 80
Max instances: 20
Timeout: 300s
Пример
import os
import asyncio
import MultiMCPTools
async def run_mcp_travel_planner(destination: str, num_days: int,
preferences: str, budget: int,
openai_key: str, google_maps_key: str):
try:
# Set Google Maps API key environment variable
os.environ["GOOGLE_MAPS_API_KEY"] = google_maps_key
# Initialize MCPTools with Airbnb MCP
mcp_tools = MultiMCPTools(
[
"npx -y @openbnb/mcp-server-airbnb --ignore-robots-txt",
"npx @gongrzhe/server-travelplanner-mcp",
],
env={
"GOOGLE_MAPS_API_KEY": google_maps_key,
},
timeout_seconds=60,
)
# This works locally but fails in Cloud Run
await mcp_tools.connect() # WebSocket connection closes here
except Exception as e:
print(f"MCP connection failed: {e}")
raise
# Test function
async def main():
await run_mcp_travel_planner("Paris", 3, "museums", 1000, "key", "maps_key")
if __name__ == "__main__":
asyncio.run(main())
Подробнее здесь: https://stackoverflow.com/questions/797 ... -cloud-run