|
|
@ -21,14 +21,16 @@ logger.add(sys.stdout,
|
|
|
|
def get_server_params():
|
|
|
|
def get_server_params():
|
|
|
|
"""Get the MCP server connection parameters."""
|
|
|
|
"""Get the MCP server connection parameters."""
|
|
|
|
return MCPServerSseParams(
|
|
|
|
return MCPServerSseParams(
|
|
|
|
url=
|
|
|
|
url="http://0.0.0.0:8000", # Using 0.0.0.0 to be accessible
|
|
|
|
"http://127.0.0.1:8000", # Use 127.0.0.1 instead of localhost/0.0.0.0
|
|
|
|
sse_path="/sse", # Specify SSE endpoint
|
|
|
|
|
|
|
|
messages_path="/messages", # Specify messages endpoint
|
|
|
|
headers={
|
|
|
|
headers={
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
"Accept": "text/event-stream"
|
|
|
|
"Accept": "text/event-stream"
|
|
|
|
},
|
|
|
|
},
|
|
|
|
timeout=15.0, # Longer timeout
|
|
|
|
timeout=15.0, # Longer timeout
|
|
|
|
sse_read_timeout=60.0 # Longer read timeout
|
|
|
|
sse_read_timeout=60.0, # Longer read timeout
|
|
|
|
|
|
|
|
require_session_id=False # Match server configuration
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -79,16 +81,21 @@ async def get_tools_list():
|
|
|
|
def test_server_connection():
|
|
|
|
def test_server_connection():
|
|
|
|
"""Test if the server is reachable and responsive."""
|
|
|
|
"""Test if the server is reachable and responsive."""
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
# Create a short-lived connection to check server
|
|
|
|
params = get_server_params()
|
|
|
|
server = MCPServerSse(get_server_params())
|
|
|
|
health_url = f"{params.url}{params.sse_path}"
|
|
|
|
|
|
|
|
response = httpx.get(
|
|
|
|
# Try connecting (this is synchronous)
|
|
|
|
health_url,
|
|
|
|
asyncio.run(server.connect())
|
|
|
|
headers={"Accept": "text/event-stream"},
|
|
|
|
asyncio.run(server.cleanup())
|
|
|
|
timeout=5.0
|
|
|
|
logger.info("✅ Server connection test successful")
|
|
|
|
)
|
|
|
|
return True
|
|
|
|
if response.status_code == 200:
|
|
|
|
|
|
|
|
logger.info("✅ SSE endpoint is up")
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
logger.error(f"❌ Unexpected status {response.status_code}")
|
|
|
|
|
|
|
|
return False
|
|
|
|
except Exception as e:
|
|
|
|
except Exception as e:
|
|
|
|
logger.error(f"❌ Server connection test failed: {e}")
|
|
|
|
logger.error(f"❌ Connection to SSE endpoint failed: {e}")
|
|
|
|
return False
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|