Uname : Linux premium36.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64
Soft : LiteSpeed
Ip : 198.54.115.237
Port : 443
~
/
opt
/
hc_python
/
lib64
/
python3.12
/
site-packages
/
sentry_sdk
/
integrations
/
__pycache__
[ HOME ]
Exec
Submit
mcp.cpython-312.pyc
� w�/iTN � � � d Z ddlZddlmZ ddlmZ ddlZddlmZ ddl m Z mZ ddlm Z mZ ddlmZ dd lmZ dd lmZ ddlmZ er dd lmZmZmZ G d� de � Zd� Zd� Zd� Zd� Zd� Z d� Z!d� Z"d� Z#d� Z$d� Z%d� Z&y# e$ r ed� �w xY w)a Sentry integration for MCP (Model Context Protocol) servers. This integration instruments MCP servers to create spans for tool, prompt, and resource handler execution, and captures errors that occur during execution. Supports the low-level `mcp.server.lowlevel.Server` API. � N)�wraps)� TYPE_CHECKING)�get_start_span_function)�OP�SPANDATA)�Integration�DidNotEnable)�safe_serialize)�should_send_default_pii)�Server)�request_ctxzMCP SDK not installed)�Any�Callable�Optionalc �, � e Zd ZdZdZdd�Zed� � Zy)�MCPIntegration�mcpzauto.ai.mcpc � � || _ y)z� Initialize the MCP integration. Args: include_prompts: Whether to include prompts (tool results and prompt content) in span data. Requires send_default_pii=True. Default is True. N)�include_prompts)�selfr s �J/opt/hc_python/lib/python3.12/site-packages/sentry_sdk/integrations/mcp.py�__init__zMCPIntegration.__init__$ s � � /��� c � � t � y)zM Patches MCP server classes to instrument handler execution. N)�_patch_lowlevel_server� r r � setup_oncezMCPIntegration.setup_once/ s � � � r N)T)�__name__� __module__�__qualname__� identifier�originr �staticmethodr r r r r r s% � ��J� �F� /� �!� �!r r c �� � d} d}d} t j � }|��|j } t |d� r�|j ��|j }t |d� r9|j j d� rd}|j j d� }nDt |d� r8|j j d� rd }|j j d� }| ||fS # t $ r Y �w xY w) a8 Extract request ID, session ID, and MCP transport type from the request context. Returns: Tuple of (request_id, session_id, mcp_transport). - request_id: May be None if not available - session_id: May be None if not available - mcp_transport: "http", "sse", "stdio" N�stdio�request�query_params� session_id�sse�headerszmcp-session-id�http)r �get� request_id�hasattrr&