File tree Expand file tree Collapse file tree 5 files changed +712
-0
lines changed
Expand file tree Collapse file tree 5 files changed +712
-0
lines changed Original file line number Diff line number Diff line change @@ -749,6 +749,36 @@ class SPANDATA:
749749 Example: "MainThread"
750750 """
751751
752+ MCP_TOOL_NAME = "mcp.tool.name"
753+ """
754+ The name of the MCP tool being called.
755+ Example: "get_weather"
756+ """
757+
758+ MCP_PROMPT_NAME = "mcp.prompt.name"
759+ """
760+ The name of the MCP prompt being retrieved.
761+ Example: "code_review"
762+ """
763+
764+ MCP_RESOURCE_URI = "mcp.resource.uri"
765+ """
766+ The URI of the MCP resource being accessed.
767+ Example: "file:///path/to/resource"
768+ """
769+
770+ MCP_METHOD_NAME = "mcp.method.name"
771+ """
772+ The MCP protocol method name being called.
773+ Example: "tools/call", "prompts/get", "resources/read"
774+ """
775+
776+ MCP_REQUEST_ID = "mcp.request.id"
777+ """
778+ The unique identifier for the MCP request.
779+ Example: "req_123abc"
780+ """
781+
752782
753783class SPANSTATUS :
754784 """
@@ -845,6 +875,9 @@ class OP:
845875 WEBSOCKET_SERVER = "websocket.server"
846876 SOCKET_CONNECTION = "socket.connection"
847877 SOCKET_DNS = "socket.dns"
878+ MCP_TOOL = "mcp.tool"
879+ MCP_PROMPT = "mcp.prompt"
880+ MCP_RESOURCE = "mcp.resource"
848881
849882
850883# This type exists to trick mypy and PyCharm into thinking `init` and `Client`
Original file line number Diff line number Diff line change @@ -98,6 +98,7 @@ def iter_default_integrations(with_auto_enabling_integrations):
9898 "sentry_sdk.integrations.langgraph.LanggraphIntegration" ,
9999 "sentry_sdk.integrations.litestar.LitestarIntegration" ,
100100 "sentry_sdk.integrations.loguru.LoguruIntegration" ,
101+ "sentry_sdk.integrations.mcp.MCPIntegration" ,
101102 "sentry_sdk.integrations.openai.OpenAIIntegration" ,
102103 "sentry_sdk.integrations.pymongo.PyMongoIntegration" ,
103104 "sentry_sdk.integrations.pyramid.PyramidIntegration" ,
Original file line number Diff line number Diff line change 1+ """
2+ Sentry integration for MCP (Model Context Protocol) servers.
3+
4+ This integration instruments MCP servers to create spans for tool, prompt,
5+ and resource handler execution, and captures errors that occur during execution.
6+
7+ Supports both the low-level `mcp.server.lowlevel.Server` and high-level
8+ `mcp.server.fastmcp.FastMCP` APIs.
9+ """
10+
11+ from sentry_sdk .integrations import Integration , DidNotEnable
12+
13+ try :
14+ import mcp .server .lowlevel # noqa: F401
15+ import mcp .server .fastmcp # noqa: F401
16+ except ImportError :
17+ raise DidNotEnable ("MCP SDK not installed" )
18+
19+
20+ class MCPIntegration (Integration ):
21+ identifier = "mcp"
22+ origin = "auto.ai.mcp"
23+
24+ @staticmethod
25+ def setup_once ():
26+ # type: () -> None
27+ """
28+ Patches MCP server classes to instrument handler execution.
29+ """
30+ from sentry_sdk .integrations .mcp .lowlevel import patch_lowlevel_server
31+ from sentry_sdk .integrations .mcp .fastmcp import patch_fastmcp_server
32+
33+ patch_lowlevel_server ()
34+ patch_fastmcp_server ()
35+
36+
37+ __all__ = ["MCPIntegration" ]
You can’t perform that action at this time.
0 commit comments