Skip to content

Commit 07564c8

Browse files
mangodxdclaude
andcommitted
perf: Avoid scanning installed packages when MCP SDK is not installed (#6769)
When mcp SDK is not installed, module-level package_version('mcp') at the top of sentry_sdk/integrations/mcp.py scans every installed distribution, slowing sentry_sdk.init() by ~200ms in environments with hundreds of packages. Move the call below the ry/except ImportError guard so it only runs when import mcp succeeds. Environments without mcp skip the scan entirely. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 9996734 commit 07564c8

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

sentry_sdk/integrations/mcp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020
from sentry_sdk.tracing_utils import has_span_streaming_enabled
2121
from sentry_sdk.utils import nullcontext, package_version, safe_serialize
2222

23-
MCP_PACKAGE_VERSION = package_version("mcp")
24-
2523
try:
2624
from mcp.server.lowlevel import Server
2725
from mcp.server.streamable_http import (
2826
StreamableHTTPServerTransport,
2927
)
3028

29+
MCP_PACKAGE_VERSION = package_version("mcp")
30+
3131
if MCP_PACKAGE_VERSION and MCP_PACKAGE_VERSION < (2, 0, 0):
3232
from mcp.server.lowlevel.server import ( # type: ignore[attr-defined]
3333
request_ctx,

0 commit comments

Comments
 (0)