Skip to content

Commit ad0599d

Browse files
add types
1 parent 34d0719 commit ad0599d

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

sentry_sdk/integrations/mcp.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,14 @@
5353

5454

5555
if TYPE_CHECKING:
56-
from typing import Any, Callable, ContextManager, Optional, Tuple, Union
56+
from typing import Any, Awaitable, Callable, ContextManager, Optional, Tuple, Union
5757

58+
from mcp.types import (
59+
CallToolResult,
60+
GetPromptResult,
61+
InputRequiredResult,
62+
ReadResourceResult,
63+
)
5864
from starlette.types import Receive, Scope, Send # type: ignore[import-not-found]
5965

6066
from sentry_sdk.traces import StreamedSpan
@@ -496,12 +502,12 @@ def _prepare_handler_data(
496502

497503

498504
async def _tool_handler_wrapper(
499-
func: "Callable[..., Any]",
505+
func: "Callable[..., Awaitable[Union[CallToolResult, InputRequiredResult]]]",
500506
original_args: "tuple[Any, ...]",
501507
original_kwargs: "Optional[dict[str, Any]]" = None,
502508
self: "Optional[Any]" = None,
503509
force_await: bool = True,
504-
):
510+
) -> "Union[CallToolResult, InputRequiredResult]":
505511
"""
506512
Wrapper for MCP tool handlers.
507513
Creates and manages the MCP span and attaches all attributes on the span.
@@ -614,12 +620,12 @@ async def _tool_handler_wrapper(
614620

615621

616622
async def _prompt_handler_wrapper(
617-
func: "Callable[..., Any]",
623+
func: "Callable[..., Awaitable[Union[GetPromptResult, InputRequiredResult]]]",
618624
original_args: "tuple[Any, ...]",
619625
original_kwargs: "Optional[dict[str, Any]]" = None,
620626
self: "Optional[Any]" = None,
621627
force_await: bool = True,
622-
):
628+
) -> "Union[GetPromptResult, InputRequiredResult]":
623629
"""
624630
Wrapper for MCP prompt handlers.
625631
Creates and manages the MCP span and attaches all attributes on the span.
@@ -730,12 +736,12 @@ async def _prompt_handler_wrapper(
730736

731737

732738
async def _resource_handler_wrapper(
733-
func: "Callable[..., Any]",
739+
func: "Callable[..., Awaitable[Union[ReadResourceResult, InputRequiredResult]]]",
734740
original_args: "tuple[Any, ...]",
735741
original_kwargs: "Optional[dict[str, Any]]" = None,
736742
self: "Optional[Any]" = None,
737743
force_await: bool = True,
738-
):
744+
) -> "Union[ReadResourceResult, InputRequiredResult]":
739745
"""
740746
Wrapper for MCP resource handlers.
741747
Creates and manages the MCP span and attaches all attributes on the span.

0 commit comments

Comments
 (0)