Skip to content

Cherry pick MCP stdio: negotiate initialize protocol version, default to 2025-11-25, return description in serverInfo, and add initialize wire-shape tests #3622#3627

Open
aaronburtle wants to merge 1 commit into
release/2.0from
dev/aaronburtle/cherry-pick-3622
Open

Cherry pick MCP stdio: negotiate initialize protocol version, default to 2025-11-25, return description in serverInfo, and add initialize wire-shape tests #3622#3627
aaronburtle wants to merge 1 commit into
release/2.0from
dev/aaronburtle/cherry-pick-3622

Conversation

@aaronburtle
Copy link
Copy Markdown
Contributor

Why make this change?

Closes #3626

What is this change?

Cherry picks this PR: #3622

How was this tested?

Built locally and passes normal test suite.

…25, return description in serverInfo, and add initialize wire-shape tests (#3622)

## Why make this change?

DAB MCP stdio always returned `2025-06-18` in `initialize`, even when
clients requested newer protocol versions, causing modern MCP clients
(e.g., Claude Code 2.x) to disconnect.
This update aligns initialize negotiation behavior with MCP version
selection expectations, updates the default supported version to
`2025-11-25`, aligns initialize metadata shape for newer protocol
versions, and adds focused wiring tests to lock down the initialize
response wire format end-to-end.

## What is this change?

- **Protocol default**
- Bumped MCP default protocol from `2025-06-18` to `2025-11-25` in
`McpProtocolDefaults`.

- **Initialize version negotiation**
- `initialize` now reads `params.protocolVersion` from the client
request.
- Server responds with the greatest supported version `<=` client
requested (never higher than the client).

- **Initialize metadata field shape by negotiated protocol**
- For negotiated protocol versions `>= 2025-11-25`, runtime MCP
description is returned as `serverInfo.description`.
- For older negotiated protocol versions, description remains top-level
`instructions` for backward compatibility.

- **Negotiation utility + parsing behavior**
  - Added centralized negotiation helper in `McpProtocolDefaults`.
- Compares date-formatted versions (`yyyy-MM-dd`) with ordinal string
fallback for non-date values.
- Added protocol-threshold helper for choosing `serverInfo.description`
vs `instructions`.

- **Focused test coverage**
  - Added helper unit tests for:
    - new default protocol value,
    - client newer than server (server version returned),
    - client older than server (client version returned),
    - missing client version,
    - non-date fallback comparison path,
    - protocol threshold behavior for `serverInfo.description`.
- Added focused initialize wiring tests for `HandleInitialize` that
validate:
    - JSON-RPC envelope shape (`jsonrpc`, `id`),
    - negotiated `result.protocolVersion`,
    - capabilities shape,
- field placement across protocol/description scenarios
(`serverInfo.description` vs `instructions` vs neither).

```csharp
string negotiatedProtocolVersion =
    McpProtocolDefaults.ResolveInitializeResponseProtocolVersion(
        _protocolVersion,
        clientRequestedProtocolVersion);
```

## How was this tested?

- [ ] Integration Tests
- [x] Unit Tests

## Sample Request(s)

- Example CLI usage:
  - `dab start --mcp-stdio`

- Example initialize request:
```json
{"jsonrpc":"2.0","method":"initialize","params":{"protocolVersion":"2025-11-25","capabilities":{},"clientInfo":{"name":"claude-code","version":"2.1.98"}},"id":1}
```

- Example initialize response behavior for negotiated `2025-11-25`:
```json
{"jsonrpc":"2.0","id":1,"result":{"protocolVersion":"2025-11-25","capabilities":{"tools":{"listChanged":true},"logging":{}},"serverInfo":{"name":"SQL MCP Server","version":"<dab-version>","description":"<mcp-runtime-description>"}}}
```

- Example initialize response behavior for negotiated older versions:
```json
{"jsonrpc":"2.0","id":1,"result":{"protocolVersion":"2025-06-18","capabilities":{"tools":{"listChanged":true},"logging":{}},"serverInfo":{"name":"SQL MCP Server","version":"<dab-version>"},"instructions":"<mcp-runtime-description>"}}
```

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Aniruddh25 <3513779+Aniruddh25@users.noreply.github.com>
Co-authored-by: Aniruddh Munde <anmunde@microsoft.com>
Co-authored-by: aaronburtle <93220300+aaronburtle@users.noreply.github.com>
(cherry picked from commit 7f4a34d)
Copilot AI review requested due to automatic review settings May 21, 2026 23:33
@aaronburtle aaronburtle changed the base branch from main to release/2.0 May 21, 2026 23:33
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 cherry-picks the MCP stdio “initialize” protocol negotiation improvements needed for 2.0 compatibility with newer MCP clients by negotiating the initialize protocol version, updating the default protocol version, and adjusting where runtime description is emitted based on negotiated protocol.

Changes:

  • Bump the default MCP protocol version to 2025-11-25 and add centralized helpers for initialize protocol negotiation and description field placement.
  • Update MCP stdio initialize handling to negotiate the response protocol version from client request + server support and emit description as serverInfo.description for newer protocols (or instructions for legacy).
  • Add focused unit tests validating protocol negotiation helpers and end-to-end initialize wire shape behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
src/Azure.DataApiBuilder.Mcp/Core/McpProtocolDefaults.cs Updates default protocol version and adds helpers for version negotiation + description placement threshold.
src/Azure.DataApiBuilder.Mcp/Core/McpStdioServer.cs Negotiates initialize protocol version using client request and moves description to serverInfo.description for newer protocols.
src/Service.Tests/UnitTests/McpProtocolDefaultsTests.cs Adds unit tests for default protocol, negotiation behavior, and description-threshold helper.
src/Service.Tests/UnitTests/McpStdioServerInitializeTests.cs Adds initialize “wire-shape” tests validating negotiated protocolVersion and description field placement.

@aaronburtle aaronburtle enabled auto-merge (squash) May 21, 2026 23:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

4 participants