Skip to content

fix(mcp): block MCP serve until message loop finishes - #5

Open
J-DubApps wants to merge 1 commit into
RyanLisse:mainfrom
J-DubApps:fix/mcp-serve-waits-for-completion
Open

J-DubApps wants to merge 1 commit into
RyanLisse:mainfrom
J-DubApps:fix/mcp-serve-waits-for-completion

Conversation

@J-DubApps

@J-DubApps J-DubApps commented Apr 10, 2026

Copy link
Copy Markdown

ContactbookMCPServer.run() calls server.start(transport:) and returns immediately. The swift-sdk Server.start() spawns the message-handling loop as a detached Task, so without awaiting completion the command exits before servicing any JSON-RPC requests. The process dies within ~1 second of launch with zero stdout, zero stderr, exit 0 -- making the MCP server unusable from Claude Code, Claude Desktop, or similar MCP client.

Fix: await server.waitUntilCompleted() after start().

Verified: initialize + tools/list now return valid JSON-RPC responses and the process stays alive; claude mcp get reports Connected.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed server lifecycle to ensure message processing completes fully before shutdown, preventing premature termination and improving reliability of the contactbook service.

ContactbookMCPServer.run() calls server.start(transport:) and returns
immediately. The swift-sdk Server.start() spawns the message-handling
loop as a detached Task, so without awaiting completion the command
exits before servicing any JSON-RPC requests. The process dies within
~1 second of launch with zero stdout, zero stderr, exit 0 -- making the
MCP server unusable from Claude Code, Claude Desktop, or any MCP client.

Fix: await server.waitUntilCompleted() after start().

Verified: initialize + tools/list now return valid JSON-RPC responses
and the process stays alive; `claude mcp get` reports Connected.
@coderabbitai

coderabbitai Bot commented Apr 10, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e706063b-6a61-4993-bd9a-128dc1406f73

📥 Commits

Reviewing files that changed from the base of the PR and between f72ce38 and ad92fc5.

📒 Files selected for processing (1)
  • Sources/MCP/ContactbookMCPServer.swift

📝 Walkthrough

Walkthrough

The ContactbookMCPServer.run() method now awaits server.waitUntilCompleted() after initiating server.start(transport:), changing the control flow from immediately returning to blocking until the server's background message-handling loop completes.

Changes

Cohort / File(s) Summary
Server Lifecycle Control
Sources/MCP/ContactbookMCPServer.swift
Added await server.waitUntilCompleted() after server.start(transport:) to block until server message-handling completes, altering task exit behavior.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 Hops with glee at the flow so fine,
No more quick returns at startup time,
Now we wait with patient grace,
For the server to finish its race,
Async control, oh so divine! 🚀

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: making the MCP server block until the message loop completes, which directly addresses the core issue of premature process termination.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

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