Commit 292ebb6
authored
feat(server): add transport-agnostic Handle entry point (#851)
* feat(server): add transport-agnostic Handle entry point
Introduces a small abstraction layer over net/http so StreamableHTTPServer
can be driven from frameworks like fasthttp/fiber without going through
the buffering net/http<->fasthttp adaptor.
Two new exported types:
- HTTPRequest: framework-neutral view of an MCP HTTP request
(Method, URL, Header, Body, Context).
- HTTPResponseWriter: minimum surface needed to write a streamable MCP
HTTP response, including a CanStream() capability
check that lets non-streaming transports gracefully
skip SSE upgrades.
New entry point:
func (s *StreamableHTTPServer) Handle(w HTTPResponseWriter, r *HTTPRequest)
ServeHTTP is refactored into a thin wrapper around Handle that builds a
default httpResponseWriterAdapter (which satisfies HTTPResponseWriter
and forwards Flush to http.Flusher when present) and an HTTPRequest
preserving the original *http.Request for legacy options like
WithHTTPContextFunc and SessionIdManagerResolver.
Backwards-compatibility:
- All existing public APIs (NewStreamableHTTPServer, ServeHTTP, Start,
Shutdown, every option, every session interface) are unchanged.
- WithHTTPContextFunc is honored from both ServeHTTP and Handle. Under
Handle it receives a synthetic *http.Request derived from the
HTTPRequest so existing options keep working.
- SessionIdManagerResolver still takes *http.Request; Handle constructs
a synthetic request only when a custom resolver is configured.
- When the configured response writer cannot stream (CanStream==false),
GET is rejected with 405 Method Not Allowed (same as today for
non-flushable writers) and POST stays in buffered application/json
mode, matching the new explicit contract.
Closes the integration gap reported in #611 while leaving the existing
adaptor.HTTPHandler workaround fully functional.
* docs(server): document Handle entry point for non-net/http frameworks
- README: add subsection under Transports introducing Handle, HTTPRequest,
and HTTPResponseWriter with a link to the full HTTP transport guide.
- www/docs/pages/transports/http.mdx: add an Embedding in Non-net/http
Frameworks section with a ServeHTTP-vs-Handle comparison table, the
full API surface, the CanStream() streaming-capability contract, a
concrete fasthttp adapter snippet, and behavior notes covering CORS,
protected-resource-metadata, WithHTTPContextFunc, and BC guarantees.1 parent 0678053 commit 292ebb6
5 files changed
Lines changed: 804 additions & 64 deletions
File tree
- server
- www/docs/pages/transports
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
657 | 657 | | |
658 | 658 | | |
659 | 659 | | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
660 | 684 | | |
661 | 685 | | |
662 | 686 | | |
| |||
0 commit comments