Skip to content

mcp: Avoid stopping servers for equivalent URI definitions - #333443

Merged
Connor Peet (connor4312) merged 1 commit into
microsoft:mainfrom
kondv:dev/kondv/mcp-uri-definition-equality
Aug 31, 2026
Merged

mcp: Avoid stopping servers for equivalent URI definitions#333443
Connor Peet (connor4312) merged 1 commit into
microsoft:mainfrom
kondv:dev/kondv/mcp-uri-definition-equality

Conversation

@kondv

Copy link
Copy Markdown

Fixes #327970

Problem

McpServerDefinition.equals uses generic structural equality for URI-bearing fields. A URI stores enumerable lazy caches such as _formatted and _fsPath, so equivalent definitions can compare unequal when only one URI instance has populated a cache. McpService.updateCollectedServers() then treats the equivalent definition as changed and stops the live server.

Change

Compare nested URI values by normalized resource identity while preserving the existing structural comparison behavior for arrays, objects, primitives, inherited enumerable properties, and missing versus explicit undefined values.

The change is scoped to the launch, presentation, and variableReplacement comparisons in McpServerDefinition.equals. Serialization, revival, hashing, and server lifecycle behavior are unchanged.

This shares the URI-cache diagnosis from #329857, but is intentionally narrower. #329857 also changes serialization, revival, hashing, and malformed or cyclic value handling; this PR changes only the in-memory equality used by the reproduced stop path and adds service-level coverage for that path.

Validation

  • Node tests: mcpTypes (20 passing), mcpService (3 passing)
  • Chromium tests: mcpTypes (19 passing), mcpService (2 passing)
  • npm run typecheck-client
  • Targeted ESLint and hygiene checks
  • Live desktop A/B/C validation with a stateful Streamable HTTP MCP server:
    • VS Code 1.135 and the same Code OSS build with the comparator reverted both sent a session-termination request after an equivalent warm/cold URI republish and logged stopped because the definition changed.
    • The patched Code OSS build kept the original session connected for 60 seconds after the equivalent republish.
    • A genuinely changed URI still stopped the original session; starting the updated definition created a new session.

@kondv

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree company="Microsoft"

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.

Pull request overview

Fixes MCP server restarts caused by URI lazy-cache differences during definition equality checks.

Changes:

  • Adds URI-aware structural comparison for relevant definition fields.
  • Adds equality and server lifecycle regression tests.
  • Preserves detection of genuine definition changes.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
mcpTypes.ts Adds URI-aware definition equality.
mcpTypes.test.ts Covers URI cache and actual-value differences.
mcpService.test.ts Covers server stop behavior after republishing definitions.

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

Comment thread src/vs/workbench/contrib/mcp/test/common/mcpService.test.ts
Compare URI values semantically when evaluating MCP server definitions so lazy URI caches do not stop live servers.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 02df8817-61e4-4a9f-8b74-f30a434897b0
@connor4312
Connor Peet (connor4312) merged commit 374ea56 into microsoft:main Aug 31, 2026
27 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.137.0 milestone Aug 31, 2026
@kondv
Girish Konda (kondv) deleted the dev/kondv/mcp-uri-definition-equality branch September 1, 2026 00:21
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 servers are stopped immediately after tool discovery (and mid-initialize) since 1.129 - kills stateful servers (1.128 OK, 1.130/1.131 broken)

5 participants