Skip to content

Commit f19320e

Browse files
AbhiPrasaddcramer
andauthored
feat: Upgrade JS SDK to 9.16.1 and add durable objects instrumentation (#165)
Durable objects instrumentation support was added in [9.16.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.16.0) of the JS SDK. This PR upgrades `sentry-mcp` to get instrumented with durable objects. Docs PR for durable objects is here: getsentry/sentry-docs#13626. In `packages/mcp-cloudflare/src/server/lib/mcp-transport.ts` I had to comment out the `wrapMcpServerWithSentry` usage, because this breaks locally with miniflare. We're following up with the cloudflare team about this (more details here in linear: https://linear.app/getsentry/issue/JS-398/9150-breaks-cloudflare-sdk-usage-in-sentry-mcp#comment-7ce26edb). When we fix this, we'll come back and re-enable it. `9.16.0` also added support for logs in the Cloudflare SDK, so I enabled that, and added the `consoleLoggingIntegration` (integration is optional while logs is experimental in the SDK) to flush logs from `console.X` calls to Sentry. --------- Co-authored-by: David Cramer <[email protected]>
1 parent 20d10a2 commit f19320e

File tree

8 files changed

+128
-113
lines changed

8 files changed

+128
-113
lines changed

packages/mcp-cloudflare/package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"@cloudflare/workers-types": "^4.20250430.0",
2828
"@sentry/mcp-server": "workspace:*",
2929
"@sentry/mcp-server-tsconfig": "workspace:*",
30-
"@sentry/vite-plugin": "^3.3.1",
30+
"@sentry/vite-plugin": "^3.4.0",
3131
"@tailwindcss/typography": "^0.5.16",
3232
"@tailwindcss/vite": "^4.1.5",
3333
"@types/react": "^19.1.2",
@@ -43,9 +43,8 @@
4343
"@modelcontextprotocol/sdk": "^1.10.2",
4444
"@radix-ui/react-accordion": "^1.2.8",
4545
"@radix-ui/react-slot": "^1.2.0",
46-
"@sentry/cloudflare": "9.14.0",
47-
"@sentry/core": "9.14.0",
48-
"@sentry/react": "9.14.0",
46+
"@sentry/cloudflare": "9.16.1",
47+
"@sentry/react": "9.16.1",
4948
"agents": "~0.0.75",
5049
"better-sqlite3": "^11.9.1",
5150
"class-variance-authority": "^0.7.1",

packages/mcp-cloudflare/src/server/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
import * as Sentry from "@sentry/cloudflare";
12
import OAuthProvider from "@cloudflare/workers-oauth-provider";
23
import SentryMCP from "./lib/mcp-transport";
34
import app from "./app";
45
import { SCOPES } from "../constants";
56
import type { Env } from "./types";
6-
import * as Sentry from "@sentry/cloudflare";
77

88
// required for Durable Objects
99
export { SentryMCP };
@@ -29,6 +29,10 @@ export default Sentry.withSentry(
2929
environment:
3030
env.SENTRY_ENVIRONMENT ??
3131
(process.env.NODE_ENV !== "production" ? "development" : "production"),
32+
_experiments: {
33+
enableLogs: true,
34+
},
35+
integrations: [Sentry.consoleLoggingIntegration()],
3236
}),
3337
oAuthProvider,
3438
) satisfies ExportedHandler<Env>;
Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
1+
import * as Sentry from "@sentry/cloudflare";
12
import { McpAgent } from "agents/mcp";
23
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
34
import { configureServer } from "@sentry/mcp-server/server";
45
import type { Env, WorkerProps } from "../types";
5-
import { flush } from "@sentry/cloudflare";
6-
import { wrapMcpServerWithSentry } from "@sentry/core";
76
import { LIB_VERSION } from "@sentry/mcp-server/version";
87

