Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
c8318d9
feat(mcp): Add a feedback tool for MCP servers
logaretm Nov 30, 2026
30b2ac4
chore(mcp): Route @sentry/mcp reviews to Abdelrahman, Jan and Rula
logaretm Nov 30, 2026
9658cbc
feat(mcp): Point agents at the feedback tool from other tools' errors
logaretm Nov 30, 2026
476d384
feat(mcp): Skip upstream 4xx and protocol errors when hinting at the …
logaretm Nov 30, 2026
dee4322
feat(mcp): Let servers name who the feedback hint reports to
logaretm Nov 30, 2026
020e43e
feat(mcp): Use one default feedback hint for all errors
logaretm Nov 30, 2026
8542adf
feat(mcp): Use the SDK's own @sentry/core through an optional peer de…
logaretm Nov 30, 2026
2a8eee8
fix(mcp): Only skip JSON-RPC client errors when hinting at the feedba…
logaretm Nov 30, 2026
493fe77
ref(mcp): Trim comments
logaretm Nov 30, 2026
eefc1d7
docs(mcp): Mark @sentry/mcp as beta
logaretm Nov 30, 2026
b787092
ref(mcp): Drop the recipient and scope options and the tool name export
logaretm Nov 30, 2026
a56b941
fix(mcp): Check for a Sentry client when the feedback tool runs, not …
logaretm Nov 30, 2026
ee551a4
test(mcp): Cover a Sentry client that appears after the feedback tool…
logaretm Nov 30, 2026
f7ec36f
feat(mcp): Return hint and withHint from addFeedbackTool, skip errors…
logaretm Nov 30, 2026
990c4aa
ref(mcp): Type the errorHints failure as a thrown Error or a tool err…
logaretm Dec 1, 2026
9e0a076
feat(mcp): Add withFeedbackHint to add the hint without the addFeedba…
logaretm Dec 1, 2026
1392a9b
ref(mcp): Drop hint and withHint from the addFeedbackTool return value
logaretm Dec 1, 2026
c5d02d7
feat(mcp): Default feedbackHint to the tool from the last addFeedback…
logaretm Dec 1, 2026
b02c6f2
ref(mcp): Take the feedbackHint condition as its first argument
logaretm Dec 1, 2026
9863992
feat(mcp): Let feedbackHint take one options object
logaretm Dec 1, 2026
f3639c5
feat(mcp): Add createFeedbackTool for servers that register tools the…
logaretm Dec 1, 2026
8d0c5cc
ref(mcp): Take only the condition in feedbackHint
logaretm Dec 1, 2026
2da27d8
fix(mcp): Return no feedbackHint until a feedback tool is made
logaretm Dec 1, 2026
56f44ba
feat(mcp): Add error hints in createFeedbackTool when given the server
logaretm Dec 1, 2026
8df64f8
feat(mcp): Return the feedback ID as structured content
logaretm Dec 1, 2026
a4194a3
feat(mcp): Name the agent from the MCP SDK v2 handler context or the …
logaretm Dec 1, 2026
c00f78d
ref(mcp): Name the team instead of the maintainers in the feedback hint
logaretm Dec 1, 2026
318798a
docs(mcp): State the @modelcontextprotocol/sdk 1.23.0 floor
logaretm Dec 1, 2026
10b3fc7
fix(mcp): Add error hints on @modelcontextprotocol/sdk 1.23.x
logaretm Dec 1, 2026
a738f64
fix(mcp): Keep error hints after a tool's callback is updated
logaretm Dec 1, 2026
b4637a1
fix(mcp): Return an error from captureAgentFeedback without a Sentry …
logaretm Dec 1, 2026
f7a755e
ref(mcp): Drop the tool() fallback in addFeedbackTool
logaretm Dec 1, 2026
5b87913
fix(scripts): Move range peer dependencies to the new major in bump-v…
logaretm Dec 1, 2026
7ad8373
test(mcp): Type the fake server's handler so createFeedbackTool's han…
logaretm Dec 1, 2026
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
1 change: 1 addition & 0 deletions .github/REVIEWERS
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
/packages/core/src/server-runtime-client.ts @getsentry/team-javascript-sdks-server
/packages/core/src/integrations/http/ @getsentry/team-javascript-sdks-server
/packages/core/src/integrations/mcp-server/ @getsentry/team-javascript-sdks-server
/packages/mcp/ @logaretm @JPeer264 @RulaKhaled
/dev-packages/e2e-tests/test-applications/node-*/ @getsentry/team-javascript-sdks-server
/dev-packages/e2e-tests/test-applications/bun-*/ @getsentry/team-javascript-sdks-server
/dev-packages/e2e-tests/test-applications/deno/ @getsentry/team-javascript-sdks-server
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@modelcontextprotocol/sdk": "1.32.1",
"@modelcontextprotocol/server": "2.3.1",
"@sentry/cloudflare": "file:../../packed/sentry-cloudflare-packed.tgz",
"@sentry/mcp": "file:../../packed/sentry-mcp-packed.tgz",
"agents": "0.31.0",
"zod": "^4.3.6"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as Sentry from '@sentry/cloudflare';
import { McpAgent } from 'agents/mcp';
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import * as z from 'zod';
import { addFeedbackTool } from '@sentry/mcp';

