Skip to content

fix(mcp): the serve path and bind failures were both invisible - #37

Merged
vietanhdev merged 1 commit into
mainfrom
fix/mcp-endpoint-and-bind-failure
Jul 20, 2026
Merged

fix(mcp): the serve path and bind failures were both invisible#37
vietanhdev merged 1 commit into
mainfrom
fix/mcp-endpoint-and-bind-failure

Conversation

@vietanhdev

Copy link
Copy Markdown
Owner

Two defects that each make the MCP feature look like it works when it doesn't.

1. Every config the app hands out points at a dead endpoint

The UI's client-config snippets — and all eight examples in docs/guide/mcp.md — pointed at /sse with "type": "sse". That's rmcp 0.1.5's transport. The rmcp 2 migration (#29) mounts Streamable HTTP at /mcp and serves nothing at /sse.

So a user starts the server, copies the Claude Desktop config displayed in the app, and every connection attempt 404s. The feature is unusable via its own documented setup path. The docs were additionally self-contradictory — claude mcp add --transport http ... /sse pairs a Streamable HTTP transport with an SSE path.

The path is now a constant the router is built from and McpStatus reports, so the UI renders whatever is actually being served rather than a second copy free to drift. "type" is corrected to "http", which is what selects Streamable HTTP.

2. A failed bind reports success

tokio::spawn(async move {
    let listener = match TcpListener::bind(addr).await {
        Err(e) => { eprintln!("[MCP] Failed to bind {}: {}", addr, e); return; }
        ...
});
s.cancel_token = Some(ct);          // unconditional
Ok(ApiResponse { success: true, ... })

The bind happened inside the spawned task, so its error had nowhere to go but stderr while the command had already returned success and stored a cancel token.

The port field is user-editable. Enter 80 (EACCES) or a port something else holds: the task exits immediately, nothing is listening, but the UI shows "Running on 127.0.0.1:80" — and because the cancel token was stored, every retry is refused with "MCP server is already running" until the user presses Stop.

Binding before the spawn puts the error back in the caller's hands.

Verification

99 tests pass, clippy clean, frontend lint + format clean.

The guard against re-hardcoding the path is mutation-verified — restoring the nest_service("/mcp", ...) literal fails it:

router_path_is_not_hardcoded_alongside_the_constant ... FAILED
  nest_service should be given MCP_PATH, not a literal

(It's scoped to code above the test module specifically so it can't match its own assertion string.)

Found while auditing the backend for runtime defects.

Two defects that each make the MCP feature look like it works when it
does not.

The client-config snippets in the UI, and every example in the docs,
pointed at /sse with "type": "sse". That is rmcp 0.1.5's transport; the
rmcp 2 migration mounts Streamable HTTP at /mcp and serves nothing at
/sse. Anyone copying the config out of the app -- its own documented
setup path -- got a 404 on every connection attempt. The docs were also
self-contradictory, pairing --transport http with an /sse URL.

The path is now a constant the router is built from and the status
payload reports, so the UI renders whatever is actually served instead of
a second copy that can drift.

Separately, TcpListener::bind ran inside tokio::spawn, leaving its error
nowhere to go but eprintln! while start_mcp_server unconditionally stored
a cancel token and returned success. An unusable port -- taken, or
privileged and EACCES -- reported "Running" in the UI, and every retry
was then refused with "already running" until the user pressed Stop.
Binding before the spawn puts the error back in the caller's hands.

Both guards mutation-verified: reintroducing the nest_service literal
fails router_path_is_not_hardcoded_alongside_the_constant.
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
❌ Deployment failed
View logs
thinkutils c18f577 Jul 20 2026, 03:05 AM

@vietanhdev
vietanhdev merged commit 4973219 into main Jul 20, 2026
9 of 10 checks passed
@vietanhdev
vietanhdev deleted the fix/mcp-endpoint-and-bind-failure branch July 20, 2026 03:18
vietanhdev added a commit that referenced this pull request Jul 20, 2026
The concurrency block intended never to cancel on main -- the comment said
so -- and did the opposite:

  cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}

The expression renders to the STRING "false", and a non-empty string is
truthy in that position, so main was cancelled like any other ref. It
failed silently for exactly as long as nobody merged twice in quick
succession.

Four main runs were cancelled during this batch of merges (#36, #37, #39,
#32), each with ZERO jobs recorded -- so those commits have no evidence
they ever built. The runs that were supposed to be the record of what
shipped are the ones that got killed.

Encoding the rule in the concurrency GROUP is unambiguous: on main the SHA
gives every run its own group, so there is nothing to supersede; every
other ref keeps a per-ref group, so a force-push still cancels the old run.

tests/workflow_concurrency.rs guards both halves -- an expression-valued
cancel-in-progress, and a group that lost its per-SHA component (which
with cancel-in-progress: true would cancel main on every push, strictly
worse than the bug it replaced). Mutation-verified: restoring the original
two lines fails both.

118 tests.
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