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

Function NewSSEHandler

mcp/sse.go:83–94  ·  view source on GitHub ↗

NewSSEHandler returns a new [SSEHandler] that creates and manages MCP sessions created via incoming HTTP requests. Sessions are created when the client issues a GET request to the server, which must accept text/event-stream responses (server-sent events). For each such request, a new [SSEServerTran

(getServer func(request *http.Request) *Server, opts *SSEOptions)

Source from the content-addressed store, hash-verified

81// request, or reuse an existing server. If it returns nil, the handler
82// will return a 400 Bad Request.
83func NewSSEHandler(getServer func(request *http.Request) *Server, opts *SSEOptions) *SSEHandler {
84 s := &SSEHandler{
85 getServer: getServer,
86 sessions: make(map[string]*SSEServerTransport),
87 }
88
89 if opts != nil {
90 s.opts = *opts
91 }
92
93 return s
94}
95
96// A SSEServerTransport is a logical SSE session created through a hanging GET
97// request.

Callers 5

ExampleSSEHandlerFunction · 0.92
mainFunction · 0.92
TestSSEServerFunction · 0.85
TestSSE405AllowHeaderFunction · 0.85

Calls

no outgoing calls

Tested by 4

ExampleSSEHandlerFunction · 0.74
TestSSEServerFunction · 0.68
TestSSE405AllowHeaderFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…