mcp: export jsonResponse field

Exporting StreamableHTTPOptions.JSONResponse is helpful for some users behind proxies that don't work well with text/event-stream.

For #211

Co-authored-by: ccpro10 <co1797249167@gmail.com>
This commit is contained in:
ccpro 2025-09-03 23:35:19 +08:00 • committed by GitHub
commit 1c20560beb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 5 additions and 5 deletions

View file

@ -72,8 +72,8 @@ type StreamableHTTPOptions struct {
// TODO: support session retention (?)
// jsonResponse is forwarded to StreamableServerTransport.jsonResponse.
jsonResponse bool
// JSONResponse is forwarded to StreamableServerTransport.jsonResponse.
JSONResponse bool
}
// NewStreamableHTTPHandler returns a new [StreamableHTTPHandler].
@ -233,7 +233,7 @@ func (h *StreamableHTTPHandler) ServeHTTP(w http.ResponseWriter, req *http.Reque
transport = &StreamableServerTransport{
SessionID: sessionID,
Stateless: h.opts.Stateless,
jsonResponse: h.opts.jsonResponse,
jsonResponse: h.opts.JSONResponse,
}
// To support stateless mode, we initialize the session with a default
@ -487,7 +487,7 @@ type stream struct {
// jsonResponse records whether this stream should respond with application/json
// instead of text/event-stream.
//
// See [StreamableServerTransportOptions.jsonResponse].
// See [StreamableServerTransportOptions.JSONResponse].
jsonResponse bool
// signal is a 1-buffered channel, owned by an incoming HTTP request, that signals

View file

@ -84,7 +84,7 @@ func TestStreamableTransports(t *testing.T) {
// Start an httptest.Server with the StreamableHTTPHandler, wrapped in a
// cookie-checking middleware.
handler := NewStreamableHTTPHandler(func(req *http.Request) *Server { return server }, &StreamableHTTPOptions{
jsonResponse: useJSON,
JSONResponse: useJSON,
})
var (