Skip to content

fix(logging): never write logs to stdout in stdio mode - #571

Merged
polaz merged 8 commits into
mainfrom
fix/#563-stdio-log-destination
Aug 8, 2026
Merged

fix(logging): never write logs to stdout in stdio mode#571
polaz merged 8 commits into
mainfrom
fix/#563-stdio-log-destination

Conversation

@polaz

@polaz polaz commented Aug 8, 2026

Copy link
Copy Markdown
Member

Summary

Logging fix (closes #563)

  • LOG_JSON=true previously created a bare pino instance writing NDJSON to stdout, which corrupts the MCP JSON-RPC channel in stdio transport mode. Logs are now forced to stderr whenever the server runs on stdio, for both plain and JSON formats.
  • New LOG_DESTINATION=stdout|stderr override for HTTP mode. Defaults keep the container convention: pretty to stderr, NDJSON to stdout. In stdio mode the override is ignored with a warning.
  • Fixed LOG_FORMAT rendering: the messageFormat template crossed the worker-thread transport boundary, so the standard prefix was rendered twice and {levelLabel} printed as undefined. Format tokens now drive field visibility via the ignore list only.
  • Documented LOG_FORMAT (visibility switches, fixed line order), LOG_DESTINATION, and a transport/destination matrix in the configuration guide; added a troubleshooting entry for the "Failed to parse JSONRPC message" startup spam (outdated build from a stale npx cache).

Note for #563 context: the default (plain) mode already wrote to stderr since the pino migration; the reporter's colored multi-line output on stdout matches a pre-9.x release (stale npx cache). The remaining real leak was the LOG_JSON path fixed here.

Dependency updates (supersedes all open Dependabot PRs)

  • @cloudflare/workers-types 4 -> 5 (major), vitepress alpha.19, undici 8.10, MCP SDK 1.30, eslint/prettier/ts-eslint/ts-jest/graphql/picomatch/xstate/clack minor+patch, prisma 7.9.1, nx 23.1.1
  • Lockfile transitive bumps: hono 4.13.1, postcss 8.5.26, ip-address 10.4.0, brace-expansion 1.1.18, js-yaml 3.15.1, fast-uri 3.1.5, tar 7.5.22, body-parser 2.3.0
  • GitHub Actions: setup-node v7, codeql-action pinned to v4.37.4
  • Skipped: typescript 7 and @types/node 26 majors (@types/node major is Dependabot-ignored; native tsc migration is a separate effort)
  • Repo reformatted for prettier 3.9 union-type style

Test fix

  • runners integration schema test still passed statuses as a bare string after c1b37f9 switched the filter to an array; updated to match the schema.

Testing

  • End-to-end log destination matrix (stdio/HTTP x pretty/JSON/full-format/debug/error paths): stdout contains only JSON-RPC frames in every stdio case; Docker HTTP behavior unchanged.
  • Full suite on the updated toolchain: 5656/5656 (202 suites) including integration against a live GitLab instance, plus 9/9 in gitlab-mcp-db. Build and lint clean.

Closes #563

Summary by CodeRabbit

  • New Features

    • Improved logging behavior across stdio and HTTP modes, including configurable output destinations and clearer JSON or pretty-formatted logs.
    • Added warnings when unsupported log destination settings are used in stdio mode.
  • Documentation

    • Expanded configuration guidance for log formats, destinations, defaults, and stream behavior.
  • Tests

    • Added coverage for logging destinations, formatting options, and multi-status job validation.
  • Maintenance

    • Updated development tooling and automated workflow components for improved reliability.

polaz added 5 commits August 8, 2026 21:04
- LOG_JSON=true previously created a bare pino instance that wrote
  NDJSON log lines to stdout, corrupting the MCP JSON-RPC channel in
  stdio transport mode; logs are now forced to stderr whenever the
  server runs on stdio, for both plain and JSON formats
- add LOG_DESTINATION=stdout|stderr override for HTTP mode; defaults
  keep the container convention (pretty to stderr, NDJSON to stdout)
- fix LOG_FORMAT rendering: messageFormat crossed the worker-thread
  transport boundary, duplicating the prefix and printing 'undefined'
  for the level; format tokens now drive field visibility via ignore
  list only
- document LOG_FORMAT and LOG_DESTINATION plus a destination matrix
  in the configuration guide

Closes #563
Applies every pending Dependabot update in one pass:

- @cloudflare/workers-types 4.20260623.1 -> 5.20260808.1 (major)
- vitepress 2.0.0-alpha.17 -> 2.0.0-alpha.19
- undici ^8.5.0 -> ^8.10.0
- @modelcontextprotocol/sdk, @clack/prompts, eslint, prettier,
  @typescript-eslint/*, ts-jest, graphql, picomatch, xstate minor/patch
- prisma + @prisma/client 7.8.0 -> 7.9.1
- nx 23.0.0 -> 23.1.1
- lockfile-only transitive bumps: hono 4.13.1, postcss 8.5.26,
  ip-address 10.4.0, brace-expansion 1.1.18, js-yaml 3.15.1,
  fast-uri 3.1.5, tar 7.5.22, body-parser 2.3.0

typescript 7 and @types/node 26 majors are intentionally skipped:
@types/node major is on the Dependabot ignore list and the native
tsc migration is a separate effort.

Supersedes Dependabot PRs #543, #544, #545, #546, #551, #556, #557,
#559, #560, #561, #566, #568, #569, #570
The list_jobs statuses filter became an array of CiJobStatus in
c1b37f9, but the integration schema test still passed a bare string
and failed against the current schema.
prettier 3.9 collapses short union types onto one line; reformat the
9 affected files so lint passes on the updated toolchain.
@coderabbitai

coderabbitai Bot commented Aug 8, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@polaz, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 21 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

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.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 0d1b6ffa-736c-4b06-9c7b-53e6d4357a03

📥 Commits

Reviewing files that changed from the base of the PR and between 36fe5bd and 5f1655e.

📒 Files selected for processing (5)
  • packages/gitlab-mcp/docs/guide/configuration.md
  • packages/gitlab-mcp/docs/troubleshooting/clients.md
  • packages/gitlab-mcp/docs/troubleshooting/index.md
  • packages/gitlab-mcp/src/logger.ts
  • packages/gitlab-mcp/tests/unit/logger.test.ts
📝 Walkthrough

Walkthrough

The pull request routes logger output by transport, updates logging documentation and tests, upgrades workflow actions and package dependencies, and applies formatting-only changes plus a runner schema test fixture update.

Changes

Logging and maintenance

Layer / File(s) Summary
Transport-aware logger routing
packages/gitlab-mcp/src/logger.ts, packages/gitlab-mcp/tests/unit/logger.test.ts, packages/gitlab-mcp/docs/guide/configuration.md
Logger destinations now depend on transport and format. Tests and documentation cover stdout, stderr, JSON, pretty output, and destination overrides.
Workflow and package version updates
.github/workflows/*, package.json, packages/gitlab-mcp-db/package.json, packages/gitlab-mcp/package.json
Node.js actions use v7, CodeQL actions use v4.37.4, and package dependency ranges are updated.
Formatting and validation fixture updates
packages/gitlab-mcp/src/cli/docker/types.ts, packages/gitlab-mcp/src/entities/*, packages/gitlab-mcp/src/graphql/workItems.ts, packages/gitlab-mcp/src/services/TokenScopeDetector.ts, packages/gitlab-mcp/tests/integration/*
Union types and tool mappings are reformatted without semantic changes. The runner fixture passes multiple job statuses as an array.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested labels: dependencies, javascript

Sequence Diagram(s)

sequenceDiagram
  participant MCPTransport
  participant Logger
  participant OutputStream
  MCPTransport->>Logger: select stdio or HTTP mode
  Logger->>Logger: resolve LOG_DESTINATION and LOG_JSON
  Logger->>OutputStream: write logs to stdout or stderr
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The PR includes unrelated dependency upgrades, GitHub Actions updates, formatting-only changes, and an integration schema test change beyond issue #563. Move dependency, workflow, formatting, and schema-test updates into separate pull requests, or document their direct necessity for this logging fix.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The logger now routes all stdio logs to stderr, ignores stdout overrides with a warning, and adds tests for the protocol requirement in issue #563.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the primary logging fix: preventing stdout writes in stdio mode.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/#563-stdio-log-destination

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.

@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown

Test Coverage Report

Overall Coverage: 96.94%

Metric Percentage
Statements 96.32%
Branches 88.13%
Functions 95%
Lines 96.94%

View detailed coverage report

@codecov

codecov Bot commented Aug 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/gitlab-mcp/tests/unit/logger.test.ts`:
- Around line 502-515: Extend the logger tests near the existing
pretty-transport case with an HTTP plain-text scenario: set PORT, leave LOG_JSON
unset, and set LOG_DESTINATION to stdout, then import the logger and assert the
pino transport destination is 1. Reuse the existing pino mock and environment
cleanup patterns.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: dd36fd0d-ff93-46f3-9143-a820cea72b25

📥 Commits

Reviewing files that changed from the base of the PR and between e536be0 and 36fe5bd.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (23)
  • .github/workflows/ci-cd.yml
  • .github/workflows/codeql.yml
  • .github/workflows/coverage-pages.yml
  • .github/workflows/docs.yml
  • .github/workflows/pr-validation.yml
  • .github/workflows/release-please.yml
  • .github/workflows/upstream-monitor.yml
  • package.json
  • packages/gitlab-mcp-db/package.json
  • packages/gitlab-mcp/docs/guide/configuration.md
  • packages/gitlab-mcp/package.json
  • packages/gitlab-mcp/src/cli/docker/types.ts
  • packages/gitlab-mcp/src/entities/context/types.ts
  • packages/gitlab-mcp/src/entities/core/index.ts
  • packages/gitlab-mcp/src/entities/files/index.ts
  • packages/gitlab-mcp/src/entities/mrs/index.ts
  • packages/gitlab-mcp/src/entities/wiki/index.ts
  • packages/gitlab-mcp/src/graphql/workItems.ts
  • packages/gitlab-mcp/src/logger.ts
  • packages/gitlab-mcp/src/services/TokenScopeDetector.ts
  • packages/gitlab-mcp/tests/integration/helpers/registry-helper.ts
  • packages/gitlab-mcp/tests/integration/schemas/runners.test.ts
  • packages/gitlab-mcp/tests/unit/logger.test.ts

Comment thread packages/gitlab-mcp/tests/unit/logger.test.ts

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 36fe5bdf90

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/gitlab-mcp/docs/guide/configuration.md Outdated
polaz added 2 commits August 8, 2026 21:39
- LOG_FORMAT tokens toggle field visibility; the line always renders in
  pino-pretty's fixed order, so stop advertising custom layouts in the
  docstring and configuration guide
- add unit test for LOG_DESTINATION=stdout with the pretty transport in
  HTTP mode
- drop issue references from code comments and test names; ticket
  numbers belong in commits and PRs, not in source
Startup 'Failed to parse JSONRPC message' bursts mean an outdated
build (stale npx cache) logging to stdout; document the symptom,
cause, and cache-refresh fix with a quick-diagnosis row.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cfc89b9639

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/gitlab-mcp/src/logger.ts
The %msg token cannot suppress the message: a log line without its
message is useless, so only %time, %level, and %name act as
visibility switches. Make the docstring and configuration guide say
so explicitly instead of implying %msg is toggleable.
@sonarqubecloud

sonarqubecloud Bot commented Aug 8, 2026

Copy link
Copy Markdown

@polaz

polaz commented Aug 8, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: 5f1655efbc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@polaz
polaz merged commit 2e8e836 into main Aug 8, 2026
19 checks passed
@polaz
polaz deleted the fix/#563-stdio-log-destination branch August 8, 2026 22:12
@sw-release-bot sw-release-bot Bot mentioned this pull request Aug 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[gitlab-mcp] All startup logs written to stdout, polluting MCP stdio channel

1 participant