Skip to content

fix(mcp): route console logs to stderr, replace git subprocess in check_fex_freshness#12

Merged
GioAbq merged 3 commits into
developfrom
bugfix/fex-mcp-freshness-stdout-logging
Jun 19, 2026
Merged

fix(mcp): route console logs to stderr, replace git subprocess in check_fex_freshness#12
GioAbq merged 3 commits into
developfrom
bugfix/fex-mcp-freshness-stdout-logging

Conversation

@GioAbq

@GioAbq GioAbq commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Bug 1 (protocol corruption): Host.CreateApplicationBuilder default Console logger was writing to stdout, interleaving info: log lines with JSON-RPC frames. MCP hosts stalled waiting for valid JSON.
    Fix: builder.Logging.AddConsole(o => o.LogToStandardErrorThreshold = LogLevel.Trace) — all logs to stderr.

  • Bug 2 (subprocess hang): check_fex_freshness spawned git rev-parse --short HEAD. Under an MCP stdio host the process inherits pipe handles, causing the subprocess to hang >10s.
    Fix: direct filesystem read of .git/HEAD + packed-refs. Resolves HEAD in <1ms.

Measured before/after

Metric Before After
stdout contents log lines + JSON mixed pure JSON only
check_fex_freshness round-trip >10 000 ms (hang) 419 ms (cold start incl.)
R# ERRORs in FEx.McpServer 0 0

Test plan

  • Reconnect fex-api MCP server after merge
  • Call check_fex_freshness — returns instantly
  • Regenerate API surface: pwsh .\Generate-ApiSurface.ps1

GioAbq added 3 commits June 19, 2026 21:18
…check_fex_freshness

The MCP stdio server was routing all Console logger output to stdout,
corrupting the newline-delimited JSON-RPC stream. Hosts would stall
waiting for a valid JSON frame while log lines were interleaved.

Added AddConsole(o => o.LogToStandardErrorThreshold = LogLevel.Trace)
so all log output goes to stderr, leaving stdout exclusively for JSON-RPC.

Also replaced the git rev-parse --short HEAD subprocess in CheckFreshness
with a direct filesystem read of .git/HEAD and packed-refs. The subprocess
was hanging under MCP stdio hosts due to inherited pipe handles, causing
check_fex_freshness call latency >10s. The new implementation resolves
HEAD from .git files in <1ms.
…r7-jv3q)

Packages 2.1.2 and 2.1.11 have a known high-severity vulnerability. Pin globally
in Directory.Build.props so TreatWarningsAsErrors does not promote NU1903 to a
build error in FEx.EFCore, FEx.AzureDevOpsx, and FEx.Imaging.Windows.
@GioAbq GioAbq merged commit 584e942 into develop Jun 19, 2026
3 checks passed
@GioAbq GioAbq deleted the bugfix/fex-mcp-freshness-stdout-logging branch June 19, 2026 20:02
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.

1 participant