From e5efc180a369dfea3903438c63cabecc4c31131f Mon Sep 17 00:00:00 2001 From: Alexander Alderman Webb Date: Mon, 19 Jan 2026 14:18:16 +0100 Subject: [PATCH 1/2] test(fastmcp): Stop accessing non-existent attribute --- tests/integrations/fastmcp/test_fastmcp.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integrations/fastmcp/test_fastmcp.py b/tests/integrations/fastmcp/test_fastmcp.py index ef2a1f9cb7..aaef096b33 100644 --- a/tests/integrations/fastmcp/test_fastmcp.py +++ b/tests/integrations/fastmcp/test_fastmcp.py @@ -606,9 +606,9 @@ def code_help_prompt(language: str): # Check PII-sensitive data if send_default_pii and include_prompts: - assert SPANDATA.MCP_PROMPT_CONTENT in span["data"] + assert SPANDATA.MCP_PROMPT_RESULT_MESSAGE_CONTENT in span["data"] else: - assert SPANDATA.MCP_PROMPT_CONTENT not in span["data"] + assert SPANDATA.MCP_PROMPT_RESULT_MESSAGE_CONTENT not in span["data"] except AttributeError: # Prompt handler not supported in this version pytest.skip("Prompt handlers not supported in this FastMCP version") From 878ac1cbbe56890d0328004728d5152e62d33c32 Mon Sep 17 00:00:00 2001 From: Alexander Alderman Webb Date: Mon, 19 Jan 2026 14:23:41 +0100 Subject: [PATCH 2/2] test(fastmcp): Narrow AttributeError try-except --- tests/integrations/fastmcp/test_fastmcp.py | 128 ++++++++++----------- 1 file changed, 64 insertions(+), 64 deletions(-) diff --git a/tests/integrations/fastmcp/test_fastmcp.py b/tests/integrations/fastmcp/test_fastmcp.py index aaef096b33..17f49b8b40 100644 --- a/tests/integrations/fastmcp/test_fastmcp.py +++ b/tests/integrations/fastmcp/test_fastmcp.py @@ -569,49 +569,49 @@ def test_fastmcp_prompt_sync( request_ctx.set(mock_ctx) # Try to register a prompt handler (may not be supported in all versions) - try: - if hasattr(mcp, "prompt"): - - @mcp.prompt() - def code_help_prompt(language: str): - """Get help for a programming language""" - return [ - { - "role": "user", - "content": { - "type": "text", - "text": f"Tell me about {language}", - }, - } - ] + if hasattr(mcp, "prompt"): + + @mcp.prompt() + def code_help_prompt(language: str): + """Get help for a programming language""" + return [ + { + "role": "user", + "content": { + "type": "text", + "text": f"Tell me about {language}", + }, + } + ] - with start_transaction(name="fastmcp tx"): + with start_transaction(name="fastmcp tx"): + try: result = call_prompt_through_mcp( mcp, "code_help_prompt", {"language": "python"} ) - - assert result.messages[0].role == "user" - assert "python" in result.messages[0].content.text.lower() - - (tx,) = events - assert tx["type"] == "transaction" - - # Verify prompt span was created - prompt_spans = [s for s in tx["spans"] if s["op"] == OP.MCP_SERVER] - assert len(prompt_spans) == 1 - span = prompt_spans[0] - assert span["origin"] == "auto.ai.mcp" - assert span["description"] == "prompts/get code_help_prompt" - assert span["data"][SPANDATA.MCP_PROMPT_NAME] == "code_help_prompt" - - # Check PII-sensitive data - if send_default_pii and include_prompts: - assert SPANDATA.MCP_PROMPT_RESULT_MESSAGE_CONTENT in span["data"] - else: - assert SPANDATA.MCP_PROMPT_RESULT_MESSAGE_CONTENT not in span["data"] - except AttributeError: - # Prompt handler not supported in this version - pytest.skip("Prompt handlers not supported in this FastMCP version") + except AttributeError: + # Prompt handler not supported in this version + pytest.skip("Prompt handlers not supported in this FastMCP version") + + assert result.messages[0].role == "user" + assert "python" in result.messages[0].content.text.lower() + + (tx,) = events + assert tx["type"] == "transaction" + + # Verify prompt span was created + prompt_spans = [s for s in tx["spans"] if s["op"] == OP.MCP_SERVER] + assert len(prompt_spans) == 1 + span = prompt_spans[0] + assert span["origin"] == "auto.ai.mcp" + assert span["description"] == "prompts/get code_help_prompt" + assert span["data"][SPANDATA.MCP_PROMPT_NAME] == "code_help_prompt" + + # Check PII-sensitive data + if send_default_pii and include_prompts: + assert SPANDATA.MCP_PROMPT_RESULT_MESSAGE_CONTENT in span["data"] + else: + assert SPANDATA.MCP_PROMPT_RESULT_MESSAGE_CONTENT not in span["data"] @pytest.mark.parametrize("FastMCP", fastmcp_implementations, ids=fastmcp_ids) @@ -634,38 +634,38 @@ async def test_fastmcp_prompt_async(sentry_init, capture_events, FastMCP): request_ctx.set(mock_ctx) # Try to register an async prompt handler - try: - if hasattr(mcp, "prompt"): - - @mcp.prompt() - async def async_prompt(topic: str): - """Get async prompt for a topic""" - return [ - { - "role": "user", - "content": {"type": "text", "text": f"What is {topic}?"}, - }, - { - "role": "assistant", - "content": { - "type": "text", - "text": "Let me explain that", - }, + if hasattr(mcp, "prompt"): + + @mcp.prompt() + async def async_prompt(topic: str): + """Get async prompt for a topic""" + return [ + { + "role": "user", + "content": {"type": "text", "text": f"What is {topic}?"}, + }, + { + "role": "assistant", + "content": { + "type": "text", + "text": "Let me explain that", }, - ] + }, + ] - with start_transaction(name="fastmcp tx"): + with start_transaction(name="fastmcp tx"): + try: result = await call_prompt_through_mcp_async( mcp, "async_prompt", {"topic": "MCP"} ) + except AttributeError: + # Prompt handler not supported in this version + pytest.skip("Prompt handlers not supported in this FastMCP version") - assert len(result.messages) == 2 + assert len(result.messages) == 2 - (tx,) = events - assert tx["type"] == "transaction" - except AttributeError: - # Prompt handler not supported in this version - pytest.skip("Prompt handlers not supported in this FastMCP version") + (tx,) = events + assert tx["type"] == "transaction" # =============================================================================