Skip to content

feat(observability): structured pino logger for stdio MCP servers - #185

Merged
chrisleekr merged 1 commit into
mainfrom
fix/issue-172
May 29, 2026
Merged

feat(observability): structured pino logger for stdio MCP servers#185
chrisleekr merged 1 commit into
mainfrom
fix/issue-172

Conversation

@chrisleekr

Copy link
Copy Markdown
Owner

What

Resolves #172. Five stdio MCP servers logged via raw console.error — no structure, no deliveryId correlation, no secret redaction. A console.error(err) on an Octokit RequestError (github-state.ts, merge-readiness.ts) could dump a ghs_… token verbatim. Only resolve-review-thread used pino, via an inline instance.

Changes

  • Extracted the redaction primitives (REDACT_PATHS, errSerializer, scrubStructured, scrubString, scrubRequest, scrubResponse, ...) verbatim from src/logger.ts into a new config-free src/utils/log-redaction.ts. logger.ts imports + re-exports REDACT_PATHS/errSerializer (back-compat). This split is load-bearing: MCP subprocesses can't import logger.ts (it reads config at module load), so parity needs a config-free source.
  • src/mcp/mcp-logger.ts createMcpLogger(serverName): a stderr pino logger applying the same REDACT_PATHS + errSerializer, binding server + inherited deliveryId.
  • Converted all 6 servers to createMcpLogger. secret_redacted JSON blobs → structured log.warn events; raw console.error(err) → redacted log.error({ err }).
  • registry.ts: DELIVERY_ID moved into sharedEnv so every server inherits it (dropped the redundant commentServerDef param).
  • executor.ts: LOG_LEVEL added to the subprocess env allowlist so LOG_LEVEL=debug propagates to the CLI + MCP subprocesses.
  • Tests (test/mcp/mcp-logger.test.ts: bindings + redaction parity + runtime stderr-vs-stdout; resolve-review-thread.test.ts retargeted to the shared helper). Docs: observability.md MCP-server section + CLAUDE.md redaction note.

Judgement calls

Verification

typecheck / eslint (0 errors) / prettier / em-dash / docs-citations clean. bun run build + check:mcp-bundle green (7 servers resolve, no config leak, redaction inlined). Tests: logger (16) + mcp (38) pass. Broad regression (mcp+core+utils+webhook) vs clean main: identical pre-existing failures, +5 passing, zero new failures. Senior-review gate: 3 independent passes, converged clean (extraction confirmed byte-identical; the two critical pino contracts verified). CodeRabbit unavailable this run (org out of credits).

🤖 Generated with Claude Code

Five of the stdio MCP servers logged via raw console.error (no structure, no
deliveryId correlation, no secret redaction); a console.error(err) on an
Octokit RequestError could dump a ghs_ token verbatim. Only resolve-review-thread
used pino, and via an inline instance.

- Extract the redaction primitives (REDACT_PATHS, errSerializer, scrubStructured,
  ...) verbatim from src/logger.ts into a new config-free src/utils/log-redaction.ts.
  logger.ts imports + re-exports REDACT_PATHS/errSerializer (back-compat). The
  config-free split is load-bearing: MCP subprocesses can't import logger.ts
  (it reads config at module load).
- Add src/mcp/mcp-logger.ts createMcpLogger(serverName): a stderr pino logger
  with the same REDACT_PATHS + errSerializer, binding server + inherited
  deliveryId. Redaction parity without pulling in config.
- Convert all 6 servers (comment, inline-comment, github-state, repo-memory,
  merge-readiness, resolve-review-thread) to createMcpLogger; secret_redacted
  blobs become structured log.warn events; raw console.error(err) becomes a
  redacted log.error({ err }).
- registry.ts: DELIVERY_ID moved into sharedEnv so every server inherits it.
- executor.ts: LOG_LEVEL added to the subprocess env allowlist so
  LOG_LEVEL=debug propagates to the CLI + MCP subprocesses.
