From 8c15368e3710b5b9c100b9ada0777a15afc04f79 Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Mon, 30 Nov 2026 08:05:29 +0000 Subject: [PATCH] ref(mcp): Remove unused _extract_tool_result_content helper The only caller was the low-level server handler patching that #7508 removed when dropping support for mcp < 2.0. The middleware-based _instrument_tool_call reads structuredContent/content from the result dict directly, so the helper has been unreachable since then. --- sentry_sdk/integrations/mcp.py | 39 ---------------------------------- 1 file changed, 39 deletions(-) diff --git a/sentry_sdk/integrations/mcp.py b/sentry_sdk/integrations/mcp.py index f847a73941..9e4cf87c0c 100644 --- a/sentry_sdk/integrations/mcp.py +++ b/sentry_sdk/integrations/mcp.py @@ -176,45 +176,6 @@ def _set_span_input_data( span.set_attribute(f"mcp.request.argument.{k}", safe_serialize(v)) -def _extract_tool_result_content(result: "Any") -> "Any": - """ - Extract meaningful content from MCP tool result. - - Tool handlers can return: - - CallToolResult (mcp v2+): Has .content list and optional .structured_content - - tuple (UnstructuredContent, StructuredContent): Return the structured content (dict) - - dict (StructuredContent): Return as-is - - list/Iterable (UnstructuredContent): Extract text from content blocks - """ - if result is None: - return None - - # Handle v2 CallToolResult-like objects (has .content list attribute) - if hasattr(result, "content") and isinstance( - getattr(result, "content", None), list - ): - # This is only present when a tool declares an output_schema - structured = getattr(result, "structured_content", None) - if structured is not None: - return structured - return _extract_text_from_content_blocks(result.content) - - # Handle CombinationContent: tuple of (UnstructuredContent, StructuredContent) - if isinstance(result, tuple) and len(result) == 2: - # Return the structured content (2nd element) - return result[1] - - # Handle StructuredContent: dict - if isinstance(result, dict): - return result - - # Handle UnstructuredContent: iterable of ContentBlock objects - if hasattr(result, "__iter__") and not isinstance(result, (str, bytes, dict)): - return _extract_text_from_content_blocks(result) - - return result - - def _extract_text_from_content_blocks(content_blocks: "Any") -> "Any": texts = [] try: