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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,10 @@ The stdio server uses the saved browser OAuth session. A `SOCKET_API_TOKEN` envi

Audit-event destinations and record behavior are documented in the [service reference](docs/service.md#audit-events).

### Error reporting

HTTP mode can report server-side failures to Sentry. It is off unless `SOCKET_MCP_SENTRY_DSN` is set, and `SOCKET_MCP_SENTRY_ENVIRONMENT` names the environment. stdio mode never reports. What is sent, and what is scrubbed, is documented in the [service reference](docs/service.md#error-reporting).

### Health check endpoint

The HTTP health response is documented in the [service reference](docs/service.md#health-check-endpoint).
Expand Down
30 changes: 16 additions & 14 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,22 @@ The transport is stateless. Each `POST /` is self-contained, with no session to

Environment variables for HTTP mode:

| Variable | Required | Default | Description |
| ------------------------------------------ | ----------------------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `MCP_HTTP_MODE` | Yes, unless you pass `--http` | `false` | Set to `true` to serve HTTP instead of stdio. The `--http` CLI flag does the same thing. |
| `MCP_PORT` | No | `3000` | Port to bind the HTTP server to. |
| `SOCKET_API_TOKEN` | Optional | None | API token for outbound API calls. Use it only as a fallback for local stdio. `socket-mcp login` is the recommended local sign-in. HTTP OAuth does not need a startup token. See the alias list below. |
| `SOCKET_OAUTH_ISSUER` | With OAuth | None | OAuth issuer URL. Must be `https` on a public host. See "Enabling OAuth" below. |
| `SOCKET_OAUTH_INTROSPECTION_CLIENT_ID` | With OAuth | None | Client ID used for RFC 7662 token introspection. |
| `SOCKET_OAUTH_INTROSPECTION_CLIENT_SECRET` | With OAuth | None | Client secret used for RFC 7662 token introspection. |
| `SOCKET_OAUTH_REQUIRED_SCOPES` | No | None | Scopes required on incoming access tokens, separated by spaces or commas. When unset, any active token passes. |
| `SOCKET_API_BASE_URL` | No | None | Override the upstream Socket API endpoint. Falls back to `https://api.socket.dev` when unset. |
| `SOCKET_MCP_OAUTH_BASE_URL` | No | API URL | Override the issuer used by local stdio OAuth. By default, OAuth follows `SOCKET_API_BASE_URL`; an `api.` hostname maps to its matching `mcp.` resource host. Non-loopback URLs must use HTTPS. |
| `SOCKET_DEBUG` | No | `false` | Turns on verbose request and cache tracing on stderr, points `depscore` at `http://localhost:8866`, and permits a local OAuth issuer. |
| `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`. |
| `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. |
| Variable | Required | Default | Description |
| ------------------------------------------ | ----------------------------- | ------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `MCP_HTTP_MODE` | Yes, unless you pass `--http` | `false` | Set to `true` to serve HTTP instead of stdio. The `--http` CLI flag does the same thing. |
| `MCP_PORT` | No | `3000` | Port to bind the HTTP server to. |
| `SOCKET_API_TOKEN` | Optional | None | API token for outbound API calls. Use it only as a fallback for local stdio. `socket-mcp login` is the recommended local sign-in. HTTP OAuth does not need a startup token. See the alias list below. |
| `SOCKET_OAUTH_ISSUER` | With OAuth | None | OAuth issuer URL. Must be `https` on a public host. See "Enabling OAuth" below. |
| `SOCKET_OAUTH_INTROSPECTION_CLIENT_ID` | With OAuth | None | Client ID used for RFC 7662 token introspection. |
| `SOCKET_OAUTH_INTROSPECTION_CLIENT_SECRET` | With OAuth | None | Client secret used for RFC 7662 token introspection. |
| `SOCKET_OAUTH_REQUIRED_SCOPES` | No | None | Scopes required on incoming access tokens, separated by spaces or commas. When unset, any active token passes. |
| `SOCKET_API_BASE_URL` | No | None | Override the upstream Socket API endpoint. Falls back to `https://api.socket.dev` when unset. |
| `SOCKET_MCP_OAUTH_BASE_URL` | No | API URL | Override the issuer used by local stdio OAuth. By default, OAuth follows `SOCKET_API_BASE_URL`; an `api.` hostname maps to its matching `mcp.` resource host. Non-loopback URLs must use HTTPS. |
| `SOCKET_DEBUG` | No | `false` | Turns on verbose request and cache tracing on stderr, points `depscore` at `http://localhost:8866`, and permits a local OAuth issuer. |
| `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. |
| `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: 34 additions & 0 deletions docs/service.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,40 @@ Tool results use text content. `organizations`, `alerts`, and `threat_feed` seri

Each tool call produces a bounded, versioned audit event. By default, the server appends JSONL records to `~/.socket/mcp-audit.jsonl`. Set `SOCKET_MCP_AUDIT_LOG` to choose another file or `SOCKET_MCP_AUDIT_SINK=stderr` to write records to stderr. The default sink is JSONL. Unknown sink values produce a diagnostic and fall back to JSONL. Existing records are left in place.

### Error reporting

Error reporting is off by default. Set `SOCKET_MCP_SENTRY_DSN` in HTTP mode to send errors to Sentry, and `SOCKET_MCP_SENTRY_ENVIRONMENT` to name the environment (Sentry's default is `production`). Without the DSN, the Sentry SDK is never loaded and nothing is sent. stdio mode never reports, even when the DSN is set. The DSN must use HTTPS; cleartext HTTP is accepted only for a loopback host, for local testing. A DSN that does not parse, or uses HTTP elsewhere, logs one line, and the server starts without reporting.

Events are sent only for failures on the server's side:

- A tool handler throws.
- A tool call fails because the Socket API answered with a 5xx, the connection failed, the request timed out, or the response could not be handled.
- An anonymous call falls back to the deployment's `SOCKET_API_TOKEN`, and the Socket API rejects that token with 401 or 403.
- The MCP handler or the Node adapter reports a serving failure, request routing or body reading throws, or OAuth token verification throws.

Invalid arguments, unknown tools, a caller's missing or rejected token, other upstream 4xx answers, and clients that disconnect are the caller's doing. They send no event; each adds a breadcrumb to the next one.

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` |

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.

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.

### Health check endpoint

In HTTP mode, `GET /health` returns a JSON object with `status`, `service`, `version`, and `timestamp`. The endpoint skips origin validation so a health probe can omit `Origin`.
Expand Down
4 changes: 3 additions & 1 deletion lib/blob.mts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,9 @@ export async function fetchRawBytes(
try {
res = await httpRequest(url, { headers })
} catch (e) {
throw new Error(`blob request to ${url} failed: ${errorMessage(e)}`)
throw new Error(`blob request to ${url} failed: ${errorMessage(e)}`, {
cause: e,
})
}
if (!res.ok) {
throw new UpstreamHttpError(
Expand Down
26 changes: 25 additions & 1 deletion lib/cli.mts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ import { serveStdio } from '@modelcontextprotocol/server/stdio'

import { errorMessage } from '@socketsecurity/lib/errors/message'

import { getMcpHttpMode, getMcpPort, getSocketApiToken } from './env.mts'
import {
getMcpHttpMode,
getMcpPort,
getSocketApiToken,
getSocketMcpSentryDsn,
getSocketMcpSentryEnvironment,
} from './env.mts'
import { startErrorReporting } from './error-reporting.mts'
import { getApiKeyInteractively } from './http.mts'
import { startHttpServer } from './http-server.mts'
import { logger } from './logger.mts'
Expand Down Expand Up @@ -45,9 +52,14 @@ 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.
readonly sentryDsn: string | undefined
readonly sentryEnvironment: string | undefined
readonly serveStdio: typeof serveStdio
readonly setOauthEnabled: () => { issuer: string } | undefined
readonly setStaticApiKey: typeof setStaticApiKey
readonly startErrorReporting: typeof startErrorReporting
readonly startHttpServer: typeof startHttpServer
}

Expand All @@ -68,9 +80,12 @@ export function createSocketMcpCliDeps(): SocketMcpCliDeps {
promptForApiKey: getApiKeyInteractively,
refreshLocalOAuthSession,
resolveLocalOAuthSession,
sentryDsn: getSocketMcpSentryDsn(),
sentryEnvironment: getSocketMcpSentryEnvironment(),
serveStdio,
setOauthEnabled,
setStaticApiKey,
startErrorReporting,
startHttpServer,
}
}
Expand Down Expand Up @@ -186,6 +201,15 @@ export async function runSocketMcpCli(deps: SocketMcpCliDeps): Promise<number> {
}

if (useHttp) {
// Opt-in and HTTP-only: without a DSN nothing is loaded. A DSN that fails
// to start reporting is logged and the server starts anyway.
if (deps.sentryDsn) {
await deps.startErrorReporting({
dsn: deps.sentryDsn,
environment: deps.sentryEnvironment,
mode: 'http',
})
}
deps.startHttpServer(deps.port)
return 0
}
Expand Down
12 changes: 12 additions & 0 deletions lib/env.mts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,18 @@ export function getSocketMcpAuditSink(): 'jsonl' | 'stderr' | 'unknown' {
return sink === 'stderr' ? 'stderr' : 'unknown'
}

// The Sentry DSN for HTTP-mode error reporting. Unset by default, which keeps
// reporting off: the Sentry SDK is never loaded and nothing leaves the
// process. stdio mode ignores it.
export function getSocketMcpSentryDsn(): string | undefined {
return envString('SOCKET_MCP_SENTRY_DSN')
}

// The Sentry `environment` reported events carry, e.g. `production`.
export function getSocketMcpSentryEnvironment(): string | undefined {
return envString('SOCKET_MCP_SENTRY_ENVIRONMENT')
}

// 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