Skip to content
Merged
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
1 change: 1 addition & 0 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ Environment variables for HTTP mode:
| `SOCKET_MCP_APPS_CHALLENGE_TOKEN` | For domain verification | None | Token the OpenAI plugin portal issues for domain verification. When set, `GET /.well-known/openai-apps-challenge` returns it as plain text; when unset, that path returns `404`. |
| `SOCKET_MCP_SENTRY_DSN` | No | None | Sentry DSN for error reporting; it must use HTTPS. When unset, reporting is off: the Sentry SDK is never loaded and nothing is sent. When set, HTTP mode sends scrubbed events for server-side failures. See [Error reporting](service.md#error-reporting). |
| `SOCKET_MCP_SENTRY_ENVIRONMENT` | No | `production` | Sentry `environment` reported events carry, such as `staging`. Read only when `SOCKET_MCP_SENTRY_DSN` is set. |
| `SOCKET_MCP_SENTRY_TRACES_SAMPLE_RATE` | No | `0` | Share of `tools/call` requests sent to Sentry as transactions, from 0 to 1. `0`, unset or out of range sends none. Read only when `SOCKET_MCP_SENTRY_DSN` is set. See [Tracing](service.md#tracing). |
| `TRUST_PROXY` | No | `false` | Trust `X-Forwarded-Host` and `X-Forwarded-Proto` when building OAuth metadata URLs. Enable only behind a reverse proxy that rewrites them. |

The three OAuth variables are a set: configure all three or none. Setting only some of them makes the server print `Incomplete OAuth configuration for HTTP mode` and exit `1`, rather than quietly start unauthenticated.
Expand Down
34 changes: 21 additions & 13 deletions docs/service.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,22 +249,30 @@ Invalid arguments, unknown tools, a caller's missing or rejected token, other up

Every event carries these tags:

| Tag | Values |
| -------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `mcp.tool` | A registered tool name, or `unknown` |
| `mcp.client` | The request's `clientInfo.name` (2026-07-28 requests), else the first product token of the `User-Agent`, else `unknown`. Lowercased and capped at 64 characters. |
| `mcp.client_version` | The matching version, when it looks like one and fits in 32 characters |
| `auth.outcome` | `anonymous`, `bearer_ok`, `bearer_denied`, `operator_denied` (the deployment's own token was rejected), or `unknown` for errors outside a tool call |
| `tool.outcome` | `failure` or `denied`, on tool-call events |
| `failure.cause` | `thrown`, `upstream_5xx`, `network`, `timeout`, `exception`, or `upstream_denied`, on tool-call events |
| `upstream.status` | The upstream HTTP status, when there was one |
| `error.code` | A Node error code such as `ECONNREFUSED`, when there was one |
| `error.source` | `mcp_handler`, `mcp_adapter`, `mcp_request`, `http_route`, `http_body`, or `oauth_verify`, on events outside a tool call |
| `transport` | `http` |
| Tag | Values |
| -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `mcp.tool` | A registered tool name, or `unknown` |
| `mcp.client` | The request's `clientInfo.name` (2026-07-28 requests), else the client family of the `User-Agent`'s first product token (such as `claude-code`, `cursor` or `curl`; `other` when not listed), else `unknown`. Lowercased and capped at 64 characters. |
| `mcp.client_version` | The matching version, when it looks like one and fits in 32 characters |
| `auth.outcome` | `anonymous`, `bearer_ok`, `bearer_denied`, `operator_denied` (the deployment's own token was rejected), or `unknown` for errors outside a tool call |
| `tool.outcome` | `failure` or `denied`, on tool-call events |
| `failure.cause` | `thrown`, `upstream_5xx`, `network`, `timeout`, `exception`, or `upstream_denied`, on tool-call events |
| `upstream.status` | The upstream HTTP status, when there was one |
| `error.code` | A Node error code such as `ECONNREFUSED`, when there was one |
| `error.source` | `mcp_handler`, `mcp_adapter`, `mcp_request`, `http_route`, `http_body`, or `oauth_verify`, on events outside a tool call |
| `transport` | `http` |

The event's `release` is the package version. Tool-call events are grouped by tool, outcome, auth outcome and failure cause, and other events by source and error type, never by message text.

Before an event leaves the process, it is rebuilt from an allowlist. The exception message is replaced with a summary built from the tags, such as `alerts upstream_5xx 502`, because upstream errors embed request URLs and response bodies. Stack frames keep only the function name, the file's basename, the line and the column. Events carry no tokens or token hashes, no request headers (including `Authorization`, `Cookie` and `Mcp-Session-Id`), no query strings, no tool arguments or results, no user data and no host name. Only errors are sent; there is no performance tracing.
Before an event leaves the process, it is rebuilt from an allowlist. The exception message is replaced with a summary built from the tags, such as `alerts upstream_5xx 502`, because upstream errors embed request URLs and response bodies. Stack frames keep only the function name, the file's basename, the line and the column. Events carry no tokens or token hashes, no request headers (including `Authorization`, `Cookie` and `Mcp-Session-Id`), no query strings, no tool arguments or results, no user data and no host name.

#### Tracing

Set the DSN and `SOCKET_MCP_SENTRY_TRACES_SAMPLE_RATE` to enable tracing. A rate of `0.1` samples 10% of tool calls. The default is `0` (off).

Each sampled call appears in Sentry’s MCP dashboard as `tools/call <tool>` (`mcp.server`, origin `auto.function.mcp_server`). It records the method, registered tool name (or `unknown`), transport, client name and optional version, and whether the call failed. Thrown errors and returned error results both set `error.type` to `tool_error` and the span status to `internal_error`.

Transactions omit child spans, tool arguments and results, request headers, user data, and tags.

On `SIGINT` or `SIGTERM`, the server waits up to two seconds for queued events, then exits. An unreachable Sentry never blocks or fails a request: each send gives up after five seconds.

Expand Down
9 changes: 7 additions & 2 deletions lib/cli.mts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
getSocketApiToken,
getSocketMcpSentryDsn,
getSocketMcpSentryEnvironment,
getSocketMcpSentryTracesSampleRate,
} from './env.mts'
import { startErrorReporting } from './error-reporting.mts'
import { getApiKeyInteractively } from './http.mts'
Expand Down Expand Up @@ -52,10 +53,12 @@ export interface SocketMcpCliDeps {
readonly resolveLocalOAuthSession?: () => Promise<
LocalOAuthSession | undefined
>
// SOCKET_MCP_SENTRY_DSN and SOCKET_MCP_SENTRY_ENVIRONMENT. HTTP mode turns
// error reporting on only when the DSN is set; stdio mode ignores both.
// SOCKET_MCP_SENTRY_DSN, SOCKET_MCP_SENTRY_ENVIRONMENT and
// SOCKET_MCP_SENTRY_TRACES_SAMPLE_RATE. HTTP mode turns error reporting on
// only when the DSN is set; stdio mode ignores all three.
readonly sentryDsn: string | undefined
readonly sentryEnvironment: string | undefined
readonly sentryTracesSampleRate: number
readonly serveStdio: typeof serveStdio
readonly setOauthEnabled: () => { issuer: string } | undefined
readonly setStaticApiKey: typeof setStaticApiKey
Expand All @@ -82,6 +85,7 @@ export function createSocketMcpCliDeps(): SocketMcpCliDeps {
resolveLocalOAuthSession,
sentryDsn: getSocketMcpSentryDsn(),
sentryEnvironment: getSocketMcpSentryEnvironment(),
sentryTracesSampleRate: getSocketMcpSentryTracesSampleRate(),
serveStdio,
setOauthEnabled,
setStaticApiKey,
Expand Down Expand Up @@ -208,6 +212,7 @@ export async function runSocketMcpCli(deps: SocketMcpCliDeps): Promise<number> {
dsn: deps.sentryDsn,
environment: deps.sentryEnvironment,
mode: 'http',
tracesSampleRate: deps.sentryTracesSampleRate,
})
}
deps.startHttpServer(deps.port)
Expand Down
7 changes: 7 additions & 0 deletions lib/env.mts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@ export function getSocketMcpSentryEnvironment(): string | undefined {
return envString('SOCKET_MCP_SENTRY_ENVIRONMENT')
}

// The share of `tools/call` requests traced to Sentry, from 0 to 1. Unset or
// out of range is 0, which sends no transactions.
export function getSocketMcpSentryTracesSampleRate(): number {
const rate = Number(envString('SOCKET_MCP_SENTRY_TRACES_SAMPLE_RATE'))
return rate >= 0 && rate <= 1 ? rate : 0
}

// OAuth getters — not yet in the canonical lib surface. These read
// the same env vars that the future lib getters will read. Once
// lib ships them, this file's OAuth section can be replaced with
Expand Down
Loading
Loading