Repository navigation
feat(http): add opt-in Sentry error reporting - #243
Conversation
Tool results already carry a denied or invalid mark for the audit outcome. Record the failure cause beside it (upstream 4xx or 5xx, a denial, a network error, a timeout, or another exception) together with the error the tool caught, so a later consumer can tell a server-side failure from the caller's mistake without reading message text. depscore now marks its connection, status and parse failures the same way the other tools do, and the blob and file-list fetches keep the original request error as `cause`, so its code survives the rewrap.
HTTP mode can now report server-side failures to Sentry. It is off unless SOCKET_MCP_SENTRY_DSN is set; SOCKET_MCP_SENTRY_ENVIRONMENT names the environment. stdio mode never reports, even with the DSN set, and without the DSN the Sentry SDK is never loaded. The client is built from @sentry/core alone, with a small fetch transport: no OpenTelemetry, no module patching, no tracing. It is loaded by a dynamic import only when reporting is on, which the bundle keeps behind a lazy initializer. Events cover a tool handler throwing, upstream 5xx, network, timeout and other unexpected failures behind a tool, a rejected deploy token on an anonymous call, and serving, routing, body-read and token-verification failures. Invalid input, unknown tools, a caller's denied token, upstream 4xx answers, client rejections and client disconnects leave a breadcrumb instead. Each event carries bounded tags (mcp.tool, mcp.client and its version, auth.outcome, tool.outcome, failure.cause, upstream.status, error.code, error.source, transport) and the package version as its release. It is grouped by tool, outcome, auth outcome and cause rather than message text. beforeSend rebuilds every event from an allowlist: messages become a summary built from the tags, stack frames keep only function, file basename and position, and request data, headers, tokens, arguments, query strings, users and the host name are dropped. SIGINT and SIGTERM wait up to two seconds for queued events before exiting.
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
PR SummaryMedium Risk Overview Reporting is wired through new Tool upstream handling is extended so failures carry classified causes ( Reviewed by Cursor Bugbot for commit 9389357. Configure here. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 9389357. Configure here.
John-David Dalton (jdalton)
left a comment
There was a problem hiding this comment.
One transport implementation detail to adjust.
John-David Dalton (jdalton)
left a comment
There was a problem hiding this comment.
fetch use switcheroo, 🙏
When every NDJSON line from the depscore endpoint fails to parse, the tool returned an unmarked error result, so error reporting treated it as a caller-side outcome and sent nothing. Mark that case as a failure the server could not handle. A body made only of control frames (every purl unresolved) stays unmarked: that is the caller's outcome.
Use the shared httpRequest helper from @socketsecurity/lib, which uses Node's own HTTP and HTTPS modules, instead of the global fetch. Send each envelope once, with no redirects and a five-second timeout. Require an HTTPS DSN. Cleartext HTTP is accepted only for a loopback host, for local test recorders. The loopback check moves from the browser sign-in module into lib/http.mts so both share it.
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|

HTTP mode can now report server-side failures to Sentry. It is off unless
SOCKET_MCP_SENTRY_DSNis set, and stdio mode never reports, even with the DSN set. Without the DSN the Sentry SDK is never evaluated and nothing is sent, so local and Claude Desktop users see no change.What changed
SOCKET_MCP_SENTRY_DSNturns reporting on in HTTP mode.SOCKET_MCP_SENTRY_ENVIRONMENTnames the environment; Sentry's default isproduction. Both are in the HTTP env table indocs/commands.md(which the README links to), in a newdocs/service.md#error-reportingsection and in a short README section.@sentry/core11.13.0 with a small transport on the repo's sharedhttpRequesthelper (Node's own HTTP and HTTPS modules): no OpenTelemetry, no module patching, no tracing. The DSN must use HTTPS; cleartext HTTP is accepted only for a loopback recorder. It's loaded by a dynamic import only when reporting starts, and rolldown keeps it behind a lazy initializer indist/index.cjs. The package still has no runtime dependencies.onerror, routing, body reads and OAuth token verification.mcp.tool,mcp.client,mcp.client_version,auth.outcome,tool.outcome,failure.cause,upstream.status,error.code,error.sourceandtransport, all from bounded vocabularies;releaseis the package version. Tool-call events are grouped by tool, outcome, auth outcome and cause, and server errors by source and error type, never by message text.beforeSendrebuilds every event from an allowlist. The exception message becomes a summary built from the tags, because upstream errors embed request URLs and bodies. Stack frames keep the function, file basename, line and column. Tokens, the audit token hash, request headers (Authorization,Cookie,Mcp-Session-Id), query strings, tool arguments and results, users and the host name are dropped. Sentry v11 removedsendDefaultPii; its replacement,dataCollection, is switched fully off. A malformed DSN, or one using HTTP off loopback, is rejected before the SDK sees it, because the SDK would print it.markUpstreamHttpOutcomenow records why an upstream call failed next to the existing denied mark.depscoremarks its connection, status and parse failures the same way (an NDJSON body with no parseable lines counts; one of onlypurlError/summaryframes, meaning every purl was unresolved, does not), and the blob and file-list fetches keep the original error ascause. Audit outcomes are unchanged.Client identity
2026-07-28 requests carry
clientInfoin the per-request_metaenvelope (ctx.mcpReq.envelope), somcp.clientusesclientInfo.name. 2025-era clients on the stateless legacy leg sendclientInfoonly oninitialize, which is its own exchange, so the per-requestServernever sees it. Those calls fall back to the User-Agent's first product token, elseunknown.Reviewer heads-up
operator_denied, where an anonymous call's fallback to the deploy's own token is rejected. That is the deploy's credential failing, not the caller's.onerroralso receives client rejections. They are matched by error class and by message prefix (Rejected …,Unsupported Media Type), which an SDK upgrade could change.SOCKET_MCP_SENTRY_DSNfor this package after a release.Cost
maindist/index.cjsdist/index.cjs,gzip -9socket-mcp --help.mcpbbundleStartup figures are medians of 60 interleaved runs on one machine (Node 26.12.1), measured before the review changes; the bundle sizes are re-measured after them. The slides below predate the review changes, so they still show the
fetchtransport and the earlier byte counts. For the SDK choice, each candidate was bundled alone with the repo's rolldown and timed for load and init over barenode:@sentry/corewith afetchtransport (since replaced byhttpRequest, which the bundle already includes) is 194 KB and +3.2 ms;@sentry/nodeis 1.35 MB and +16.9 ms without default integrations, +32.9 ms with them;@sentry/node-core10.x is 943 KB and fails to load without its OpenTelemetry peers.Testing
pnpm test: 74 files, 684 tests pass, 30 of them new. Unit tests cover the off path (no DSN, or stdio, never loads the Sentry module or sends a request), tag derivation, the event-or-breadcrumb decision and the allowlist sanitizer. Integration tests drive the real HTTP stack wired asstartHttpServerwires it, with nock for the Socket API and a recording transport. Each event class sends exactly one event with the expected tags; invalid, unknown, denied and 4xx calls send none; no token, token hash, org slug, cursor, cookie, upstream body, query key or home path reaches the envelope; an unreachable DSN leaves tool calls working.pnpm run test:e2e: 3 files, 19 tests pass, 3 of them new. The built bin in HTTP mode, with the DSN pointed at a local recorder andSOCKET_API_BASE_URLat a local server that answers 500, sends one scrubbed event and exits promptly on SIGTERM. Without a DSN, or in stdio mode with one, it sends nothing.pnpm run fmt,pnpm run lint,pnpm run repo:checkandpnpm run checkpass.mcpb validateandmcpb packpass.build-mcpb'snpm install --productionstep, which needs npm 12.2 or later and fails the same way onmainlocally with npm 11.20; a live OAuth issuer outage, which is exercised through a direct call; flushing an in-flight event on SIGTERM.Sample event from the built bin (local recorder, synthetic values)
{ "contexts": { "runtime": { "name": "node", "version": "v26.12.1" } }, "exception": { "values": [ { "type": "UpstreamHttpError", "value": "alerts upstream_5xx 502", "mechanism": { "type": "socket-mcp", "handled": true }, "stacktrace": { "frames": [ { "function": "Object.handler", "filename": "index.cjs", "lineno": 43717, "colno": 18, "in_app": true }, { "function": "process.processTicksAndRejections", "filename": "node:internal/process/task_queues", "lineno": 104, "colno": 5, "in_app": false }, { "function": "fetchAlerts", "filename": "index.cjs", "lineno": 42030, "colno": 21, "in_app": true } ] } } ] }, "tags": { "auth.outcome": "bearer_ok", "mcp.client": "example-client", "mcp.client_version": "1.4.0", "mcp.tool": "alerts", "tool.outcome": "failure", "transport": "http", "failure.cause": "upstream_5xx", "upstream.status": "502" }, "event_id": "7d5448859dab4b3fb9e73255437a0d8a", "timestamp": 1795543726.195, "level": "error", "platform": "node", "release": "0.4.0", "environment": "example", "fingerprint": [ "socket-mcp", "tool", "alerts", "failure", "bearer_ok", "upstream_5xx" ] }Slides
🤖 Generated with Claude Code