Skip to content

Commit 5e0953d

Browse files
authored
chore: add httpx.HTTPStatusException handling to tool runs
1 parent ee54acb commit 5e0953d

File tree

1 file changed

+7
-0
lines changed
  • src/mcp/server/fastmcp/tools

1 file changed

+7
-0
lines changed

src/mcp/server/fastmcp/tools/base.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations as _annotations
22

33
import functools
4+
import httpx
45
import inspect
56
from collections.abc import Callable
67
from functools import cached_property
@@ -106,6 +107,12 @@ async def run(
106107
result = self.fn_metadata.convert_result(result)
107108

108109
return result
110+
except httpx.HTTPStatusException as e:
111+
try:
112+
error_detail = e.response.json()
113+
except:
114+
error_detail = e.response.text
115+
raise ToolError(f"Error executing tool {self.name}: [{e.response.status_code}] {error_detail}")
109116
except Exception as e:
110117
raise ToolError(f"Error executing tool {self.name}: {e}") from e
111118

0 commit comments

Comments
 (0)