Skip to main content
Glama
manufacts

mcp-use-sentry-example

by manufacts
README.md
# Sentry tool monitoring

Trace mcp-use tool callbacks and report both returned tool errors and exceptions using existing MCP middleware. No SDK changes or additional application services are required.

## Run

Requires Node.js 22.22.2 or newer. Clone this repository, then:

```bash
npm install
cp .env.example .env
# Set MCP_USE_SENTRY_DSN to your Sentry project DSN.
npm run dev
```

In Inspector, call `monitored_report` with `outcome` set to `success`, `tool_error`, or `exception`. Look for `tools/call monitored_report` in Sentry Traces and the failures in Issues. Without a DSN, tools still work but no telemetry is sent.

The example initializes Sentry once with automatic integrations disabled and every trace sampled. Arguments and returned content are not recorded. Exception messages and stacks are captured. Reuse an existing Sentry initialization when adapting this middleware, and check for duplicate capture from other instrumentation.

This monitors registered tool callbacks, not transport failures or validation rejected before callback dispatch. It targets a long-running Node process; serverless runtimes need lifecycle-aware flushing.

## Verify

```bash
npm run typecheck
npm run test
npm run build
```

Tests invoke the server over MCP and use real Sentry spans and error processing with a local transport. No Sentry account or network access is needed for the tests.