Skip to content

mcp: enforce URL policy after variable resolution - #336849

Draft
Dmitriy Vasyura (dmitrivMS) wants to merge 2 commits into
mainfrom
fix/mcp-resolved-url-policy
Draft

Dmitriy Vasyura (dmitrivMS) wants to merge 2 commits into
mainfrom
fix/mcp-resolved-url-policy

Conversation

@dmitrivMS

@dmitrivMS Dmitriy Vasyura (dmitrivMS) commented Sep 18, 2026

Copy link
Copy Markdown
Collaborator

MCP URL rules must be enforced against the fully resolved launch, even if the resulting URL still contains text that resembles a configuration variable. Policy updates must also recheck existing connections and keep blocked servers from exposing cached tools or prompts.

  • Separate preliminary definition checks from authoritative runtime URL allow/deny checks. Defer preliminary URL checks only for syntactically complete configuration variables, using the same balanced/nested-variable parser as the configuration resolver.
  • Recheck the local resolved connection immediately before starting its transport, even when reactive policy enforcement has already cleared the stored connection.
  • Re-evaluate policy changes and stop connections that become blocked. Retain the last resolved identity after disposal while the server definition remains unchanged, so the block and cached-metadata suppression remain effective.
  • Settle pending startup on explicit stop or disposal, allowing a retry after policy restoration without regressing normal transport restarts. Do not start a disposed connection.
  • Cover resolved allow/deny enforcement, permitted variable-based definitions, literal incomplete markers, access/name restrictions, cached metadata, definition changes, and policy revocation during both running and starting states.

Distinguish preliminary definition checks from authoritative resolved launch checks. Validate the local resolved connection before starting its transport, and re-evaluate active connections whenever policy changes.

Add regression coverage for literal variable markers, resolved URL allow/deny rules, permitted unresolved definitions, and policy changes affecting running servers.

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

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.

Copilot review overview

🟡 Changes recommended

Preliminary checks still defer literal markers, and reactive denial loses its blocked state after clearing unresolved connections.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 High severity · 1 Medium severity

Open (2)
What changed in this PR

Enforces MCP URL policy against resolved runtime connections and reacts to policy changes.

Changes:

  • Separates definition-time and resolved-runtime policy checks.
  • Rechecks resolved connections before transport startup.
  • Adds regression coverage for URL resolution and policy updates.
File Description
allowedMcpServersService.ts Splits preliminary and authoritative checks.
mcpManagement.ts Documents policy-check phases.
mcpServer.ts Adds resolver-aware checks and reactive enforcement.
allowedMcpServersService.test.ts Tests URL policy semantics.
mcpService.test.ts Tests runtime resolution and policy updates.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/vs/workbench/contrib/mcp/common/mcpServer.ts
Comment thread src/vs/platform/mcp/common/allowedMcpServersService.ts Outdated
roblourens
roblourens previously approved these changes Sep 18, 2026
Comment thread src/vs/workbench/contrib/mcp/common/mcpServer.ts
@dmitrivMS
Dmitriy Vasyura (dmitrivMS) marked this pull request as draft September 18, 2026 22:27
Keep resolved policy blocks effective after disposing a connection, including suppression of cached tools and prompts. Settle startup waits on explicit stop or disposal so policy restoration permits a retry without regressing normal transport restarts.

Share configuration-variable parsing with preliminary MCP checks so literal incomplete markers do not defer allow/deny enforcement. Add regression coverage for retained blocks, definition changes, preliminary checks, and cancelled startup.

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

Copy link
Copy Markdown
Contributor

Screenshot Changes

Base: de3a59e0 Current: bec607d2

Changed (2)

sessions/sessionChatInputToolbar/SessionChatPills_HorizontalOverflow/Dark
Before After
before after
sessions/sessionChatInputToolbar/SessionChatPills_HorizontalOverflow/Light
Before After
before after

1 insignificant change(s) omitted (≤20 px, Δ≤2). See CI logs for details.

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.

Copilot review overview

🟡 Changes recommended

Definition updates can revive stale identities, bypass renamed-server policies, and leave cached metadata exposed under access or name restrictions.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 High severity

Open (1)
Resolved since last review (2)

Comment on lines +542 to +543
if (resolved && definition && McpServerDefinition.equals(resolved.definition, definition)) {
return this._evaluatePolicy(resolved.identity);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants