Repository navigation
feat(mcp): relay authorized modern upstream subscriptions - #46153
Conversation
|
@greptileai Please review the current commit, including caller isolation and subscription cleanup. |
|
@veria-ai Please review the current commit, including authorization, credential scoping and subscription cleanup. |
|
bugbot run |
|
@litereview code-review |
Review not startedSign in to LiteReview with your workspace Google account and link your GitHub account once before requesting a review. Your linked GitHub account can then request reviews without signing in again. |
PR overviewAll previously flagged issues have been addressed. No open security concerns remain on this pull request. Security reviewNo open security issues remain on this pull request. Fixed/addressed: 1 · PR risk: 0/10 |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
@greptileai Please review current commit 2066acb for catalog credential scoping, setup notification delivery, metadata stability, and remaining actionable concerns. |
|
cursor review Please review commit 2066acb. Setup races and metadata changes are repaired; credential lifetime evidence addresses the remaining fingerprint concern. |
|
@litereview code-review Please review current commit 2066acb, including subscription setup ordering, catalog credential policy, configuration identity, and the updated live evidence. |
Review not startedSign in to LiteReview with your workspace Google account and link your GitHub account once before requesting a review. Your linked GitHub account can then request reviews without signing in again. |
|
@veria-ai Please review commit 2066acb. Catalog refresh retains complete authorized scope, with live credential capture verifying both initial and refreshed requests. |
|
@cursor review Independent execution confirms different SigV4 signatures retain identical fingerprints. Token rotation intentionally expires listeners; see updated credential-lifetime evidence. |
|
@greptileai review this draft before I make it official. Please assess current commit 2066acb and its subscription authorization evidence. |
|
@cursor review the remaining credential-lifetime finding using the thread clarification and existing signer evidence. Preserve the approved reconnect contract |
|
@veria-ai the managed M2M renewal repair at 6d54346. Live renewal, reduced-scope rejection and failed-credential controls pass |
|
@cursor review Please confirm current head |
|
Current gap-repair evidence for
The initial independent isolation observation was a harness synchronization/shared-registry artifact. After synchronizing on the existing catalog readiness boundary, each caller receives only its authorized changes; unauthorized tool calls remain rejected. A separate inconsistent-upstream control advertises subscription support but refuses listen. It preserves ordinary tool use and leaves zero listeners, but a subsequent legacy resource subscription reaches the existing 10-second setup bound with an unhelpful error. This is distinct from empty advertised capabilities (prompt rejection and no listener), and is retained as a limitation rather than adding retry/fallback behavior outside the approved scope. Reviewer reproduction uses the committed uv run --no-sync pytest --override-ini=pythonpath=tests tests/integration/mcp/test_interactions.py -qThe standalone wire replay is also available above. Both enabled-review threads are resolved and Bugbot's fresh |
|
Automatic reviews are disabled for this repository. |
d80e42a to
00a41f4
Compare
Merging this PR will not alter performance
|
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 00a41f4. Configure here.
|
Main CircleCI job integration-mcp fails test_shared_redis_enforces_paginated_tools_and_rest_listings since this merged and passes before it, likely the relay's per-session rate-limit check. https://app.circleci.com/pipelines/github/BerriAI/litellm/91275 |
Restack verification pending: Current head
00a41f4993350ada008bfdd2e7a8ee9f86a0ef22follows PR1 squash merge. Earlier tip-specific evidence below is historical. Local lint/type and affected tests passed (one known unrelated environment-origin failure); fresh CI, completed coverage, bot reviews, and independent verification are pending.TLDR
Problem this solves:
How it solves it:
User Flow
Before, subscribing through the gateway returns Method not found
$GATEWAY_URL/mcp/Method not foundand no subscription eventsAfter, authorized changes arrive and fresh listings include them
$GATEWAY_URL/mcp/Linear ticket
Related to LIT-4510, prerequisite 2 of the approved three-PR stack. Depends on #46134 and targets
litellm_mcp_progress_cancellation. Capability advertisement and the complete modern enablement acceptance tests follow in #46264. Existing #43340 and #34051 are unchangedImplementation
The repair extends the existing listener owner with SDK legacy notification translation, resource subscribe/unsubscribe, bounded queues and session-owned cleanup. Legacy HTTP and SSE callers share the existing authorization, catalog and credential policies. A connection-local readiness event prevents startup notification loss. Non-notifying upstreams do not receive automatic subscription requests. Identity comparison and reauthorization now belong to the subscription owner; routes only extract requests and wire handlers.
The new interaction handler uses the SDK listener and bounded subscription bus. It reuses catalog, authorization, credential and rate-limit policies, including the existing protection against forwarding one caller bearer to multiple upstreams. Catalog events refresh listings and only notify when the caller-visible catalog changes. Each delivery rechecks authorization, including queued events. The stream is bound to the API key and its user, team, organization and end-user identity, so reassignment closes it before another event is delivered. Idle listeners recheck every 15 seconds
There are 128 downstream and upstream slots per process and eight listeners per caller. Partial setup failure releases acquired slots. Disconnect, revoked access, changed credentials or upstream configuration, and upstream closure end the listener. Resource URI subscriptions require exactly one selected server so identical URIs cannot cross server boundaries
Catalog snapshots retain the complete authorized server scope, so the existing credential policy protects both listener creation and listing refreshes. A pre-listen snapshot and post-registration reconciliation preserve setup-time changes. Reauthorization compares the existing catalog configuration identity, excluding discovered OAuth metadata while still rejecting real configuration changes
Managed client-credentials subscriptions bind to the existing grant configuration identity and effective granted scopes. Routine token renewal preserves the listener; a changed grant, reduced scope or failed credential resolution still closes it. Other authentication modes keep exact-token binding. Discovery-cache identity and token refresh behavior are unchanged.
The server declaration now names the existing SDK class directly so handler registration is typed. This uses the same runtime class, with no server lifecycle change
Pre-Submission checklist
Verification
At
6d543461dcc1bd28def8a339474718dc77d8e00b, 169 affected coverage tests, three final renewal integration cases and two supplemental controls passed. The broader client/credential unit run passed 654 cases, with one existing isolated-interpreter environment mismatch. Canonical lint and type gates pass. The repair covers 11/11 changed executable lines. The complete PR covers 188/190, 98.95%, with subscription branches 27/28. The existing gaps are defensive catalog-page exhaustion and the post-cancellation fallback. No exclusions or budget increasesSeven standalone source-bound SDK replays passed, covering all four notification types, normal M2M renewal, scope reduction and credential-resolution failure. Routine renewal now preserves delivery. Reduced scopes and failed credentials close the listener. AWS signing and discovery-cache fingerprints retain their existing behavior
Independent Devin execution used source builds at base
163c474de8101e0e2d319107f91b24f6c64a935f, pre-repair control2066acb93e61ea6565b6ff25e10c0566d2dd0c13, and historical head6d543461dcc1bd28def8a339474718dc77d8e00b. The routine-renewal scenario failed on the control withSubscriptionLostand passed on head; both denial controls passed on both builds. All 22 subscription integration cases passed on head and were unsupported at the original base. Independent real-HTTP controls confirmed event delivery, identity isolation, idle revocation, credential scoping, setup races and cleanup. Progress/cancellation behavior matched the parent. Those historical results are supplemented by the current-head evidence linked above.Completed current-tip Codecov confirms 98.39% patch coverage; local executable-line coverage is 368/374 (98.4%). Veria found no security issues; Bugbot found no issues, and all review threads are resolved. Relevant CI checks pass. The OSV scan still fails for existing mlflow 3.15.0 in unchanged
uv.lock(PYSEC-2026-3865), outside this ticket. Greptile is disabled, LiteReview is deferred by the author, and the contributor agreement is confirmed signedScreenshots / Proof of Fix
Use the standalone script below with the existing locked Python environment.
$SOURCEpoints at the heading's source SHA and$OUTis an empty task scratch directory. It starts an actual SDK upstream and source-built gateway, caps logs at 10 MiB, prints the observed events/listings, and stops both services. No database or paid model calls are neededBefore (163c474)
Tool catalog change
python replay_subscriptions.py "$SOURCE" "$OUT/tools" toolsMethod not foundbefore acknowledgmentPrompt catalog change
python replay_subscriptions.py "$SOURCE" "$OUT/prompts" promptsMethod not foundbefore acknowledgmentResource catalog change
python replay_subscriptions.py "$SOURCE" "$OUT/resources" resourcesMethod not foundbefore acknowledgmentResource content change
python replay_subscriptions.py "$SOURCE" "$OUT/updated" updatedMethod not foundbefore acknowledgmentAfter (6d54346)
Tool catalog change
python replay_subscriptions.py "$SOURCE" "$OUT/tools" toolsToolsListChanged(), then peer-added appears in tools/listand upstream disconnect cleanupPrompt catalog change
python replay_subscriptions.py "$SOURCE" "$OUT/prompts" promptsPromptsListChanged(), then peer-added appears in prompts/listand upstream disconnect cleanupResource catalog change
python replay_subscriptions.py "$SOURCE" "$OUT/resources" resourcesResourcesListChanged(), then test://added appears in resources/listand upstream disconnect cleanupResource content change
python replay_subscriptions.py "$SOURCE" "$OUT/updated" updatedResourceUpdated(uri=test://value), honoring only the requested URIand upstream disconnect cleanupAdditional head replays cover same-key user/team/organization/end-user reassignment, idle revocation, two-upstream credential scoping, setup-time changes, discovered metadata updates and actual configuration changes. Run the script with
toolsand respectivelyidentity,team,org,end-user,idle,fanout,setup-race,metadataorconfig-change. Reassignment, revocation and configuration changes close the listener. Setup changes and metadata updates preserve delivery. Fanout captures no caller bearer on either listeners or catalog requestsreplay_subscriptions.py
Managed renewal regression
Subscription validation now uses the existing managed M2M grant identity and resolved scopes instead of the changing access token. URL, other headers, caller authorization and server configuration remain checked. Discovery-cache identity is unchanged. Caller-supplied and per-user OAuth credentials retain exact-token comparison
Before (2066acb)
python replay_managed_renewal.py "$SOURCE" "$OUT/renewal" renewalusing the script belowSubscriptionLost, and the gateway reportsSubscription authorization or upstream configuration changedAfter (6d54346)
ToolsListChangedis delivered. The added tool appears in the next listingrenewal-scopesandrenewal-failedinstead ofrenewal. Both close the listener before delivering an event, preserving authorization controlsreplay_managed_renewal.py
Type
New Feature
Caveats
Medium
Low
Final Attestation
Note
High Risk
Long-lived subscription tasks touch auth, outbound credentials, and multi-upstream fan-out with reauthorization on every event—bugs could leak notifications across callers or hold upstream connections incorrectly.
Overview
Adds MCP subscription relay on the experimental gateway so clients can use
subscriptions/listen(and legacy notification/resource subscribe paths) to receive upstream catalog and resource events without polling.A new
GatewaySubscriptionslayer opens authorized upstream listeners per caller, merges fan-out across allowed servers, refreshes gateway catalogs when listings change, and re-checks auth before each delivery and on idle. Listeners are capped (global and per-caller), bound to caller identity, and torn down on revocation, credential/config drift, or upstream disconnect. Legacy clients get bridged vianotifications/initialized, resource subscribe/unsubscribe, and SSE request context; modern 2026-07-28 uses the SDK subscription flow.MCPClientnow accepts anon_notificationhook onrun_with_sessionand exposessubscription_auth_fingerprint(). Managed client-credentials grants get a stablesubscription_identity(config + granted scopes) so token renewal does not drop listeners; discovery fingerprint behavior is unchanged.Reviewed by Cursor Bugbot for commit 00a41f4. Bugbot is set up for automated code reviews on this repo. Configure here.