Skip to content

Commit ef2ad9d

Browse files
fix(insights-mcp): improve docs to clarify situation with libraries with MCP SDK and FastAPI (#15413)
## DESCRIBE YOUR PR Contributes to https://linear.app/getsentry/issue/TET-1328/fastmcp-documentation-onboarding ## IS YOUR CHANGE URGENT? Help us prioritize incoming PRs by letting us know when the change needs to go live. - [ ] Urgent deadline (GA date, etc.): <!-- ENTER DATE HERE --> - [ ] Other deadline: <!-- ENTER DATE HERE --> - [x] None: Not urgent, can wait up to 1 week+ ## SLA - Teamwork makes the dream work, so please add a reviewer to your PRs. - Please give the docs team up to 1 week to review your PR unless you've added an urgent due date to it. Thanks in advance for your help! ## PRE-MERGE CHECKLIST *Make sure you've checked the following before merging your changes:* - [ ] Checked Vercel preview for correctness, including links - [ ] PR was reviewed and approved by any necessary SMEs (subject matter experts) - [ ] PR was reviewed and approved by a member of the [Sentry docs team](https://github.com/orgs/getsentry/teams/docs) ## LEGAL BOILERPLATE <!-- Sentry employees and contractors can delete or ignore this section. --> Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms. ## EXTRA RESOURCES - [Sentry Docs contributor guide](https://docs.sentry.io/contributing/)
1 parent 994c231 commit ef2ad9d

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 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.
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)