MCPcopy Create free account
hub / github.com/modelcontextprotocol/go-sdk / NewStreamableHTTPHandler

Function NewStreamableHTTPHandler

mcp/streamable.go:194–210  ·  view source on GitHub ↗

NewStreamableHTTPHandler returns a new [StreamableHTTPHandler]. The getServer function is used to create or look up servers for new sessions. It is OK for getServer to return the same server multiple times. If getServer returns nil, a 400 Bad Request will be served.

(getServer func(*http.Request) *Server, opts *StreamableHTTPOptions)

Source from the content-addressed store, hash-verified

192// sessions. It is OK for getServer to return the same server multiple times.
193// If getServer returns nil, a 400 Bad Request will be served.
194func NewStreamableHTTPHandler(getServer func(*http.Request) *Server, opts *StreamableHTTPOptions) *StreamableHTTPHandler {
195 h := &StreamableHTTPHandler{
196 getServer: getServer,
197 sessions: make(map[string]*sessionInfo),
198 }
199 if opts != nil {
200 h.opts = *opts
201 }
202
203 h.opts.Logger = ensureLogger(h.opts.Logger)
204
205 if h.opts.CrossOriginProtection == nil && enableoriginverification == "1" {
206 h.opts.CrossOriginProtection = &http.CrossOriginProtection{}
207 }
208
209 return h
210}
211
212// closeAll closes all ongoing sessions, for tests.
213//

Callers 15

runServerFunction · 0.92
mainFunction · 0.92
mainFunction · 0.92
childFunction · 0.92
mainFunction · 0.92
runBackendServerFunction · 0.92
runProxyServerFunction · 0.92
mainFunction · 0.92

Calls 1

ensureLoggerFunction · 0.85

Used in the wild real call sites across dependent graphs

searching dependent graphs…