- Tests (mcp-logger bindings/redaction/stderr; resolve-review-thread retargeted)
  + docs (observability.md MCP section, CLAUDE.md note).

Volume reuses LOG_LEVEL, no new env. Pre-existing resolve-review-thread config
coupling via retry.ts is tracked as follow-up #184.

Closes #172

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 29, 2026 14:18
@coderabbitai

coderabbitai Bot commented May 29, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@chrisleekr, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 32 minutes and 51 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: f82082cd-fcd0-44a0-a7d4-5538b2f9583d

📥 Commits

Reviewing files that changed from the base of the PR and between 30e1715 and c9346f0.

📒 Files selected for processing (15)
  • CLAUDE.md
  • docs/operate/observability.md
  • src/core/executor.ts
  • src/logger.ts
  • src/mcp/mcp-logger.ts
  • src/mcp/registry.ts
  • src/mcp/servers/comment.ts
  • src/mcp/servers/github-state.ts
  • src/mcp/servers/inline-comment.ts
  • src/mcp/servers/merge-readiness.ts
  • src/mcp/servers/repo-memory.ts
  • src/mcp/servers/resolve-review-thread.ts
  • src/utils/log-redaction.ts
  • test/mcp/mcp-logger.test.ts
  • test/mcp/resolve-review-thread.test.ts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors stdio MCP servers from raw console.error to a shared structured pino logger (createMcpLogger) that writes to stderr and applies the same REDACT_PATHS + errSerializer scrubbing as the main daemon logger. The redaction primitives are extracted verbatim from src/logger.ts into a new config-free src/utils/log-redaction.ts so MCP subprocesses can import them without pulling in config validation. DELIVERY_ID is moved into sharedEnv so every server inherits it for log correlation, and LOG_LEVEL is added to the executor env allowlist so verbosity propagates through the CLI to MCP subprocesses.

Changes:

  • New src/utils/log-redaction.ts (extracted) and src/mcp/mcp-logger.ts helper; src/logger.ts re-exports for back-compat.
  • All 6 stdio MCP servers converted to createMcpLogger; raw console.error(err) → redacted log.error({ err }); ad-hoc JSON.stringify({...}) → structured log.warn.
  • Registry promotes DELIVERY_ID into sharedEnv; executor allowlists LOG_LEVEL; new tests for logger bindings, redaction parity, stderr-only output, and resolve-review-thread shared-helper contract; docs updated.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/utils/log-redaction.ts New config-free module holding REDACT_PATHS, errSerializer, and scrubbers extracted from logger.ts.
