Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 99 additions & 3 deletions docs/product/insights/ai/mcp/getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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 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 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
Expand All @@ -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
Expand All @@ -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())
```
Loading