Repository navigation
Add streamable HTTP bridge for the aitools MCP proxy - #7540
Draft
simonfaltum wants to merge 7 commits into
Draft
simonfaltum wants to merge 7 commits into
simonfaltum wants to merge 7 commits into
Conversation
simonfaltum
force-pushed
the
aitools-mcp/06a-bridge
branch
from
November 12, 2026 12:12
beafb3d to
ad50549
Compare
Contributor
|
Commit: Regression test reportSelected 10 changed tests (limit=20, 0 not selected) 10 tests: regression=10 unreleased=0 coverage=0 failing=0
TestAccept/cmd/aitools/mcp/add-agent-not-installed: branch ✅ | main (8e70c8b) ❌ | latest (v1.26.0) ❌main (8e70c8b): latest (v1.26.0): TestAccept/cmd/aitools/mcp/add-default-config: branch ✅ | main (8e70c8b) ❌ | latest (v1.26.0) ❌main (8e70c8b): latest (v1.26.0): TestAccept/cmd/aitools/mcp/add-text: branch ✅ | main (8e70c8b) ❌ | latest (v1.26.0) ❌main (8e70c8b): latest (v1.26.0): TestAccept/cmd/aitools/mcp/add-two-agents: branch ✅ | main (8e70c8b) ❌ | latest (v1.26.0) ❌main (8e70c8b): latest (v1.26.0): TestAccept/cmd/aitools/mcp/add-two-profiles: branch ✅ | main (8e70c8b) ❌ | latest (v1.26.0) ❌main (8e70c8b): latest (v1.26.0): 5 more failure details omitted, see the full report in the run. |
simonfaltum
changed the base branch from
aitools-mcp/04-add
to
aitools-mcp/05-list-remove
November 12, 2026 12:25
simonfaltum
force-pushed
the
aitools-mcp/06a-bridge
branch
from
November 12, 2026 12:25
ad50549 to
4ecc28f
Compare
This was referenced Nov 12, 2026
simonfaltum
force-pushed
the
aitools-mcp/05-list-remove
branch
from
November 12, 2026 14:35
7db8c31 to
9967822
Compare
simonfaltum
force-pushed
the
aitools-mcp/06a-bridge
branch
from
November 12, 2026 14:36
4ecc28f to
2f43e8a
Compare
simonfaltum
force-pushed
the
aitools-mcp/05-list-remove
branch
from
November 12, 2026 17:07
9967822 to
3d361ee
Compare
simonfaltum
force-pushed
the
aitools-mcp/06a-bridge
branch
from
November 12, 2026 17:08
2f43e8a to
3c43783
Compare
simonfaltum
force-pushed
the
aitools-mcp/05-list-remove
branch
2 times, most recently
from
November 12, 2026 20:05
6e86c42 to
30b949b
Compare
simonfaltum
force-pushed
the
aitools-mcp/06a-bridge
branch
2 times, most recently
from
November 12, 2026 22:00
4688f64 to
ed4190f
Compare
Adds libs/aitools/mcp/proxy, a bridge between MCP stdio (newline-delimited JSON-RPC on stdin and stdout) and a streamable HTTP MCP endpoint. Nothing calls it yet; the `aitools mcp serve` command comes in a later change. Co-authored-by: Isaac <no-reply@databricks.com>
- A stream that ends, is cut, or idles after only notifications now answers the request with -32000. Only a response with the request's id counts as an answer. - A non-2xx body passes through only when it is the response to this request. Other bodies become "HTTP <status>: <message>", with the message taken from a Databricks error body or a single-line excerpt. A failed notification writes nothing. - MCP-Protocol-Version is the version the server picked in the initialize result, not the one the client asked for. - Notifications and client responses are posted before the next stdin line is read, so notifications/initialized reaches the server before the requests after it. Requests stay concurrent. - A 404 for a request that carried Mcp-Session-Id starts a new session: the client's initialize and notifications/initialized are replayed silently, then the request is posted once more. - SSE events with empty data (the priming event) are skipped. - Hook output with line breaks is compacted, so every message stays on one stdout line. - The synthesized error reaches hooks with a context the idle timeout has not cancelled. A cancelled request is neither logged nor answered. - A stdin line over 64 MiB ends Run with the limit named. - Valid JSON that is not an object gets -32600 Invalid Request. - Contexts are passed as arguments, not stored in structs. Named constants replace repeated method and member names. Co-authored-by: Isaac <no-reply@databricks.com>
A session restart no longer clears the session before its replay. The session and protocol version a replay negotiates are published only when the whole replay succeeds, so a failed replay is retried on the next 404. Requests read the session once per send, and a request that hits an ended session waits for the rejoin. A 404 is treated as an ended session only when its body is not the server's response to the request. Responses are matched by the decoded value of the id, and the response stream is closed once the response is written. Notifications are posted in order, but stdin is no longer blocked on them: a request waits at most notificationWait for the notification before it. Stdin EOF and cancellation are seen while a notification is pending. The idle error reaches hooks with a context that the idle timeout does not cancel. A 2xx JSON body that is not the response to the request fails the request, and a notification's JSON body is not written. Co-authored-by: Isaac <no-reply@databricks.com>
No behavior change. The session replay is a function that posts the saved initialize and notifications/initialized and returns the session and protocol version they establish, instead of an exchange with a replay mode. Hooks receive the request context as an argument; exchange no longer stores it. Shutdown cancels and waits once after the grace period. The Accept header name is a constant, and isRequest compares the null id by bytes. Co-authored-by: Isaac <no-reply@databricks.com>
A replayed initialize answered with a JSON-RPC error no longer counts as a replay that succeeded: the session needs a result. The session id is taken only from the initialize response, so a late answer on an ended session cannot replace the new one. A 404 ends the session unless its body is the result for the request, and only requests start a new session. Notifications and client responses are not reposted after a rejoin. SSE events are delivered only when their type is message or empty, so a keepalive no longer ends a request. The media type is matched without regard to case. The upstream client takes an optional Transport, so a profile's TLS settings apply. It does not follow redirects: a 3xx is a failed response. A notification's gate closes after notificationWait from when the notification starts, and a request waits only for the gate or its context. Request ids compare by exact numeric value, so integers above 2^53 stay distinct. A retried request reports status 0 to the hooks when it fails before a response. A rejoin waiting for the slot honors the request's context. A failed replay deletes the session it created. A 2xx body is limited to 64 MiB, and an error body is read up to 1 MiB and excerpted. Co-authored-by: Isaac <no-reply@databricks.com>
No behavior change, except that an id number is keyed from its text, which keeps a large exponent short. Upstream message parsing and the response check are one helper each, the replay and the session DELETE share their error paths, the unused rejoin branch for a missing initialize is gone, and doc comments are trimmed. The rejoin and idle-watchdog docs say what the replay restores and when the watchdog starts. Co-authored-by: Isaac <no-reply@databricks.com>
Each change has a test. The SSE reader limits an event's data to 64 MiB, reads bare CR and CRLF line endings and a leading BOM, and answers a ping the server sends during a session replay. A 404 whose body is the server's JSON-RPC error passes through when the request carried no session id. The session id and protocol version come only from an initialize answer with a result, and a session that a new initialize replaces is deleted. A notification's gate opens notificationWait after its POST starts. A hook output is checked before any of it is written, and a hook error on a message other than the response is logged and dropped. A notification's answer is closed unread, not forwarded. The stale 404 response is closed before the replay. Bridge.Transport nil now means http.DefaultTransport, with no 10 s connect timeout. A test that relied on a 100 ms idle timeout now uses 1 s. Co-authored-by: Isaac <no-reply@databricks.com>
simonfaltum
force-pushed
the
aitools-mcp/05-list-remove
branch
from
November 13, 2026 15:05
eb0b033 to
95c5e54
Compare
simonfaltum
force-pushed
the
aitools-mcp/06a-bridge
branch
from
November 13, 2026 15:05
6634449 to
5c42df0
Compare
This branch has not been deployed
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.
This is part of a stack, on top of #7549, that adds the hidden
databricks aitools mcpcommand group. This PR adds the stdio-to-HTTP transport for theservecommand. Nothing calls it yet.Changes
Bridge.RunPOSTs each stdin message's exact bytes to the endpoint and writes each answer to stdout as one line. Requests run concurrently. A stalled notification holds later messages for at most 2 s.-32000error. A non-2xx body passes through when it is that request's response, such as-32006under 401. So does a 404 error for a request that had no session id.initializeandnotifications/initializedare replayed silently, a server ping during the replay is answered, and the old session is replaced only after the replay succeeds.Bridge.Transport. Nil meanshttp.DefaultTransport.Why
serverelays MCP responses over stdio. The package is separate so an in-process fake endpoint can test it. A probe of a Databricks managed MCP endpoint returnedMcp-Session-Idoninitialize, andtools/listworked with or without the session headers. The bridge sends both, as the MCP transports specification requires. The transport is injectable so that a profile's TLS settings reach the upstream client.Decisions to review
Transportishttp.DefaultTransport, with its 30 s dial timeout. The 10 s connect timeout moves to the transport thatservebuilds, in the next PR.initializeandnotifications/initialized. Logging levels and subscriptions set later are lost on a session restart.Tests
TestRunAnswersPingDuringReplay,TestRunClosesStaleResponseBeforeReplay,TestRunPassesThroughErrorOf404WithoutSession,TestRunDeletesSessionReplacedByInitialize,TestReadEvents(CR, BOM),TestReadEventsDispatchesBareCRBeforeNextBytes,TestReadEventsLimitsEventData.TestRunHoldsRequestUntilNotificationWaitFromItsPost,TestRunWritesNothingWhenHookOutputIsInvalid,TestIDKeyComparesNumbersByValue.go test -race -count=5 ./libs/aitools/mcp/proxy/...,./task test-exp-aitools(1472 tests, 5 skipped),GOOS=windows go vet, golangci-lint, and./task checks.-32042, which come in a later change. The TLS settings and connect timeout are not exercised, sinceservedoes not build the transport yet. No acceptance test, because no command is wired.This pull request and its description were written by Isaac.