src/logger.ts Drops inlined redaction code and re-exports errSerializer/REDACT_PATHS from the new module for back-compat.
src/mcp/mcp-logger.ts New createMcpLogger(serverName) helper: stderr pino with shared redaction and server/deliveryId bindings.
src/mcp/servers/comment.ts Switches to createMcpLogger, structured secret_redacted event, process.exit(1) on runServer failure.
src/mcp/servers/inline-comment.ts Same conversion; structured redaction event includes pull_number/path; catch now exits non-zero.
src/mcp/servers/github-state.ts Routes raw err through redacting logger to avoid leaking Octokit auth headers.
src/mcp/servers/merge-readiness.ts Same redacted-error logging change.
src/mcp/servers/repo-memory.ts Replaces fail-fast console.error with structured log.error.
src/mcp/servers/resolve-review-thread.ts Drops inline pino(...) instance in favor of shared createMcpLogger.
src/mcp/registry.ts Moves DELIVERY_ID into sharedEnv; simplifies commentServerDef signature.
src/core/executor.ts Adds LOG_LEVEL to env allowlist so verbosity propagates to CLI + MCP subprocesses.
test/mcp/mcp-logger.test.ts New tests: bindings, redaction parity (err.message, installationToken), and stderr-only runtime check.
test/mcp/resolve-review-thread.test.ts Retargets static contract to assert use of shared createMcpLogger and absence of direct pino(.
docs/operate/observability.md Documents the MCP-server log fields, stderr contract, and LOG_LEVEL propagation.
CLAUDE.md Updates the secret-handling invariant note to reference createMcpLogger + log-redaction.ts.

@chrisleekr
chrisleekr merged commit 5244e8a into main May 29, 2026
23 checks passed
@chrisleekr
chrisleekr deleted the fix/issue-172 branch May 29, 2026 14:39
chrisleekr pushed a commit that referenced this pull request Jun 30, 2026
# [1.14.0](v1.13.0...v1.14.0) (2026-06-30)

### Bug Fixes

* **agent-sdk:** pass settingSources [] so SDK ignores cloned PR .claude/settings.json ([#195](#195)) ([153fef3](153fef3))
* **check:** derive scoped-executor scan set from filesystem (dead guard) ([#208](#208)) ([8b0e8ef](8b0e8ef))
* **daemon:** sweep full workspace triple on startup and crash exit ([#239](#239)) ([56fa714](56fa714))
* **idempotency:** gate side-effecting handlers with Valkey claim to prevent redelivery duplicates ([#212](#212)) ([68dacdb](68dacdb))
* **infrastructure:** patch krb5 HIGH CVE-2026-40356 in shared Docker base ([#180](#180)) ([1d1bc3b](1d1bc3b))
* **mcp:** redact Octokit error tool-results and widen GitHub token regex ([#238](#238)) ([675d610](675d610))
* **mcp:** wrap GitHub-touching MCP servers + state-fetchers in retryWithBackoff ([#205](#205)) ([319beb9](319beb9))
* **observability:** canonicalise child-logger entity id under entityNumber ([#178](#178)) ([808ca46](808ca46))
* **security:** gate LLM scanner redacted_body to deletion-only ([#206](#206)) ([d52cf78](d52cf78))
* **security:** set strictMcpConfig to block cloned-PR .mcp.json auto-load ([#210](#210)) ([2c58ec1](2c58ec1))
* **testing:** run colocated src/**/*.test.ts in CI + add drift guard ([#204](#204)) ([5990e0d](5990e0d))

### Features

* **agent-sdk:** block destructive Bash at runtime via PreToolUse hook ([#241](#241)) ([f3132f2](f3132f2))
* **observability:** add 12 structured Pino event families with Zod-strict schemas ([#251](#251)) ([eaad36b](eaad36b))
* **observability:** add queue_wait_ms to dispatcher offer/no-daemon logs ([#207](#207)) ([7a5cfb0](7a5cfb0))
* **observability:** add structured retry.* events ([#225](#225)) ([6713cbf](6713cbf))
* **observability:** emit failed_stage and failed_stage_delta_ms on pipeline.failed ([#244](#244)) ([4f2483c](4f2483c))
* **observability:** emit structured idempotency events on all 4 claimDelivery outcomes ([#242](#242)) ([e1e7f9e](e1e7f9e))
* **observability:** installationId on loggers + config-free MCP retry ([#189](#189)) ([ba09f76](ba09f76)), closes [#177](#177) [#184](#184)
* **observability:** log + persist SDK token usage on executions ([#209](#209)) ([5407dcd](5407dcd))
* **observability:** log octokit rate-limit headers via hook.after ([#183](#183)) ([30e1715](30e1715))
* **observability:** periodic fleet-state gauge snapshot ([#186](#186)) ([7429460](7429460))
* **observability:** redact crash logs via uncaughtException/unhandledRejection handlers ([#181](#181)) ([d4248f4](d4248f4))
* **observability:** structured dispatcher + heartbeat log events ([#188](#188)) ([c615bc4](c615bc4))
* **observability:** structured pino logger for stdio MCP servers ([#185](#185)) ([5244e8a](5244e8a))
* **observability:** structured pipeline.stage timing events with delta_ms ([#182](#182)) ([4125971](4125971))
@chrisleekr

Copy link
Copy Markdown
Owner Author

🎉 This PR is included in version 1.14.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(observability): structured pino logger for stdio MCP servers w/ deliveryId correlation + err redaction parity

2 participants