Set Up
Learn how to set up Sentry MCP Monitoring
Sentry MCP Monitoring helps you track and debug Model Context Protocol (MCP) implementations using our supported SDKs and integrations. Monitor your complete MCP workflows from client connections to server responses, including tool executions, resource access, and protocol communications.
To start sending MCP data to Sentry, make sure you've created a Sentry project for your MCP-enabled repository and follow the guide below:
Version requirement
MCP Monitoring requires Node SDK version 9.46.0 or newer.
The example below uses @modelcontextprotocol/sdk 1.x. The Sentry wrapper automatically captures spans for MCP server workflows, including tool executions, resource access, and client connections.
import * as Sentry from "@sentry/node";
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
// Sentry init needs to be above everything else
Sentry.init({
dsn: "___PUBLIC_DSN___",
tracesSampleRate: 1.0,
});
// Wrap every MCP server instance
const server = Sentry.wrapMcpServerWithSentry(
new McpServer({
name: "my-mcp-server",
version: "1.0.0",
}),
);
...
import * as Sentry from "@sentry/node";
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
// Sentry init needs to be above everything else
Sentry.init({
dsn: "___PUBLIC_DSN___",
tracesSampleRate: 1.0,
});
// Wrap every MCP server instance
const server = Sentry.wrapMcpServerWithSentry(
new McpServer({
name: "my-mcp-server",
version: "1.0.0",
}),
);
...
Stable @modelcontextprotocol/server 2.x support requires Sentry JavaScript SDK version 10.70.0 or newer. For framework-specific setup, see MCP Monitoring for Node.js, Hono, or Cloudflare.
The recordInputs and recordOutputs options require Sentry JavaScript SDK version 10.33.0 or newer.
Type: boolean
Records inputs to MCP tool and prompt calls (such as tool arguments and prompt parameters).
Defaults to dataCollection.genAI.inputs. In Sentry JavaScript SDK 10.x, when dataCollection isn't configured, this follows sendDefaultPii.
Type: boolean
Records outputs from MCP tool and prompt calls (such as tool results and prompt messages).
Defaults to dataCollection.genAI.outputs. In Sentry JavaScript SDK 10.x, when dataCollection isn't configured, this follows sendDefaultPii.
MCP work on Cloudflare can finish after the Worker returns an HTTP response. Configure traceLifecycle: "stream" so spans are sent when they finish instead of depending on a static request snapshot. This requires @sentry/cloudflare version 10.49.0 or newer.
See MCP Monitoring on Cloudflare for the configuration and filtering differences in stream mode.
Version requirement
MCP Monitoring requires Python SDK version 2.43.0 or newer.
The Sentry Python SDK supports MCP Monitoring for the MCP Python SDK (both low-level and FastMCP APIs) and standalone FastMCP. The integration automatically captures spans for your MCP server workflows, including tool executions, resource access, and prompt handling.
import sentry_sdk
from sentry_sdk.integrations.mcp import MCPIntegration
from mcp.server.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()
import sentry_sdk
from sentry_sdk.integrations.mcp import MCPIntegration
from mcp.server.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()
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()
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())
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").