98
// Context from the auth process, encrypted & stored in the auth token
109
// and provided to the DurableMCP as this.props
11-
export default class SentryMCP extends McpAgent<Env, unknown, WorkerProps> {
12-
server = wrapMcpServerWithSentry(
13-
new McpServer({
14-
name: "Sentry MCP",
15-
version: LIB_VERSION,
16-
}),
17-
);
10+
class SentryMCPBase extends McpAgent<Env, unknown, WorkerProps> {
11+
server = new McpServer({
12+
name: "Sentry MCP",
13+
version: LIB_VERSION,
14+
});
15+
// Note: This does not work locally with miniflare so we are not using it
16+
// server = wrapMcpServerWithSentry(
17+
// new McpServer({
18+
// name: "Sentry MCP",
19+
// version: LIB_VERSION,
20+
// }),
21+
// );
22+
23+
// biome-ignore lint/complexity/noUselessConstructor: Need the constructor to match the durable object types.
24+
constructor(state: DurableObjectState, env: Env) {
25+
super(state, env);
26+
}
1827

1928
async init() {
2029
await configureServer({
@@ -25,8 +34,27 @@ export default class SentryMCP extends McpAgent<Env, unknown, WorkerProps> {
2534
userId: this.props.id,
2635
},
2736
onToolComplete: () => {
28-
this.ctx.waitUntil(flush(2000));
37+
this.ctx.waitUntil(Sentry.flush(2000));
2938
},
3039
});
3140
}
3241
}
42+
43+
export default Sentry.instrumentDurableObjectWithSentry(
44+
(env) => ({
45+
dsn: env.SENTRY_DSN,
46+
tracesSampleRate: 1,
47+
sendDefaultPii: true,
48+
initialScope: {
49+
tags: {
50+
durable_object: true,
51+
mcp_server_version: LIB_VERSION,
52+
},
53+
},
54+
_experiments: {
55+
enableLogs: true,
56+
},
57+
integrations: [Sentry.consoleLoggingIntegration()],
58+
}),
59+
SentryMCPBase,
60+
);

packages/mcp-cloudflare/src/server/types.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { OAuthHelpers } from "@cloudflare/workers-oauth-provider";
2-
import type SentryMCP from "./lib/mcp-transport";
32
import type { ServerContext } from "@sentry/mcp-server/types";
43

54
export type WorkerProps = ServerContext & {
@@ -17,7 +16,7 @@ export interface Env {
1716
SENTRY_CLIENT_SECRET: string;
1817
SENTRY_DSN?: string;
1918
SENTRY_HOST?: string;
20-
MCP_OBJECT: DurableObjectNamespace<SentryMCP>;
19+
MCP_OBJECT: DurableObjectNamespace;
2120
OAUTH_PROVIDER: OAuthHelpers;
2221
AI: Ai;
2322
}

packages/mcp-server-tsconfig/package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,5 @@
22
"name": "@sentry/mcp-server-tsconfig",
33
"version": "0.5.0",
44
"private": true,
5-
"files": [
6-
"tsconfig.base.json",
7-
"tsconfig.vite.json"
8-
]
5+
"files": ["tsconfig.base.json", "tsconfig.vite.json"]
96
}

packages/mcp-server/package.json

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
"author": "Sentry",
1414
"description": "Sentry MCP Server",
1515
"homepage": "https://github.com/getsentry/sentry-mcp",
16-
"keywords": [
17-
"sentry"
18-
],
16+
"keywords": ["sentry"],
1917
"bugs": {
2018
"url": "https://github.com/getsentry/sentry-mcp/issues"
2119
},
@@ -26,9 +24,7 @@
2624
"bin": {
2725
"sentry-mcp": "./dist/index.js"
2826
},
29-
"files": [
30-
"./dist/*"
31-
],
27+
"files": ["./dist/*"],
3228
"exports": {
3329
".": {
3430
"types": "./dist/index.ts",
@@ -87,8 +83,8 @@
8783
},
8884
"dependencies": {
8985
"@modelcontextprotocol/sdk": "^1.10.2",
90-
"@sentry/core": "^9.14.0",
91-
"@sentry/node": "^9.14.0",
86+
"@sentry/core": "^9.16.1",
87+
"@sentry/node": "^9.16.1",
9288
"zod": "^3.24.3"
9389
}
9490
}

packages/mcp-server/src/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
44
import { startStdio } from "./transports/stdio";
5-
import { wrapMcpServerWithSentry } from "@sentry/core";
65
import * as Sentry from "@sentry/node";
76
import { LIB_VERSION } from "./version";
87

@@ -46,6 +45,11 @@ if (!accessToken) {
4645
Sentry.init({
4746
dsn: sentryDsn,
4847
sendDefaultPii: true,
48+
initialScope: {
49+
tags: {
50+
mcp_server_version: LIB_VERSION,
51+
},
52+
},
4953
environment:
5054
process.env.SENTRY_ENVIRONMENT ??
5155
(process.env.NODE_ENV !== "production" ? "development" : "production"),
@@ -56,7 +60,7 @@ const server = new McpServer({
5660
version: LIB_VERSION,
5761
});
5862

59-
const instrumentedServer = wrapMcpServerWithSentry(server);
63+
const instrumentedServer = Sentry.wrapMcpServerWithSentry(server);
6064

6165
const SENTRY_TIMEOUT = 5000; // 5 seconds
6266

0 commit comments

Comments
 (0)