Repository navigation
fix(upstream): hold a GET stream for streamable-HTTP upstreams that advertise tools.listChanged (#1910) - #1915
Merged
Merged
Conversation
…dvertise tools.listChanged (#1910) A streamable-HTTP upstream can send notifications/tools/list_changed outside a request only on a standalone GET stream, and mcpproxy never opened one, so tool changes on HTTP upstreams waited for the 5-minute discovery poll. mcpproxy now runs its own listener (internal/transport/listen_stream.go) instead of mcp-go's WithContinuousListening, which is fixed before initialize (so it cannot depend on the advertised capability), runs on the connect attempt's context and the basic client's 180s timeout, retries every second forever on anything but 405/404 with Error logs, and stops for good after a 404. - Opened only when initialize advertises tools.listChanged, on the plain and OAuth paths (session id, protocol version, static headers and the transport's own OAuth bearer). - 405/400/406/401/403/other 4xx or a non-event-stream answer: one request, one INFO line, then the discovery poll covers it. 404: stops until a session re-initialize or reconnect. Network errors, 408, 429, 5xx and streams that end at once back off exponentially (1s to 2m, jittered). - Own http.Client with no total timeout; POST clients are unchanged. - Lifecycle in core (list_changed_stream.go): context from the instance gate (retirement ends it), stopped by Disconnect and the reconnect path, moved to the new session by ReinitializeSession after the old listener exits, and never restarted for a connection Disconnect released. - A ping request on the stream is answered; other requests get method-not-found. Test fixtures that closed an in-process upstream before disconnecting the client (httptest.Server.Close and http.Server.Shutdown wait for the held GET) now cut client connections first or use Close. Docs: docs/api/mcp-protocol.md, docs/features/search-discovery.md.
…dispatch; a late re-init failure ends only its own stream (#1910) The listener queued nothing and ran the tools/prompts-changed handlers on its own goroutine. managed.Client holds mc.mu across core Disconnect and those callbacks take mc.mu.RLock, so Disconnect (stopListChangedStream with wait) could stall for the full 5s stop timeout while holding mc.mu. Notifications now go to a non-blocking, per-method coalescing queue drained by a separate dispatch goroutine; a stop waits only for the reader. endListChangedStream now takes the re-initialized client and does nothing unless the stream still belongs to it, matching restartListChangedStream, so a late re-init failure on an old connection cannot end the stream of the connection a reconnect put in its place.
…redirects, never blocks draining a refusal, answers on its own session (#1910) - An SSE event that grows past 1 MiB across many data: lines is dropped whole instead of accumulating without bound. - A cross-origin redirect ends the stream: static headers such as an API key are not sent to the other origin (Go strips only Authorization and Cookie). Polling covers the server. - The response body is closed without draining, so a refusal whose body never finishes cannot hold the listener. - A request received on the stream is answered with the session id that opened the stream, not the transport's current one after a re-init. Raised by cross-review.
…notifications (#1910) Notifications the dispatcher ignores (logging, progress, resources) are no longer queued, so they cannot fill the bounded queue while a callback is blocked and drop a later tools/list_changed. Raised by cross-review.
…T stream redirect and jitter (#1910) The scope-latency workflow copies only scope_latency_test.go onto the merge-base checkout, so it cannot call the new closeHTTPFixture helper. Raised by cross-review.
Dumbris
enabled auto-merge (squash)
November 16, 2026 08:52
Deploying mcpproxy-docs with
|
| Latest commit: |
8fac375
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://3a02112c.mcpproxy-docs.pages.dev |
| Branch Preview URL: | https://fix-1910-http-list-changed.mcpproxy-docs.pages.dev |
…ort; refused-GET test counts per session (#1910) The listener's transport was cloned from http.DefaultTransport before baseTransport put it behind the instance's dial gate. It is now an explicit *http.Transport, so the Spec 116 FR-024a write-site check holds by construction. The refused-GET test asserts one GET per session, so a second connect on a slow CI host (a new session) is not mistaken for a retry.
This was referenced Nov 16, 2026
The GET stream opens asynchronously after connect, so a test that closes its fixture right after connecting could see the GET arrive after a single CloseClientConnections; httptest.Server.Close then waited on it forever (CI: TestClient_GetPrompt_UpstreamError_ReturnsWrappedError hit the 20m timeout). Close now runs in the background, which closes the listener first, while open connections are cut until it returns.
…1910) http.Server.Shutdown waits for every connection to go idle, and the runtime's standalone GET stream to the upstream never does, so the cleanup hung (Windows CI: TestAgentTokenRateLimit_EndToEnd hit the 20m timeout).
Contributor
📦 Build ArtifactsWorkflow Run: View Run Available Artifacts
How to DownloadOption 1: GitHub Web UI (easiest)
Option 2: GitHub CLI gh run download 43851996951 --repo smart-mcp-proxy/mcpproxy-go
|
|
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
Dumbris
added a commit
that referenced
this pull request
Nov 18, 2026
…ver the real push TestToolsListChanged_TrustedServer_DoesNotJoinPreChangeList failed on Ubuntu (job 135193801169): expected "changed", got "approved", in 0.27s. Its stage server advertised tools.listChanged. Since #1915 (GH #1910) that gives the client a standing GET stream, so the test's own DeleteTools/AddTool also pushed a real list_changed: two notification-driven runs, not one. When the real push took the per-server discovery marker first, the test's manual onUpstreamToolsListChanged was coalesced and returned at once, and the record was read before the owning run had stored "changed". A 300ms head start for the real push reproduces it 3/3. The owning run was fresh and did store "changed", so production behaviour is correct. The test's server no longer advertises the capability, so the manual call is the only notification. The test now: - marks its own run through a context value and requires that run to have happened, instead of counting every run; - arms only after connect-time discovery has run and released the marker, since that discovery could otherwise absorb the notification. With the head start the test passes. Reverting the fix fails it on the own-run check, and reintroducing the joining bug (a fresh list adopting the in-flight one) fails it on the status. TestToolsListChanged_AdvertisedPush_HoldsChangedContract covers the transport path the first test now avoids. A trusted manual-mode upstream advertises the capability, changes its approved tool and pushes the notification itself. The test waits for discovery to settle, then requires "changed", the old ApprovedHash kept and the previous description recorded. It fails without the capability and with trust_mode auto. Test-only. Both tests pass 50/50 under -race, 20/20 with GOMAXPROCS=1, and 10/10 with -tags server -shuffle=on.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1910
Problem
A streamable-HTTP upstream delivers server-initiated messages,
notifications/tools/list_changedamong them, only on a standaloneGETstream that the client keeps open. mcpproxy never opened one, so tool changes on HTTP upstreams waited for the discovery poll.Fix
mcpproxy now holds one
GETstream per connection, and only for an upstream whoseinitializeresult advertisescapabilities.tools.listChanged. Other upstreams get noGETand no extra held connection, which matters for scale-to-zero hosts.Why not mcp-go's
WithContinuousListening:initialize, so it cannot depend on the advertised capability.The listener is
internal/transport/listen_stream.go; its lifecycle is ininternal/upstream/core/list_changed_stream.go.Responses that end the stream after one request: 405, 400, 406, 401, 403, other 4xx, a cross-origin redirect, a non-event-stream 2xx, or OAuth authorization-required. mcpproxy logs one INFO line and polling covers the server from then on.
Session lost: a 404 stops the stream; the next re-init or reconnect opens a new one.
Transient failures: network errors, 408, 429, 5xx, and streams that end within 30s back off from 1s to 2m with ±25% jitter, honouring
Retry-After.Client: the stream has its own
http.Client, with no total timeout and a 30s response-header timeout. It never follows a redirect to another origin, so static headers are not leaked. Event size is bounded at 1 MiB.Lifecycle:
Dispatch:
list_changed. A separate goroutine drains it, so Disconnect never waits on a callback blocked on the managed lock.pingon the stream is answered on the stream's own session; any other request gets method-not-found.Test fixtures: an in-process fixture with a held
GETmakeshttptest.Server.Closeandhttp.Server.Shutdownwait. Fixtures now cut client connections first, through a per-packagecloseHTTPFixturehelper. Production code has no test switch.Docs:
docs/api/mcp-protocol.md(Tool Change Notifications) anddocs/features/search-discovery.md.Tests
internal/transport/listen_stream*_test.go:internal/upstream/core/list_changed_stream_test.go:go test -raceon./internal/transport/,./internal/upstream/...and./internal/runtime/...-tags serverrace overinternal/server,servereditionandhttpapiwith the CI skip list./scripts/test-api-e2e.sh--build-tags servergpt-6.1-sol, in three chunks: