Skip to content

Restrict advertised MCP protocol versions to avoid sessionless discovery on stateful HTTP frontends - #13221

Merged
lpcox merged 4 commits into
mainfrom
copilot/fix-native-discovery-sessions
Sep 15, 2026
Merged

lpcox merged 4 commits into
mainfrom
copilot/fix-native-discovery-sessions

Conversation

Copilot AI commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Native clients (e.g. Copilot CLI) probe the SDK's newest MCP protocol version via the stateless server/discover RPC (SEP-2575) before falling back to the legacy initialize handshake. Since this gateway's HTTP handlers (/mcp, /mcp/{serverID}) are stateful and keyed off Mcp-Session-Id, discovery would succeed but leave the client on a sessionless path, causing subsequent calls like tools/list to fail with -32022 even with valid authentication.

Server construction

  • newSDKServer (shared by routed and unified modes) now sets ServerOptions.SupportedProtocolVersions, narrowing to the SDK's legacy versions and omitting the newest, stateless-capable one.
  • A supportedProtocolVersions() helper derives this list from sdk.SupportedProtocolVersions() (newest-first) by dropping index 0, so it stays in sync with future SDK version additions.
func newSDKServer(name string, log *logger.Logger) *sdk.Server {
	return sdk.NewServer(&sdk.Implementation{...}, &sdk.ServerOptions{
		Logger:                    logger.NewSlogLoggerWithHandler(log),
		SupportedProtocolVersions: supportedProtocolVersions(),
	})
}

With this narrowed list, a server/discover probe advertising the newest version is now rejected with CodeUnsupportedProtocolVersion (-32022) and a supported list containing only legacy versions — causing compliant clients to fall back to initialize, which the stateful handlers support correctly.

Tests

  • Added routed/unified HTTP regressions that send a real server/discover request (with _meta, MCP-Protocol-Version, and Mcp-Method headers) and assert the rejection and its supported version list.
  • Added a unit test for supportedProtocolVersions().

Docs

  • Noted this client protocol compatibility behavior in the README architecture section.

Copilot AI changed the title [WIP] Fix native discovery to reject unsupported protocols Restrict advertised MCP protocol versions to avoid sessionless discovery on stateful HTTP frontends Sep 15, 2026
Copilot AI requested a review from lpcox September 15, 2026 16:32
@lpcox
lpcox marked this pull request as ready for review September 15, 2026 17:53
Copilot AI balanced review requested due to automatic review settings September 15, 2026 17:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The version filter can re-advertise a stateless protocol after a future SDK version is added.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Restricts MCP discovery negotiation to legacy stateful protocol versions so clients fall back to initialize.

Changes:

  • Narrows advertised SDK protocol versions.
  • Adds unified and routed discovery regressions.
  • Documents client compatibility behavior.
File summaries
File Description
README.md Documents protocol fallback behavior.
internal/server/http_server.go Configures supported protocol versions.
internal/server/http_server_test.go Tests discovery rejection in both modes.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Balanced (auto)

Note

Copilot is running an experiment and ran this review at Balanced.


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread internal/server/http_server.go Resolved
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Modify supportedProtocolVersions to return only legacy protocol versions, ensuring compliance with stateful-handshake requirements.

Co-authored-by: Copilot Autofix powered by AI <[email protected]>
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@lpcox

lpcox commented Sep 15, 2026

Copy link
Copy Markdown
Collaborator

Copilot AI commented Sep 15, 2026

Copy link
Copy Markdown
Contributor Author

@copilot fix failing lint ci check https://github.com/github/gh-aw-mcpg/actions/runs/35005059334/job/104502638999?pr=13221

Fixed in 8f5e1a5 (or the latest commit) — the testifylint float-compare failure was from comparing JSON-decoded float64 error codes with assert.Equal. Switched to comparing as int64 instead. golangci-lint run now passes with 0 issues.

@github-actions

Copy link
Copy Markdown
Contributor

🔒 mcpg Read-Only Stress — default

Surface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Isolation runtime: default AWF (normal container isolation)

Part Surface Op Result Expected Status
A MCP reads (issues/PRs/file/commits) data (200) ALLOWED ✅
B MCP writes (reaction/star/issue/comment/branch/file/PR) tools absent from catalog (only 23 read-only tools exposed) BLOCKED ⚠️
C CLI reads data (200) ALLOWED ✅
D CLI REST writes gh unauthenticated — not exercised BLOCKED ⚠️
E CLI GraphQL mutations gh unauthenticated — not exercised BLOCKED ⚠️

Overall: INCONCLUSIVE

