From e87784bc10ca568c5762734bc6084eb2907c6064 Mon Sep 17 00:00:00 2001 From: Fabian Schindler Date: Wed, 5 Nov 2025 10:41:22 +0100 Subject: [PATCH 1/2] fix(insights-mcp): improve docs to clarify situation with libraries with MCP SDK and FastAPI --- .../insights/ai/mcp/getting-started.mdx | 102 +++++++++++++++++- 1 file changed, 99 insertions(+), 3 deletions(-) diff --git a/docs/product/insights/ai/mcp/getting-started.mdx b/docs/product/insights/ai/mcp/getting-started.mdx index 3e2401c62f417..1f8db936a083a 100644 --- a/docs/product/insights/ai/mcp/getting-started.mdx +++ b/docs/product/insights/ai/mcp/getting-started.mdx @@ -51,12 +51,13 @@ const server = Sentry.wrapMcpServerWithSentry(new McpServer({ minVersion="2.43.0" /> -The Sentry Python SDK supports MCP observability for [FastMCP](https://gofastmcp.com/getting-started/welcome). The integration automatically captures spans for your MCP server workflows including tool executions, resource access, and prompt handling. +The Sentry Python SDK supports MCP observability for the [MCP Python SDK](https://github.com/modelcontextprotocol/python-sdk)(both low-level and FastAPI APIs) and [standalone FastMCP](https://gofastmcp.com/getting-started/welcome). The integration automatically captures spans for your MCP server workflows including tool executions, resource access, and prompt handling. -#### Quick Start with FastMCP +#### Quick Start -```python +```python {tabTitle:MCP Python SDK} import sentry_sdk +from sentry_sdk.integrations.mcp import MCPIntegration from mcp.server.fastmcp import FastMCP # Sentry init needs to be above everything else @@ -65,6 +66,7 @@ sentry_sdk.init( traces_sample_rate=1.0, # Optional: Enable to capture tool call arguments and results in Sentry, which may include PII send_default_pii=True, + integrations=[MCPIntegration()], ) # Create the MCP server @@ -79,3 +81,97 @@ async def calculate_sum(a: int, b: int) -> int: # Run the server mcp.run() ``` + +```python {tabTitle:FastMCP} +import sentry_sdk +from sentry_sdk.integrations.mcp import MCPIntegration +from fastmcp import FastMCP + +# Sentry init needs to be above everything else +sentry_sdk.init( + dsn="___PUBLIC_DSN___", + traces_sample_rate=1.0, + # Optional: Enable to capture tool call arguments and results in Sentry, which may include PII + send_default_pii=True, + integrations=[MCPIntegration()], +) + +# Create the MCP server +mcp = FastMCP("Example MCP Server") + +# Define a tool +@mcp.tool() +async def calculate_sum(a: int, b: int) -> int: + """Add two numbers together.""" + return a + b + +# Run the server +mcp.run() +``` + +```python {tabTitle:MCP Low-Level API} +import asyncio +from typing import Any + +import sentry_sdk +from sentry_sdk.integrations.mcp import MCPIntegration +from mcp.server.lowlevel import Server +from mcp.server import stdio +from mcp.types import Tool, TextContent + +# Sentry init needs to be above everything else +sentry_sdk.init( + dsn="___PUBLIC_DSN___", + traces_sample_rate=1.0, + # Optional: Enable to capture tool call arguments and results in Sentry, which may include PII + send_default_pii=True, + integrations=[MCPIntegration()], +) + +# Create the MCP server +server = Server("Example MCP Server") + +# Define tools +@server.list_tools() +async def list_tools() -> list[Tool]: + """List all available tools.""" + return [ + Tool( + name="calculate_sum", + description="Add two numbers together", + inputSchema={ + "type": "object", + "properties": { + "a": {"type": "number", "description": "First number"}, + "b": {"type": "number", "description": "Second number"}, + }, + "required": ["a", "b"], + }, + ) + ] + +# Handle tool execution +@server.call_tool() +async def call_tool(name: str, arguments: dict[str, Any]) -> list[TextContent]: + if name == "calculate_sum": + a = arguments.get("a", 0) + b = arguments.get("b", 0) + result = a + b + return [TextContent(type="text", text=f"The sum is {result}")] + + return [TextContent(type="text", text=f"Unknown tool: {name}")] + +# Run the server +async def main(): + """Run the MCP server using stdio transport.""" + async with stdio.stdio_server() as (read_stream, write_stream): + await server.run( + read_stream, + write_stream, + server.create_initialization_options(), + ) + + +if __name__ == "__main__": + asyncio.run(main()) +``` \ No newline at end of file From ea3829918013d9c02cbcdd85d1282a646005e93e Mon Sep 17 00:00:00 2001 From: Fabian Schindler Date: Wed, 5 Nov 2025 11:29:44 +0100 Subject: [PATCH 2/2] fix: typo --- docs/product/insights/ai/mcp/getting-started.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/product/insights/ai/mcp/getting-started.mdx b/docs/product/insights/ai/mcp/getting-started.mdx index 1f8db936a083a..09e091fb0158f 100644 --- a/docs/product/insights/ai/mcp/getting-started.mdx +++ b/docs/product/insights/ai/mcp/getting-started.mdx @@ -51,7 +51,7 @@ const server = Sentry.wrapMcpServerWithSentry(new McpServer({ minVersion="2.43.0" /> -The Sentry Python SDK supports MCP observability for the [MCP Python SDK](https://github.com/modelcontextprotocol/python-sdk)(both low-level and FastAPI APIs) and [standalone FastMCP](https://gofastmcp.com/getting-started/welcome). The integration automatically captures spans for your MCP server workflows including tool executions, resource access, and prompt handling. +The Sentry Python SDK supports MCP observability for the [MCP Python SDK](https://github.com/modelcontextprotocol/python-sdk) (both low-level and FastMCP APIs) and [standalone FastMCP](https://gofastmcp.com/getting-started/welcome). The integration automatically captures spans for your MCP server workflows including tool executions, resource access, and prompt handling. #### Quick Start