Skip to content

fix(mcp): route deferred transport requests under the client's outbound scope - #9199

Merged
waleedlatif1 merged 1 commit into
stagingfrom
fix/mcp-deferred-request-outbound-scope
Oct 18, 2026
Merged

waleedlatif1 merged 1 commit into
stagingfrom
fix/mcp-deferred-request-outbound-scope

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • When a workflow times out or is aborted with MCP tool calls in flight, the MCP SDK sends notifications/cancelled from the abort listener, which runs in the async context of whoever called abort() (e.g. the execute route's timeout timer, created outside the outbound scope)
  • That request hit the transport fetch with no outbound scope, so routing failed with MISSING_SCOPE: the server never learned of the cancellation and kept running abandoned calls, and the transport logged a failed request each time
  • McpClient now captures the outbound scope at construction and wraps its transport fetch: a scope current at call time still wins (pooled clients never pin an organization), the captured scope only fills in when none is current, and a client built outside any scope keeps failing closed
  • Route policy is still resolved per request; the new captureOutboundScopeFallback lives next to captureOutboundScope, which keeps its stricter semantics for isolated-vm callbacks
  • Regressed with org-specific HTTPS egress (feat(network): add organization-specific HTTPS egress #7807)

Type of Change

  • Bug fix

Testing

  • New McpClient outbound scope tests run the real AsyncLocalStorage scope: a transport request from outside any scope routes under the constructing organization, a current scope still wins, and an unscoped client still throws MISSING_SCOPE
  • Red without the wrapper (MISSING_SCOPE), and red with plain captureOutboundScope (a current scope is ignored)
  • lib/mcp suite: 351 passed; comment-hygiene, test-patterns, test-types checks pass

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing (new tests pass the test-audit authoring gate)
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercel Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

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

1 Skipped Deployment
Project Deployment Actions Updated
docs Skipped Skipped Oct 18, 2026 9:06pm UTC

Request Review

@cubic-dev-ai cubic-dev-ai Bot 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.

No issues found across 3 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Turn on auto-fix | Re-trigger cubic

@greptile-apps

greptile-apps Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issues were found.

Summary

McpClient now restores its construction-time outbound scope when a transport request has no current scope.

  • MCP requests keep their organization scope when callbacks run later.

No actionable issues were found. Tests were inspected, not run.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[MCP transport request] --> B{Current scope exists?}
  B -->|Yes| C[Keep current scope]
  B -->|No| D{Construction scope captured?}
  D -->|Yes| E[Restore captured scope]
  D -->|No| F[Continue without scope]
  C --> G[Existing guarded fetch]
  E --> G
  F --> G
  G --> H[Read current routing policy]
  H --> I[Send request or reject]
Loading

Reviews (1) · Last reviewed commit: "fix(mcp): route deferred transport reque..." · Reviewed by Greptile

@waleedlatif1
waleedlatif1 merged commit 124a319 into staging Oct 18, 2026
53 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/mcp-deferred-request-outbound-scope branch October 18, 2026 22:12

This branch was previously deployed

1 inactive deployment
Preview — c0aecd12 Deployed Oct 18, 2026 by vercel[bot]
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.

1 participant