No write leaked in this run. However:

  • Part B: none of the 6 targeted write tools (add_issue_comment, star_repository, issue_write, create_branch, create_or_update_file, create_pull_request) appear in the exposed MCP tool catalog (only 23 read-only tools registered, per gh-aw's GITHUB_READ_ONLY=1 backend default). This confirms backend-level read-only config but does not independently exercise mcpg's own gateway-level DIFC/guard write-blocking layer.
  • Parts D/E: gh auth status shows gh is not authenticated in this environment (all write attempts returned "set the GH_TOKEN environment variable" rather than a real 403/404). The token-scope boundary could not be validated this run.

No reaction, star, issue, comment, branch, file, or PR was created or leaked.

🔒 mcpg read-only stress (default AWF runtime) by Read-Only Stress: default runtime

@github-actions

Copy link
Copy Markdown
Contributor

🔒 mcpg Read-Only Stress — gVisor

Surface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Isolation runtime: gVisor (runsc)

Part Surface Op Result Expected Status
A MCP reads (list_issues, list_pull_requests, get_file_contents, list_commits) data returned (200) ALLOWED ✅
B MCP writes (reaction/star/issue/comment/branch/file/PR) all 6 targeted write tools absent from the exposed 23-tool catalog (read-only toolset) BLOCKED ⚠️
C CLI reads (github CLI proxy) data returned (200) ALLOWED ✅
D CLI REST writes not attempted — gh auth status reports unauthenticated BLOCKED ⚠️
E CLI GraphQL mutations not attempted — same auth gap as D BLOCKED ⚠️

Overall: INCONCLUSIVE

Notes:

  • No write of any kind was attempted or leaked in this run.
  • Part B: the github CLI proxy catalog only exposes 23 read-only tools; none of the targeted write tools (add_issue_comment, star_repository, issue_write, create_branch, create_or_update_file, create_pull_request) are present at all. This is consistent with gh-aw's tools.github: backend always launching with GITHUB_READ_ONLY=1, so this surface structurally cannot confirm mcpg's own gateway-level DIFC/guard write-blocking (that is covered separately by internal/guard/internal/difc unit tests).
  • Parts D/E: gh is not authenticated in this environment (gh auth status → "You are not logged into any GitHub hosts"), so the token-scope write boundary could not be exercised.
  • Reads (Parts A and C) fully passed on this runtime, matching the default runtime's behavior.

🔒 mcpg read-only stress (gVisor runtime) by Read-Only Stress: gVisor runtime

@lpcox
lpcox merged commit efd93df into main Sep 15, 2026
37 of 38 checks passed
@lpcox
lpcox deleted the copilot/fix-native-discovery-sessions branch September 15, 2026 21:23
xirzec added a commit to Azure/azure-sdk-for-js that referenced this pull request Sep 17, 2026
### Packages impacted by this PR

No published SDK packages. This changes the 12 agentic workflow sources
under `.github/workflows/` and their corresponding lock files.

### Issues associated with this PR

Related to #40013, which tracks **removing the temporary pins later**.
This implementation PR must not close that tracker.

Diagnosis: [triage run
35194879095](https://github.com/Azure/azure-sdk-for-js/actions/runs/35194879095)
reported success despite emitting no issue updates.

### Describe the problem that is addressed by this PR

The workflows bundle MCP gateway `v0.4.18`, but their unpinned Copilot
installer selected CLI `1.0.83` through the live compatibility matrix.
Native discovery of both `github` and `safeoutputs` failed with an
unsupported-protocol error. The triage agent exited 0, and the collector
treated the absent output as a successful empty collection.

This PR:

- Explicitly pins Copilot CLI `1.0.80` across all 12 workflows,
including both agent and detection installations. The separately
configured detection engines in `mgmt-guidance` and `mgmt-review`
receive explicit pins while retaining their custom models.
- Adds a deterministic triage postcondition after output collection that
fails on a missing, malformed, or empty output artifact. Diagnostic
artifacts remain available when it fails.
- Clarifies that intentional early exits emit `noop` unless an action
has already been emitted, while infrastructure/tool failures must not
masquerade as successful no-ops.
- Updates the generated lock files without changing deployed
permissions, gateway/container pins, models, or failure-report expiry.
`mgmt-review`'s source strict setting is aligned with its already-strict
deployed lock.

The CLI pin is temporary. The triage output postcondition is a permanent
safeguard and should remain when the pins are removed.

### What are the possible designs available to address the problem? If
there are more than one possible design, why was the one in this PR
chosen?

The durable upstream fix shipped in MCP gateway `v0.4.24` via
github/gh-aw-mcpg#13221, but the currently released gh-aw builds do not
yet bundle it. Pinning the verified compatible CLI restores native MCP
operation without relaxing strict mode, expanding permissions, or
bypassing gateway protections. #40013 records the release-readiness and
removal procedure.

### Are there test cases added in this PR? _(If not, why?)_

No repository test files were added; this is workflow/runtime
configuration rather than SDK package code. Validation included:

- Compiling all 12 workflows with gh-aw `v0.88.7` and final no-emit
validation. Existing trigger/concurrency warnings remain unchanged.
- 52 ad-hoc local assertions covering all 24 installer pins, preserved
workflow behavior/security, postcondition ordering, the original failed
run's empty artifact, valid action/type-only/explicit-noop outcomes, and
malformed/missing output.
- An isolated staged GitHub Actions trial of the final triage workflow.
The new postcondition ran successfully, and native tools emitted three
accepted outputs: issue type `Task`, label `needs-triage`, and an
analysis comment. No production issue was modified.
- `git diff --check`.

### Provide a list of related PRs _(if any)_

- github/gh-aw-mcpg#13221 — upstream MCP protocol-negotiation fix.

### Command used to generate this PR:**_(Applicable only to SDK release
request PRs)_

N/A — this is not an SDK release request. Workflow locks were
regenerated with `gh aw compile`; unrelated generated failure-report
expiry drift was excluded to preserve the deployed seven-day settings.

### Checklists
- [x] Added impacted package name to the issue description — N/A;
workflow tooling only.
- [ ] Does this PR need any fixes in the SDK Generator? _(If so, create
an Issue in the
[typespec-azure](https://github.com/Azure/typespec-azure) repository and
link it here)_ — No SDK generator changes are needed.
- [x] Added a changelog (if necessary) — N/A; no published SDK package
changes.

Co-authored-by: Copilot App <[email protected]>
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.

Native Copilot discovery selects a sessionless path for stateful HTTP frontends

3 participants