fix: Handle RequestError in mcp tools

This commit is contained in:
Chris Coutinho
2025-10-17 04:17:41 +02:00
parent 0fd32ecd34
commit 2999d4b65e
2 changed files with 56 additions and 2 deletions
+8 -1
View File
@@ -1,6 +1,6 @@
import logging
from httpx import HTTPStatusError
from httpx import HTTPStatusError, RequestError
from mcp.server.fastmcp import Context, FastMCP
from mcp.shared.exceptions import McpError
from mcp.types import ErrorData
@@ -83,6 +83,13 @@ def configure_cookbook_tools(mcp: FastMCP):
recipe=recipe,
recipe_id=recipe.id or "unknown",
)
except RequestError as e:
raise McpError(
ErrorData(
code=-1,
message=f"Network error importing recipe from {url}: {str(e)}",
)
)
except HTTPStatusError as e:
if e.response.status_code == 400:
raise McpError(