Free toolGenerate .mcp.json configs for Claude Code, Cursor & Codex →

Based on Sentry and Anthropic official docs, checked

How to add Sentry error monitoring with Claude Code

Sentry scores 5/5 on our Claude Code fit scale: it ships an official plugin with a hosted MCP server. Sentry catches the errors your users hit in production and shows you the stack trace, the affected release, and the exact line that broke, instead of leaving you guessing from a vague bug report. This guide wires Sentry into a Next.js app with Claude Code doing the editing, using the official Sentry plugin, the hosted Sentry MCP server, and the Sentry JavaScript SDK. By the end you will have a live project, a test error in your Issues list, and an alert that tells you when the next real error shows up.

  1. 1. Create a Sentry account and project

    Sign up at sentry.io and create a project. Pick the platform that matches your app. This guide follows the Next.js setup, and Sentry has the same flow for plain JavaScript, Node.js, React, and other platforms.

    When the project is ready, copy its DSN (Data Source Name). The DSN is the address your SDK sends events to, and you will paste it into your app config in step 5. You can find it again any time in your project settings.

    Source: https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/

  2. 2. Install the official Sentry plugin in Claude Code

    The Sentry plugin lives in Anthropic's official marketplace, claude-plugins-official, which Claude Code adds automatically the first time you start an interactive session. Install it with one command inside Claude Code.

    The plugin bundles the Sentry MCP server and a set of Sentry skills, so Claude can read your Sentry issues and follow Sentry's own setup workflows without you pasting docs into the chat.

    /plugin install sentry@claude-plugins-official

    Source: https://code.claude.com/docs/en/discover-plugins

  3. 3. Connect Claude Code to Sentry with the MCP server

    The plugin gives Claude the tools, but Claude still needs to sign in to your Sentry account. The hosted Sentry MCP server uses OAuth, so no API key is needed. Run this command in your terminal, replacing the placeholders with your own organization and project slugs.

    Scoping the URL to one project is recommended, because the tools then default to that project and the discovery tools you do not need stay hidden. After adding the server, run /mcp inside Claude Code and complete the browser sign-in when it asks.

    claude mcp add --transport http sentry https://mcp.sentry.dev/mcp/{organizationSlug}/{projectSlug}

    Source: https://mcp.sentry.dev/

  4. 4. Install the SDK in your app

    Ask Claude to install the SDK, or run the install yourself. For Next.js 15 or later with the App Router and Turbopack, the package is @sentry/nextjs, and you need Node.js 20.19.0 or later.

    Then wrap your Next.js config with withSentryConfig and add your org and project slugs. Sentry's manual setup also asks for three init files in your app root: instrumentation-client.ts for the browser, sentry.server.config.ts for the server, and sentry.edge.config.ts for the edge runtime, plus an instrumentation.ts file that loads the server and edge configs.

    npm install @sentry/nextjs --save
    
    // next.config.ts
    import { withSentryConfig } from "@sentry/nextjs/config";
    
    export default withSentryConfig(nextConfig, {
      org: "YOUR_ORG_SLUG",
      project: "YOUR_PROJECT_SLUG",
      silent: !process.env.CI,
    });
    
    // instrumentation-client.ts
    import * as Sentry from "@sentry/nextjs";
    
    Sentry.init({
      dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
      tracesSampleRate: process.env.NODE_ENV === "development" ? 1.0 : 0.1,
    });

    Source: https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/

  5. 5. Keep the DSN and auth token in environment variables

    Put the DSN in a .env.local file so it never lands in git. The DSN is a public identifier for your project, not a password, but keeping it in an env var keeps every environment on its own value.

    Source maps are what turn minified production stack traces back into readable code. To upload them, add the authToken option to withSentryConfig and set SENTRY_AUTH_TOKEN in your CI environment. Treat the auth token like a password: never commit it and never paste it into a chat.

    # .env.local (never commit this file)
    NEXT_PUBLIC_SENTRY_DSN=https://YOUR_PUBLIC_KEY@o0.ingest.sentry.io/YOUR_PROJECT_ID
    
    // next.config.ts, inside withSentryConfig
    authToken: process.env.SENTRY_AUTH_TOKEN,
    widenClientFileUpload: true,

    Source: https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/

  6. 6. Trigger a test error and confirm it in Sentry

    Error monitoring starts working as soon as you call Sentry.init(), so prove it with a deliberate error before you ship. Add a button to any page that throws, run your app, and click it.

    Then open Issues in Sentry. Your test error should appear there within seconds, with its stack trace and the browser and release details attached. If it does not show up, check the troubleshooting section below before changing anything else.

    <button
      type="button"
      onClick={() => {
        throw new Error("Sentry Test Error");
      }}
    >
      Break the world
    </button>

    Source: https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/

What the Sentry skills do

The plugin bundles skills that Claude loads when they are relevant, including sentry-get-started, sentry-instrument, sentry-debug-issue, sentry-fix-stack-traces, sentry-create-alert, sentry-setup-releases, sentry-otel-exporter-setup, and sentry-snapshots-cocoa. You do not need to memorize them. Describe the job and let Claude pick the skill.

A prompt that works well is: "Help me add Sentry error monitoring in this project. Follow the Sentry skills, keep secrets in environment variables, and show me the plan before changing files." Ask Claude to show the plan first, because the SDK touches your app entry points and your build config.

Check tracing, replay, and logs too

Error monitoring is only the first feature that starts working. The same Sentry.init() call also enables tracing when you set tracesSampleRate, session replay when you add replayIntegration(), and structured logs, which are on by default in the Next.js SDK.

Verify each one the same way you verified errors: navigate around your app and open Traces in Sentry, trigger an error and open Replays to watch the session that led to it, then send a log with Sentry.logger.info() and check Logs. If replay shows masked text everywhere, that is the default privacy setting doing its job, and you can tune it in the replay privacy configuration.

Set up an alert so new issues reach you

An error feed nobody watches is just a log file. In Sentry, go to Alerts and click Create Alert, choose your project, then build the rule with WHEN, IF, and THEN blocks. A good first rule fires when a new issue is created and sends you a notification.

Start narrow. Alert on new issues at error level or higher, not on every warning, or your channel will fill up and you will start ignoring it. You can add a second rule later for spikes, such as an issue seen many times in one hour.

Troubleshooting

Three problems cover most broken Sentry setups. Work through them in order before reinstalling anything.

Tips

Next steps

Frequently asked questions

No. The official Sentry plugin already bundles the MCP server, so installing the plugin is enough for most setups. The direct claude mcp add command is the alternative if you want only the MCP connection without the plugin's skills.

Sources