Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
157 changes: 123 additions & 34 deletions docs/platforms/javascript/common/mcp-monitoring/agent-feedback.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
title: Collect Agent Feedback
sidebar_title: Agent Feedback
sidebar_order: 10
new_until: 2027-03-03
description: "Let AI agents report problems with your MCP server's tools as Sentry Feedback."
supportedCategories:
- server
Expand All @@ -15,7 +16,7 @@ supportedCategories:

AI agents that use your MCP server know when a tool is missing, fails, or returns something confusing. `@sentry/mcp` adds a feedback tool to your server so agents can report that friction. Each report arrives in [Feedback](/product/user-feedback/) with tags that describe what went wrong.

This only needs a Sentry SDK initialized with a DSN. We recommend also setting up <PlatformLink to="/mcp-monitoring/">MCP Monitoring</PlatformLink>, so errors your tools throw are captured too, and each report links to the trace of its `submit_feedback` call.
![An agent's tool call fails, the error result tells it to report the problem with submit_feedback, and the report arrives in Sentry as Feedback.](/img/agent-feedback-flow.svg)

## Install

Expand All @@ -38,25 +39,105 @@ pnpm add @sentry/mcp

## Add the Feedback Tool

Call `addFeedbackTool` with your `McpServer` from `@modelcontextprotocol/server`, or from `@modelcontextprotocol/sdk` 1.23.0 or newer:
Add the integration once, and every MCP server Sentry instruments gets the tool. Set it up by hand only if the integration can't cover your server, as described in [Manual Setup](#manual-setup).

The tool, the hints, and error capture all work without tracing.

<Alert>

Keep `@sentry/mcp` on the same version as your Sentry SDK. On a different version, the integration turns itself off.

</Alert>

<PlatformSection notSupported={["javascript.cloudflare"]}>

Add `mcpFeedbackIntegration` to your `Sentry.init` call:

```javascript
import * as Sentry from "@sentry/node";
import { McpServer } from "@modelcontextprotocol/server";
import { addFeedbackTool } from "@sentry/mcp";
import * as Sentry from "___SDK_PACKAGE___";
import { mcpFeedbackIntegration } from "@sentry/mcp";

Sentry.init({
dsn: "___PUBLIC_DSN___",
integrations: [
// Adds the feedback tool to your MCP servers
mcpFeedbackIntegration(),
],
});
```

const server = Sentry.wrapMcpServerWithSentry(
new McpServer({ name: "orders", version: "1.0.0" })
);
</PlatformSection>

server.registerTool("search_orders", { ... }, handler);
<PlatformSection supported={["javascript.nextjs"]}>

addFeedbackTool(server, { serverName: "Orders" });
Add it to the `Sentry.init` call in `sentry.server.config.ts`. Route handlers already run on Node.js, so leave out `export const runtime = "nodejs"`. With `cacheComponents` on, it fails the build.

</PlatformSection>

<PlatformSection supported={["javascript.bun"]}>

On Bun, Sentry only adds the tool to an instrumented server. Build your app with the [Sentry Bun plugin](/platforms/javascript/guides/bun/#build-with-the-sentry-plugin-recommended), or run it with `--preload @sentry/bun/import` on Bun 1.4.6 or newer. Without either, your server gets no tool, no hints, and no error capture.

</PlatformSection>

<PlatformSection supported={["javascript.cloudflare"]}>

Add `mcpFeedbackIntegration` to your Sentry options. With the <PlatformLink to="/install/vite-plugin/">Vite plugin</PlatformLink>, they're in `instrument.server.ts`. The plugin instruments your server, so you don't need other code.

On a <PlatformLink to="/install/wrangler/">Wrangler build</PlatformLink>, pass the same options to `withSentry` and to the class that hosts your server, since your Worker and its Durable Objects share one Sentry client, and wrap the server with `wrapMcpServerWithSentry`.

```typescript {tabTitle:Vite} {filename:instrument.server.ts} {mdExpandTabs}
import { defineCloudflareOptions } from "@sentry/cloudflare";
import { mcpFeedbackIntegration } from "@sentry/mcp";

export default defineCloudflareOptions((env) => ({
dsn: "___PUBLIC_DSN___",
integrations: [
// Adds the feedback tool to your MCP servers
mcpFeedbackIntegration(),
],
}));
```

```typescript {tabTitle:Wrangler} {filename:index.ts}
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import * as Sentry from "@sentry/cloudflare";
import { mcpFeedbackIntegration } from "@sentry/mcp";
import { McpAgent } from "agents/mcp";

const sentryOptions = (env: Env) => ({
dsn: "___PUBLIC_DSN___",
integrations: [
// Adds the feedback tool to your MCP servers
mcpFeedbackIntegration(),
],
});

class MyMCPBase extends McpAgent<Env> {
server = Sentry.wrapMcpServerWithSentry(
new McpServer({ name: "orders", title: "Orders", version: "1.0.0" })
);

async init() {
// Register your tools on this.server
}
}

export const MyMCP = Sentry.instrumentAgentWithSentry(sentryOptions, MyMCPBase);

export default Sentry.withSentry(
sentryOptions,
MyMCP.serve("/mcp", { binding: "MY_MCP" })
);
```

This registers a `submit_feedback` tool that agents call when one of your tools is missing, fails, or gets in the way. By default, it also adds a hint to your other tools' errors that tells agents to report them with it. Learn more in [Point Agents at the Tool](#point-agents-at-the-tool).
</PlatformSection>

The integration adds the tool to every `McpServer` that Sentry instruments, from `@modelcontextprotocol/server`, or from `@modelcontextprotocol/sdk` 1.23.0 or newer. If your server isn't instrumented automatically, wrap it with `wrapMcpServerWithSentry` as shown in <PlatformLink to="/mcp-monitoring/">MCP Monitoring</PlatformLink>. Without a DSN, no tool is added.

Agents describe each report with:
## What Agents Report

Agents call `submit_feedback` when one of your tools is missing, fails, or gets in the way, and describe each report with:

| Field | Values |
| ------------- | ------------------------------------------- |
Expand All @@ -68,47 +149,47 @@ Agents describe each report with:

In Sentry, reports are tagged with `feedback.kind`, `feedback.impact`, and `feedback.tool`. Filler descriptions such as `N/A` or `test` are rejected, and tokens and email addresses are removed from the message.

## Point Agents at the Tool
## Result Hints

Agents rarely go looking for a feedback tool, so `addFeedbackTool` also adds a hint to the errors of your other tools:
Agents rarely go looking for a feedback tool, so the results of your other tools tell them about it:

```text
Upstream returned 500

If this keeps failing after you adjust your request, report it to the Orders team with `submit_feedback`.
```

Only the agent sees the hint. Errors in Sentry keep their original message, and your tools' successful results and `structuredContent` don't change.
Only the agent sees the hint. Errors in Sentry keep their original message, and `structuredContent` doesn't change.

### Choose Which Errors Get the Hint
### Error Hints

By default, upstream HTTP 4xx errors (bad input, auth, rate limits) and JSON-RPC client errors (invalid params) don't get the hint, since they aren't your server's to fix.

The `errorHints` option lets you change which errors get the hint:
The `errorHints` option of `mcpFeedbackIntegration` and `addFeedbackTool` lets you change which errors get the hint:

- To build on the defaults and narrow them down further, pass a callback that combines `shouldHintFeedback` with your own logic.
- To replace the defaults, pass a callback with your own logic.
- To turn the error hints off for all tools, pass `false`.

```javascript
import { addFeedbackTool, shouldHintFeedback } from "@sentry/mcp";
import { mcpFeedbackIntegration, shouldHintFeedback } from "@sentry/mcp";

// Keep the defaults, and also skip errors of your own type
addFeedbackTool(server, {
mcpFeedbackIntegration({
errorHints: (toolName, failure) =>
shouldHintFeedback(failure) && !(failure instanceof CustomError),
});

// Replace the defaults: hint on every error except those from search_orders
addFeedbackTool(server, {
mcpFeedbackIntegration({
errorHints: (toolName) => toolName !== "search_orders",
});

// Turn the error hints off for all tools
addFeedbackTool(server, { errorHints: false });
mcpFeedbackIntegration({ errorHints: false });
```

### Add the Hint to Other Results
### Other Result Hints

Some results aren't errors but still suggest a problem, like a search that comes back empty. Add the hint to those yourself with `withFeedbackHint`, and tell the agent when to report it:

Expand Down Expand Up @@ -141,26 +222,34 @@ If you don't say when to report it, the hint starts with "If this keeps failing

## Options

| Option | Default | Description |
| ------------- | -------------------- | -------------------------------------------------------------------------- |
| `name` | `submit_feedback` | The tool name, also used in the hints |
| `serverName` | none | Names your server in the tool description and the error hints |
| `description` | built-in | Replaces the tool description |
| `scrub` | none | Removes more sensitive data from each report, after the built-in scrubbing |
| `errorHints` | `shouldHintFeedback` | `false`, or a function that decides per failure |
| Option | Default | Description |
| ------------- | -------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
| `name` | `submit_feedback` | The tool name, also used in the hints. A server that already has a tool with this name is left as it is |
| `serverName` | Your server's `title` or `name`, none for `createFeedbackTool` | Names your server in the tool description and the error hints |
| `description` | built-in | Replaces the tool description |
| `scrub` | none | Removes more sensitive data from each report, after the built-in scrubbing |
| `errorHints` | `shouldHintFeedback` | `false`, or a function that decides per failure |

The report's display name includes the user ID only when <PlatformLink to="/configuration/options/#dataCollection">`dataCollection.userInfo`</PlatformLink> is enabled.

## Register the Tool Yourself
## Manual Setup

If only some of your servers should get the tool, or you register tools through your own catalog, add the tool yourself with one of these functions. Both take the same [options](#options).

`addFeedbackTool` adds the tool to the `McpServer` you pass it, and the hint to its other tools' errors:

```javascript
import { addFeedbackTool } from "@sentry/mcp";

addFeedbackTool(server, { serverName: "Orders" });
```

If your server registers tools through its own catalog, create the tool with `createFeedbackTool` and register it like your other tools:
`createFeedbackTool` creates the tool for you to register, for example through your own tool catalog. Your other tools' errors don't get the hint, so add it yourself with [`feedbackHint`](#other-result-hints):

```javascript
import { createFeedbackTool } from "@sentry/mcp";

const tool = createFeedbackTool({ serverName: "Orders", server });
const tool = createFeedbackTool({ serverName: "Orders" });

server.registerTool(tool.name, tool.config, tool.handler);
```

`createFeedbackTool` takes the same [options](#options) as `addFeedbackTool`. Pass it your `server` so your other tools' errors get the hint.
Loading
Loading