class MyMCPAgentBase extends McpAgent<Env, unknown, Record<string, unknown>> {
#mcpServer = Sentry.wrapMcpServerWithSentry(
Expand All @@ -16,6 +17,8 @@ class MyMCPAgentBase extends McpAgent<Env, unknown, Record<string, unknown>> {
}

async init(): Promise<void> {
addFeedbackTool(this.#mcpServer);

this.#mcpServer.registerTool(
'my-tool',
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { expect, test } from '@playwright/test';
import { waitForEnvelopeItem } from '@sentry-internal/test-utils';

async function rpc(baseURL: string, sessionId: string | undefined, body: unknown): Promise<Response> {
return fetch(`${baseURL}/mcp`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Accept: 'application/json, text/event-stream',
...(sessionId ? { 'Mcp-Session-Id': sessionId } : {}),
},
body: JSON.stringify(body),
});
}

async function result(response: Response): Promise<any> {
const text = await response.text();
const data = text
.split('\n')
.filter(line => line.startsWith('data: '))
.at(-1);
return JSON.parse(data ? data.slice(6) : text).result;
}

test('McpAgent registers the feedback tool in init() and sends reports', async ({ baseURL }) => {
const init = await rpc(baseURL!, undefined, {
jsonrpc: '2.0',
id: 0,
method: 'initialize',
params: {
protocolVersion: '2024-11-05',
capabilities: {},
clientInfo: { name: 'feedback-client', version: '1.0.0' },
},
});
const sessionId = init.headers.get('Mcp-Session-Id')!;
await rpc(baseURL!, sessionId, { jsonrpc: '2.0', method: 'notifications/initialized' });

const tools = await result(
await rpc(baseURL!, sessionId, { jsonrpc: '2.0', id: 1, method: 'tools/list', params: {} }),
);
expect(tools.tools.map((t: { name: string }) => t.name)).toContain('submit_feedback');

const feedbackPromise = waitForEnvelopeItem('cloudflare-mcp-agent', item => item[0].type === 'feedback');
const sent = await result(
await rpc(baseURL!, sessionId, {
jsonrpc: '2.0',
id: 2,
method: 'tools/call',
params: {
name: 'submit_feedback',
arguments: {
task: 'report from an agent',
kind: 'idea',
impact: 'friction',
description: 'Feedback from a Cloudflare McpAgent.',
},
},
}),
);
expect(sent.content[0].text).toMatch(/^Feedback sent \(ID [0-9a-f]{32}\)\.$/);

const [, feedback] = await feedbackPromise;
expect(feedback).toMatchObject({
contexts: {
feedback: {
source: 'mcp_agent',
name: 'MCP agent (feedback-client)',
message: 'Task: report from an agent\n\nFeedback from a Cloudflare McpAgent.',
},
},
tags: { 'feedback.kind': 'idea', 'feedback.impact': 'friction' },
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"dependencies": {
"@modelcontextprotocol/server": "^2.0.0",
"@sentry/cloudflare": "file:../../packed/sentry-cloudflare-packed.tgz",
"@sentry/mcp": "file:../../packed/sentry-mcp-packed.tgz",
"agents": "0.20.1",
"zod": "^4.2.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import * as Sentry from '@sentry/cloudflare';
import { McpServer } from '@modelcontextprotocol/server';
import { createMcpHandler } from 'agents/mcp/server';
import { z } from 'zod';
import { addFeedbackTool } from '@sentry/mcp';

function createServer() {
const server = Sentry.wrapMcpServerWithSentry(
Expand Down Expand Up @@ -54,6 +55,8 @@ function createServer() {
},
);

addFeedbackTool(server);

return server;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { expect, test } from '@playwright/test';
import { waitForEnvelopeItem } from '@sentry-internal/test-utils';

test('sends feedback from a server built per request', async ({ baseURL }) => {
const feedbackPromise = waitForEnvelopeItem('cloudflare-mcp', item => item[0].type === 'feedback');

const response = await fetch(`${baseURL}/mcp?protocol=modern&case=feedback`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Accept: 'application/json, text/event-stream',
'MCP-Protocol-Version': '2026-07-28',
'Mcp-Method': 'tools/call',
'Mcp-Name': 'submit_feedback',
},
body: JSON.stringify({
jsonrpc: '2.0',
id: 'feedback-call',
method: 'tools/call',
params: {
_meta: {
'io.modelcontextprotocol/protocolVersion': '2026-07-28',
'io.modelcontextprotocol/clientInfo': { name: 'cloudflare-feedback-client', version: '1.0.0' },
'io.modelcontextprotocol/clientCapabilities': {},
},
name: 'submit_feedback',
arguments: {
task: 'report from an agent',
kind: 'idea',
impact: 'friction',
description: 'Per-request server.',
},
},
}),
});

expect(response.status).toBe(200);
await expect(response.text()).resolves.toContain('Feedback sent');

const [, feedback] = await feedbackPromise;
expect(feedback).toMatchObject({
contexts: {
feedback: {
source: 'mcp_agent',
name: 'MCP agent (cloudflare-feedback-client)',
message: 'Task: report from an agent\n\nPer-request server.',
},
},
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
},
"dependencies": {
"@modelcontextprotocol/sdk": "^1.26.0",
"@sentry/mcp": "file:../../packed/sentry-mcp-packed.tgz",
"@sentry/node": "file:../../packed/sentry-node-packed.tgz",
"@types/express": "^4.17.21",
"@types/node": "^18.19.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { randomUUID } from 'node:crypto';
import express from 'express';
import { McpServer, ResourceTemplate } from '@modelcontextprotocol/sdk/server/mcp.js';
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
import { addFeedbackTool } from '@sentry/mcp';
import { z } from 'zod';

const mcpRouter = express.Router();
Expand Down Expand Up @@ -51,6 +52,8 @@ server.registerTool('always-error', {}, async () => {
throw new Error('intentional error for span status testing');
});

addFeedbackTool(server, { serverName: 'Echo-V1' });

const transports: Record<string, StreamableHTTPServerTransport> = {};

mcpRouter.post('/mcp', async (req, res) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, test } from '@playwright/test';
import { waitForStreamedSpan, getSpanOp } from '@sentry-internal/test-utils';
import { waitForEnvelopeItem, waitForError, waitForStreamedSpan, getSpanOp } from '@sentry-internal/test-utils';
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';

Expand Down Expand Up @@ -79,6 +79,11 @@ test('auto-instruments a legacy MCP SDK v1 server (no manual wrap)', async ({ ba
});

await test.step('error tool sets span status to error', async () => {
// The feedback hint is added for the agent, but the Sentry error keeps the original message.
const errorPromise = waitForError(
'node-express-mcp-v1',
event => event.exception?.values?.some(value => value.value?.startsWith('intentional error')) ?? false,
);
const toolSegmentPromise = waitForStreamedSpan(
'node-express-mcp-v1',
segment => segment.is_segment && segment.name === 'tools/call always-error',
Expand All @@ -94,6 +99,83 @@ test('auto-instruments a legacy MCP SDK v1 server (no manual wrap)', async ({ ba
expect(toolSegment).toBeDefined();
expect(getSpanOp(toolSegment)).toEqual('mcp.server');
expect(toolSegment?.status).toEqual('error');

const error = await errorPromise;
expect(error.exception?.values?.at(-1)?.value).toBe('intentional error for span status testing');
});

await test.step('lists the tool with its input schema', async () => {
const { tools } = await client.listTools();
const feedbackTool = tools.find(tool => tool.name === 'submit_feedback');

expect(feedbackTool?.description).toContain('Report friction with the Echo-V1 MCP server');
expect(feedbackTool?.inputSchema).toMatchObject({
type: 'object',
properties: {
kind: { enum: ['missing', 'broken', 'confusing', 'idea'] },
impact: { enum: ['blocked', 'worked_around', 'friction'] },
},
required: expect.arrayContaining(['task', 'kind', 'impact', 'description']),
});
});

await test.step('sends a report as user feedback', async () => {
const feedbackPromise = waitForEnvelopeItem('node-express-mcp-v1', item => item[0].type === 'feedback');

const result = await client.callTool({
name: 'submit_feedback',
arguments: {
task: 'echo a message',
kind: 'broken',
impact: 'worked_around',
description: 'echo dropped the trailing newline. Token Bearer abc.def leaked.',
toolName: 'echo',
},
});

expect(result.isError).toBeFalsy();
expect(result.content).toEqual([
{ type: 'text', text: expect.stringMatching(/^Feedback sent \(ID [0-9a-f]{32}\)\.$/) },
]);
expect(result.structuredContent).toEqual({ feedbackId: expect.stringMatching(/^[0-9a-f]{32}$/) });

const [, feedback] = await feedbackPromise;
expect(feedback).toMatchObject({
type: 'feedback',
contexts: {
feedback: {
source: 'mcp_agent',
name: 'MCP agent (test-client-v1)',
message:
'Task: echo a message\nTool: echo\n\necho dropped the trailing newline. Token Bearer [REDACTED_TOKEN] leaked.',
},
},
tags: { 'feedback.kind': 'broken', 'feedback.impact': 'worked_around', 'feedback.tool': 'echo' },
});
});

await test.step('rejects filler reports', async () => {
const result = await client.callTool({
name: 'submit_feedback',
arguments: { task: 'echo a message', kind: 'idea', impact: 'friction', description: 'N/A' },
});

expect(result.isError).toBe(true);
expect(result.content).toEqual([{ type: 'text', text: expect.stringContaining('`description` is a placeholder') }]);
});

await test.step('points the agent at the feedback tool on errors', async () => {
const result = await client.callTool({ name: 'always-error', arguments: {} });

expect(result.isError).toBe(true);
expect(result.content).toEqual([
{
type: 'text',
text: expect.stringContaining(
'intentional error for span status testing\n\nIf this keeps failing after you adjust your request, report it to the Echo-V1 team with `submit_feedback`.',
),
},
]);
});

await client.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"@cfworker/json-schema": "^4.0.0",
"@modelcontextprotocol/node": "^2.0.0",
"@modelcontextprotocol/server": "^2.0.0",
"@sentry/mcp": "file:../../packed/sentry-mcp-packed.tgz",
"@sentry/node": "file:../../packed/sentry-node-packed.tgz",
"@types/express": "^4.17.21",
"@types/node": "^18.19.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { randomUUID } from 'node:crypto';
import express from 'express';
import { McpServer, ResourceTemplate } from '@modelcontextprotocol/server';
import { NodeStreamableHTTPServerTransport } from '@modelcontextprotocol/node';
import { addFeedbackTool } from '@sentry/mcp';
import { z } from 'zod';

const mcpRouter = express.Router();
Expand Down Expand Up @@ -55,6 +56,8 @@ server.registerTool('always-error', {}, async () => {
throw new Error('intentional error for span status testing');
});

addFeedbackTool(server, { serverName: 'Echo-V2' });

const transports: Record<string, NodeStreamableHTTPServerTransport> = {};

mcpRouter.post('/mcp', async (req, res) => {
Expand Down
Loading
Loading