Skip to content

Commit 7c161d6

Browse files
committed
bound methods
1 parent 1f87450 commit 7c161d6

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

sentry_sdk/integrations/mcp.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,8 @@ def _prepare_handler_data(
316316
elif handler_type == "prompt":
317317
if original_args:
318318
handler_name = original_args[0]
319-
elif original_kwargs.get("tool_name"):
320-
handler_name = original_kwargs["tool_name"]
319+
elif original_kwargs.get("name"):
320+
handler_name = original_kwargs["name"]
321321

322322
arguments = {}
323323
if len(original_args) > 1:
@@ -357,6 +357,7 @@ async def _async_handler_wrapper(
357357
func: "Callable[..., Any]",
358358
original_args: "tuple[Any, ...]",
359359
original_kwargs: "Optional[dict[str, Any]]" = None,
360+
self: "Optional[Any]" = None,
360361
) -> "Any":
361362
"""
362363
Async wrapper for MCP handlers.
@@ -365,6 +366,8 @@ async def _async_handler_wrapper(
365366
handler_type: "tool", "prompt", or "resource"
366367
func: The async handler function to wrap
367368
original_args: Original arguments passed to the handler
369+
original_kwargs: Original keyword arguments passed to the handler
370+
self: Optional instance for bound methods
368371
"""
369372
if original_kwargs is None:
370373
original_kwargs = {}
@@ -416,6 +419,8 @@ async def _async_handler_wrapper(
416419

417420
try:
418421
# Execute the async handler
422+
if self is not None:
423+
original_args = (self, *original_args)
419424
result = await func(*original_args, **original_kwargs)
420425
except Exception as e:
421426
# Set error flag for tools
@@ -627,12 +632,13 @@ def _patch_fastmcp():
627632
original_get_prompt_mcp = FastMCP._get_prompt_mcp
628633

629634
@wraps(original_get_prompt_mcp)
630-
async def patched_get_prompt_mcp(*args: "Any", **kwargs: "Any") -> "Any":
635+
async def patched_get_prompt_mcp(self, *args: "Any", **kwargs: "Any") -> "Any":
631636
return await _async_handler_wrapper(
632637
"prompt",
633638
original_get_prompt_mcp,
634639
args,
635640
kwargs,
641+
self,
636642
)
637643

638644
FastMCP._get_prompt_mcp = patched_get_prompt_mcp
@@ -641,12 +647,15 @@ async def patched_get_prompt_mcp(*args: "Any", **kwargs: "Any") -> "Any":
641647
original_read_resource_mcp = FastMCP._read_resource_mcp
642648

643649
@wraps(original_read_resource_mcp)
644-
async def patched_read_resource_mcp(*args: "Any", **kwargs: "Any") -> "Any":
650+
async def patched_read_resource_mcp(
651+
self, *args: "Any", **kwargs: "Any"
652+
) -> "Any":
645653
return await _async_handler_wrapper(
646654
"resource",
647655
original_read_resource_mcp,
648656
args,
649657
kwargs,
658+
self,
650659
)
651660

652661
FastMCP._read_resource_mcp = patched_read_resource_mcp

0 commit comments

Comments
 (0)