make mcp "prodution ready"
All checks were successful
Build and Push Agent Docker Image / build (push) Successful in 2m11s
All checks were successful
Build and Push Agent Docker Image / build (push) Successful in 2m11s
This commit is contained in:
@@ -17,36 +17,35 @@ logging.basicConfig(
|
||||
)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
MCP_URL = "https://mcp.caving.dev/mcp"
|
||||
CAVE_MCP_URL = os.getenv("CAVE_MCP_URL", "https://mcp.caving.dev/mcp")
|
||||
|
||||
logger.info("Initializing Cavepedia agent...")
|
||||
|
||||
def check_mcp_available(url: str, timeout: float = 5.0) -> bool:
|
||||
"""Check if MCP server is reachable."""
|
||||
"""Check if MCP server is reachable via health endpoint."""
|
||||
try:
|
||||
# Just check if we can connect - don't need a full MCP handshake
|
||||
response = httpx.get(url, timeout=timeout, follow_redirects=True)
|
||||
# Any response (even 4xx/5xx) means server is reachable
|
||||
# 502 means upstream is down, so treat as unavailable
|
||||
if response.status_code == 502:
|
||||
logger.warning(f"MCP server returned 502 Bad Gateway")
|
||||
return False
|
||||
return True
|
||||
# Use the health endpoint instead of the MCP endpoint
|
||||
health_url = url.rsplit("/", 1)[0] + "/health"
|
||||
response = httpx.get(health_url, timeout=timeout, follow_redirects=True)
|
||||
if response.status_code == 200:
|
||||
return True
|
||||
logger.warning(f"MCP health check returned {response.status_code}")
|
||||
return False
|
||||
except Exception as e:
|
||||
logger.warning(f"MCP server not reachable: {e}")
|
||||
return False
|
||||
|
||||
# Try to configure MCP if server is available
|
||||
toolsets = []
|
||||
if check_mcp_available(MCP_URL):
|
||||
if check_mcp_available(CAVE_MCP_URL):
|
||||
try:
|
||||
from pydantic_ai.mcp import MCPServerStreamableHTTP
|
||||
mcp_server = MCPServerStreamableHTTP(
|
||||
url=MCP_URL,
|
||||
url=CAVE_MCP_URL,
|
||||
timeout=30.0,
|
||||
)
|
||||
toolsets.append(mcp_server)
|
||||
logger.info(f"MCP server configured: {MCP_URL}")
|
||||
logger.info(f"MCP server configured: {CAVE_MCP_URL}")
|
||||
except Exception as e:
|
||||
logger.warning(f"Could not configure MCP server: {e}")
|
||||
else:
|
||||
@@ -54,7 +53,7 @@ else:
|
||||
|
||||
# Create the agent with Google Gemini model
|
||||
agent = Agent(
|
||||
model=GoogleModel("gemini-2.5-pro"),
|
||||
model=GoogleModel("gemini-3-pro-preview"),
|
||||
toolsets=toolsets if toolsets else None,
|
||||
instructions="""You are a helpful caving assistant. Help users with all aspects of caving including cave exploration, safety, surveying techniques, cave locations, geology, equipment, history, conservation, and any other caving-related topics.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user