Skip to content

Fix MCP server exiting before in-flight tool calls finish responding - #1

Merged
Ramachandrajoshi merged 5 commits into
mainfrom
claude/ci-build-failures-hrcnsg
Jul 26, 2026
Merged

Ramachandrajoshi merged 5 commits into
mainfrom
claude/ci-build-failures-hrcnsg

Conversation

@Ramachandrajoshi

Copy link
Copy Markdown
Owner

StdioServer.start() resolved as soon as stdin closed, without waiting for _handleLine promises still in flight (they were fired via .catch() and never tracked). serve.js exits the process right after start() resolves, so any tools/call still awaiting real work (indexing/DB queries) at that moment lost its response — the client saw the process exit with no reply. Track pending line-handling promises and wait for them before resolving.

StdioServer.start() resolved as soon as stdin closed, without waiting for
_handleLine promises still in flight (they were fired via .catch() and
never tracked). serve.js exits the process right after start() resolves,
so any tools/call still awaiting real work (indexing/DB queries) at that
moment lost its response — the client saw the process exit with no reply.
Track pending line-handling promises and wait for them before resolving.
Copilot AI review requested due to automatic review settings July 26, 2026 01:27

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

This PR prevents the MCP stdio server from exiting as soon as stdin closes by tracking per-line request handlers and waiting for all in-flight request processing to finish before StdioServer.start() resolves. This aligns the server lifecycle with cgraph serve, which exits the process immediately after start() completes, ensuring clients don’t lose tool responses mid-flight.

Changes:

  • Track _handleLine(...) promises in a pending set.
  • Remove completed promises from tracking when they settle.
  • Delay start() resolution until readline closes and all pending handlers have finished.

Comment thread src/mcp/protocol.js Outdated
Comment thread src/mcp/protocol.js Outdated
});

rl.on('close', resolve);
rl.on('close', () => { Promise.all(pending).then(resolve); });
@Ramachandrajoshi
Ramachandrajoshi merged commit 96bde5b into main Jul 26, 2026
12 checks passed
@Ramachandrajoshi
Ramachandrajoshi deleted the claude/ci-build-failures-hrcnsg branch July 26, 2026 02:06
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.

4 participants