Try the live example
Select monitored_report, choose an outcome, and click Execute. Trysuccess for a report, tool_error for a returned tool error, and exception for a thrown exception. No chat model or API key is needed to use the demo.
Open the example in a new tab.
This hosted demo sends traces and intentional errors to Manufact’s demo Sentry project. The tool result is visible here; run your own copy with your DSN to inspect the corresponding issues and traces in your Sentry account.
Prerequisites
- A working mcp-use server running on Node.js.
- A Sentry project and its DSN, available under Project Settings → Client Keys (DSN).
Add the integration
Install Sentry in your server project:.env:
.env
.env out of version control. Initialize Sentry once in your server entry point, then add the middleware below. If your application already initializes Sentry, reuse that initialization rather than calling Sentry.init() again.
Copy this complete example into src/index.ts, or keep your existing tools and add the initialization and middleware:
src/index.ts
withIsolationScope keeps each call’s error tags separate from concurrent requests. startSpan ends the span when the callback finishes. Returning isError: true is a valid MCP result, so the middleware explicitly marks it as failed and reports a stable message. Exceptions are captured and rethrown to preserve normal MCP error handling.
Try it
Start or restart your server so it loads.env:
In your Sentry project, look for the transaction/span named
tools/call monitored_report in Traces, and the two error types in Issues. Error events have the mcp.tool.name tag. Delivery and indexing are asynchronous; leave the development server running briefly after making the calls.
Adapt it to your server
- Replace
monitored_reportwith your own tools. The middleware covers registered tool callbacks; discovery and failures rejected before callback dispatch are outside its scope. - The demo samples every trace with
tracesSampleRate: 1.0. Choose a suitable sample rate for production traffic. - Tool arguments and returned content are not attached to telemetry. Captured exceptions still include their messages and stack traces; redact sensitive application errors using Sentry’s
beforeSendconfiguration as needed. defaultIntegrations: falseintentionally disables automatic integrations for this focused example. Applications that already use Sentry should retain their existing setup and check for overlapping error capture. Automatic HTTP/database instrumentation has additional initialization requirements; this recipe only demonstrates explicit spans.- For a long-running Node server, let Sentry send in the background. For a short-lived script, await
Sentry.flush(2000)before exit. Serverless deployments need their platform’s supported lifecycle integration so queued telemetry can finish; do not assume a returned HTTP response keeps the process alive.
wrapMcpServerWithSentry targets underlying MCP SDK instances and should not be applied directly to the outer mcp-use server.