Skip to content

Commit e87784b

Browse files
committed
fix(insights-mcp): improve docs to clarify situation with libraries with MCP SDK and FastAPI
1 parent 5167542 commit e87784b

File tree

1 file changed

+99
-3
lines changed

1 file changed

+99
-3
lines changed

docs/product/insights/ai/mcp/getting-started.mdx

Lines changed: 99 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,13 @@ const server = Sentry.wrapMcpServerWithSentry(new McpServer({
5151
minVersion="2.43.0"
5252
/>
5353

54-
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.
54+
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.
5555

56-
#### Quick Start with FastMCP
56+
#### Quick Start
5757

58-
```python
58+
```python {tabTitle:MCP Python SDK}
5959
import sentry_sdk
60+
from sentry_sdk.integrations.mcp import MCPIntegration
6061
from mcp.server.fastmcp import FastMCP
6162

6263
# Sentry init needs to be above everything else
@@ -65,6 +66,7 @@ sentry_sdk.init(
6566
traces_sample_rate=1.0,
6667
# Optional: Enable to capture tool call arguments and results in Sentry, which may include PII
6768
send_default_pii=True,
69+
integrations=[MCPIntegration()],
6870
)
6971

7072
# Create the MCP server
@@ -79,3 +81,97 @@ async def calculate_sum(a: int, b: int) -> int:
7981
# Run the server
8082
mcp.run()
8183
```
84+
85+
```python {tabTitle:FastMCP}
86+
import sentry_sdk
87+
from sentry_sdk.integrations.mcp import MCPIntegration
88+
from fastmcp import FastMCP
89+
90+
# Sentry init needs to be above everything else
91+
sentry_sdk.init(
92+
dsn="___PUBLIC_DSN___",
93+
traces_sample_rate=1.0,
94+
# Optional: Enable to capture tool call arguments and results in Sentry, which may include PII
95+
send_default_pii=True,
96+
integrations=[MCPIntegration()],
97+
)
98+
99+
# Create the MCP server
100+
mcp = FastMCP("Example MCP Server")
101+
102+
# Define a tool
103+
@mcp.tool()
104+
async def calculate_sum(a: int, b: int) -> int:
105+
"""Add two numbers together."""
106+
return a + b
107+
108+
# Run the server
109+
mcp.run()
110+
```
111+
112+
```python {tabTitle:MCP Low-Level API}
113+
import asyncio
114+
from typing import Any
115+
116+
import sentry_sdk
117+
from sentry_sdk.integrations.mcp import MCPIntegration
118+
from mcp.server.lowlevel import Server
119+
from mcp.server import stdio
120+
from mcp.types import Tool, TextContent
121+
122+
# Sentry init needs to be above everything else
123+
sentry_sdk.init(
124+
dsn="___PUBLIC_DSN___",
125+
traces_sample_rate=1.0,
126+
# Optional: Enable to capture tool call arguments and results in Sentry, which may include PII
127+
send_default_pii=True,
128+
integrations=[MCPIntegration()],
129+
)
130+
131+
# Create the MCP server
132+
server = Server("Example MCP Server")
133+
134+
# Define tools
135+
@server.list_tools()
136+
async def list_tools() -> list[Tool]:
137+
"""List all available tools."""
138+
return [
139+
Tool(
140+
name="calculate_sum",
141+
description="Add two numbers together",
142+
inputSchema={
143+
"type": "object",
144+
"properties": {
145+
"a": {"type": "number", "description": "First number"},
146+
"b": {"type": "number", "description": "Second number"},
147+
},
148+
"required": ["a", "b"],
149+
},
150+
)
151+
]
152+
153+
# Handle tool execution
154+
@server.call_tool()
155+
async def call_tool(name: str, arguments: dict[str, Any]) -> list[TextContent]:
156+
if name == "calculate_sum":
157+
a = arguments.get("a", 0)
158+
b = arguments.get("b", 0)
159+
result = a + b
160+
return [TextContent(type="text", text=f"The sum is {result}")]
161+
162+
return [TextContent(type="text", text=f"Unknown tool: {name}")]
163+
164+
# Run the server
165+
async def main():
166+
"""Run the MCP server using stdio transport."""
167+
async with stdio.stdio_server() as (read_stream, write_stream):
168+
await server.run(
169+
read_stream,
170+
write_stream,
171+
server.create_initialization_options(),
172+
)
173+
174+
175+
if __name__ == "__main__":
176+
asyncio.run(main())
177+
```

0 commit comments

Comments
 (0)