go-sdk/mcp
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Robert Findley 104d39c609
mcp: allow disabling stream replay; disable by default (#585)
This CL implements two changes that must be logically connected.

The first is to provide a mechanism for disabling stream replay.
Previously, our documentation stated that if
StreamableServerTransport.EventStore was nil, a default in-memory event
store would be used. In that case, there would be no way to completely
disable stream replay, and as described in #576, there are many cases
where replay is undesirable.

But of course changing the behavior of the transport zero value
implicitly affects its default behavior, and so this CL also implements
the proposal #580: stream replay is disabled by default.

Implementing this change required a significant refactoring, as
previously we were relying on the event store for serialized message
delivery from the JSON-RPC layer to the MCP layer: the connection would
write to the event store, and independently the stream (be it an
incoming POST or replay GET) would iterate and serve messages in the
stream.

In order to achieve the goals of this CL, it was necessary to decouple
storage from delivery. The 'stream' abstraction now tracks a delivery
callback that writes straight to the HTTP response. It would have been
convenient to store the ongoing http.ResponseWriter directly in the
stream (this is how typescript does it), but due to the design of our
EventStore API, only the HTTP handler knows the next event index, so a
'deliver' abstraction was an unfortunate requirement (suggestions for
how to further simplify this are welcome).

More simplification is possible: in particular, as a result of this
refactoring it should be entirely possible to clean up streams once
we've received all responses. Any replay would only need access to the
EventStore, if at all. This is left to a follow-up CL, to limit this
already significant change.

Furthermore, a nice consequence of this refactoring is that, when not
using event storage, servers can get synchronous feedback that message
delivery failed, which should avoid unnecessary work. We can
additionally cancel ongoing requests on early client termination, but
that is also left to a follow-up CL.

Throughout, the terminology 'standalone SSE stream' replaced 'hanging
GET' when referring to the non-replay GET request issued by the client.
This is consistent with other SDKs.

Fixes #576
Updates #580
2025-10-16 12:11:49 -04:00
..
testdata mcp: propertly validate against JSON, independent of Go values 2025-09-12 10:50:19 -04:00
client.go mcp: unexport incidentally exported error codes (#536) 2025-09-26 14:04:28 -04:00
client_example_test.go mcp: fix goroutine leaks in unit tests (#496) 2025-10-16 11:13:30 -04:00
client_list_test.go mcp: allow any value for schemas (#517) 2025-09-26 11:55:54 -04:00
client_test.go mcp: remove references to ClientRequest[T] for concrete T (#343) 2025-08-21 15:24:58 -04:00
cmd.go mcp: speed up TestCommandTransportDuration 2025-09-12 12:00:29 -04:00
cmd_export_test.go mcp: speed up TestCommandTransportDuration 2025-09-12 12:00:29 -04:00
cmd_test.go mcp: fix goroutine leaks in unit tests (#496) 2025-10-16 11:13:30 -04:00
conformance_go124_test.go internal/mcp: update protocol versions 2025-06-18 08:11:16 -07:00
conformance_go125_test.go internal/mcp: update protocol versions 2025-06-18 08:11:16 -07:00
conformance_test.go mcp: propertly validate against JSON, independent of Go values 2025-09-12 10:50:19 -04:00
content.go many: minor cosmetic changes (#529) 2025-09-25 16:06:24 -04:00
content_nil_test.go mcp: add CallToolResult.getError (#481) 2025-09-18 08:08:23 -04:00
content_test.go mcp: don't omit required fields in ImageContent and AudioContent (#95) 2025-07-19 17:08:56 -04:00
event.go mcp: allow disabling stream replay; disable by default (#585) 2025-10-16 12:11:49 -04:00
event_test.go mcp: remove the StreamID type (#490) 2025-09-18 12:01:07 -04:00
features.go mcp: minor cleanup of some TODOs (#332) 2025-08-20 12:55:19 -04:00
features_test.go mcp: change tool handler design (#325) 2025-08-20 19:36:34 -04:00
logging.go mcp/server: enable server logging (#501) 2025-10-02 14:44:32 -04:00
mcp.go mcp: fix inaccurate package doc (#534) 2025-09-26 14:16:10 -04:00
mcp_example_test.go docs: add feature and troubleshooting documentation (#463) 2025-09-16 11:13:40 -04:00
mcp_test.go mcp: fix goroutine leaks in unit tests (#496) 2025-10-16 11:13:30 -04:00
prompt.go mcp: align PromptHandler args with other handlers (#348) 2025-08-22 10:44:05 -04:00
protocol.go mcp: allow any value for schemas (#517) 2025-09-26 11:55:54 -04:00
protocol_test.go mcp: add CallToolResult.getError (#481) 2025-09-18 08:08:23 -04:00
requests.go mcp: statically type the server-side tool params (#378) 2025-08-30 08:16:06 -04:00
resource.go mcp: unexport incidentally exported error codes (#536) 2025-09-26 14:04:28 -04:00
resource_go124.go internal/mcp: add the FileResourceHandler method 2025-05-19 11:15:23 -07:00
resource_pre_go124.go internal/mcp: add the FileResourceHandler method 2025-05-19 11:15:23 -07:00
resource_test.go mcp/Resource: Refactor URI Template Matching with uritemplate Library (#100) 2025-07-08 15:52:54 -04:00
server.go mcp: fix goroutine leaks in unit tests (#496) 2025-10-16 11:13:30 -04:00
server_example_test.go doc: document logging (#497) 2025-09-19 11:58:58 -04:00
server_test.go mcp: allow any value for schemas (#517) 2025-09-26 11:55:54 -04:00
session.go mcp: support stateless streamable sessions (#277) 2025-08-11 16:43:46 -04:00
shared.go mcp: unexport incidentally exported error codes (#536) 2025-09-26 14:04:28 -04:00
shared_test.go all: remove ServerRequest[T] for concrete T (#342) 2025-08-21 12:10:53 -04:00
sse.go SSE: Add support for SSE handler options (#508) 2025-09-19 13:01:57 -04:00
sse_example_test.go SSE: Add support for SSE handler options (#508) 2025-09-19 13:01:57 -04:00
sse_test.go SSE: Add support for SSE handler options (#508) 2025-09-19 13:01:57 -04:00
streamable.go mcp: allow disabling stream replay; disable by default (#585) 2025-10-16 12:11:49 -04:00
streamable_bench_test.go mcp: update to jsonschema that does not validate structs (#511) 2025-09-22 15:28:04 -04:00
streamable_client_test.go mcp: allow disabling stream replay; disable by default (#585) 2025-10-16 12:11:49 -04:00
streamable_example_test.go mcp: fix goroutine leaks in unit tests (#496) 2025-10-16 11:13:30 -04:00
streamable_test.go mcp: allow disabling stream replay; disable by default (#585) 2025-10-16 12:11:49 -04:00
tool.go mcp: propertly validate against JSON, independent of Go values 2025-09-12 10:50:19 -04:00
tool_example_test.go mcp: allow any value for schemas (#517) 2025-09-26 11:55:54 -04:00
tool_test.go mcp: unexport incidentally exported error codes (#536) 2025-09-26 14:04:28 -04:00
transport.go mcp: allow disabling stream replay; disable by default (#585) 2025-10-16 12:11:49 -04:00
transport_example_test.go mcp: fix goroutine leaks in unit tests (#496) 2025-10-16 11:13:30 -04:00
transport_test.go mcp: fix goroutine leaks in unit tests (#496) 2025-10-16 11:13:30 -04:00
util.go mcp: allow any value for schemas (#517) 2025-09-26 11:55:54 -04:00