Skip to content

Fix MCP stdio framing and negotiate protocolVersion#120

Merged
adamcohenhillel merged 1 commit into
mainfrom
fix/mcp-stdio-framing
Jul 5, 2026
Merged

Fix MCP stdio framing and negotiate protocolVersion#120
adamcohenhillel merged 1 commit into
mainfrom
fix/mcp-stdio-framing

Conversation

@adamcohenhillel

Copy link
Copy Markdown
Contributor

Summary

  • Replace LSP-style Content-Length framing with the MCP stdio transport's newline-delimited JSON on both output and input parsing, so conforming MCP clients no longer hang against the server.
  • Negotiate protocolVersion in the initialize handler: echo a supported client version back, otherwise respond with the latest supported version (2025-06-18, replacing the unpublished 2025-11-25).
  • Fix the stdin buffer race: line extraction is now synchronous and messages are processed serially on a promise-chain queue, so interleaved chunks cannot drop or duplicate messages. Malformed lines now get a -32700 parse error response instead of crashing the data handler.
  • Document the stdio framing and negotiated protocol version in the mcp-server README.

Closes #68

Test plan

  • node tests/integrations/runtime-mcp-contract.mjs passes, including new protocolVersion negotiation assertions and a stdio smoke test performing a real newline-delimited JSON handshake (initialize -> notifications/initialized -> tools/list) against a spawned server process
  • ./scripts/check.sh passes from the repo root
  • Manual chunked-stdin smoke test (7-byte writes) confirms all messages are parsed and answered in order with the negotiated version

🤖 Generated with Claude Code

Replace LSP-style Content-Length framing with the MCP stdio transport's
newline-delimited JSON on both input and output, negotiate the client's
protocolVersion during initialize (latest supported: 2025-06-18), and
make stdin buffering synchronous with a serial message queue so
interleaved chunks cannot drop or duplicate messages.

Closes #68

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@vercel

vercel Bot commented Jul 4, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
openphone-docs Ready Ready Preview, Comment Jul 4, 2026 2:20am

Request Review

@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: 427dba1dc7

ℹ️ 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".

} from "../runtime/protocol/openphone-runtime-tools.mjs";

const PROTOCOL_VERSION = "2025-11-25";
export const SUPPORTED_PROTOCOL_VERSIONS = ["2025-06-18"];

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve 2025-11-25 protocol negotiation

For clients that only advertise the current MCP protocolVersion (2025-11-25), this array makes initialize respond with 2025-06-18, after which such clients should disconnect rather than use the server. The latest MCP lifecycle spec lists 2025-11-25 as the latest version and requires echoing the requested version when the server supports it (https://modelcontextprotocol.io/specification/2025-11-25/basic/lifecycle); since the server was already advertising that version before this change and this patch does not remove any 2025-11-25-specific behavior, omitting it creates an interop regression for current clients.

Useful? React with 👍 / 👎.

@adamcohenhillel adamcohenhillel merged commit 5b25b3b into main Jul 5, 2026
3 checks passed
@adamcohenhillel adamcohenhillel deleted the fix/mcp-stdio-framing branch July 6, 2026 22:25
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.

MCP server: fix stdio framing and negotiate protocolVersion

1 participant