Skip to content

Commit 5a4c9a5

Browse files
committed
Update to use new configuration
1 parent 61dd0fb commit 5a4c9a5

File tree

1 file changed

+7
-40
lines changed

1 file changed

+7
-40
lines changed

server/streamable_http.go

Lines changed: 7 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -168,59 +168,39 @@ func (s *InMemoryEventStore) ReplayEventsAfter(lastEventID string, send func(eve
168168
// WithSessionIDGenerator sets a custom session ID generator
169169
func WithSessionIDGenerator(generator func() string) StreamableHTTPOption {
170170
return streamableHTTPOption(func(s *StreamableHTTPServer) {
171-
// Store the generator for later use
172-
generatorFunc = generator
171+
s.sessionIDGenerator = generator
173172
})
174173
}
175174

176-
// Generator function stored for later use
177-
var generatorFunc func() string
178-
179175
// WithStatelessMode enables stateless mode (no sessions)
180176
func WithStatelessMode(enable bool) StreamableHTTPOption {
181177
return streamableHTTPOption(func(s *StreamableHTTPServer) {
182-
// Store the mode for later use
183-
statelessModeEnabled = enable
178+
s.statelessMode = enable
184179
})
185180
}
186181

187-
// Stateless mode flag stored for later use
188-
var statelessModeEnabled bool
189-
190182
// WithEnableJSONResponse enables direct JSON responses instead of SSE streams
191183
func WithEnableJSONResponse(enable bool) StreamableHTTPOption {
192184
return streamableHTTPOption(func(s *StreamableHTTPServer) {
193-
// Store the setting for later use
194-
enableJSONResponseFlag = enable
185+
s.enableJSONResponse = enable
195186
})
196187
}
197188

198-
// JSON response flag stored for later use
199-
var enableJSONResponseFlag bool
200-
201189
// WithEventStore sets a custom event store for resumability
202190
func WithEventStore(store EventStore) StreamableHTTPOption {
203191
return streamableHTTPOption(func(s *StreamableHTTPServer) {
204-
// Store the event store for later use
205-
customEventStore = store
192+
s.eventStore = store
206193
})
207194
}
208195

209-
// Event store stored for later use
210-
var customEventStore EventStore
211-
212196
// WithStreamableHTTPContextFunc sets a function that will be called to customize the context
213197
// to the server using the incoming request.
214-
func WithStreamableHTTPContextFunc(fn SSEContextFunc) StreamableHTTPOption {
198+
func WithStreamableHTTPContextFunc(fn HTTPContextFunc) StreamableHTTPOption {
215199
return streamableHTTPOption(func(s *StreamableHTTPServer) {
216-
// Store the context function for later use
217-
contextFunction = fn
200+
s.contextFunc = fn
218201
})
219202
}
220203

221-
// Context function stored for later use
222-
var contextFunction SSEContextFunc
223-
224204
// realStreamableHTTPServer is the concrete implementation of StreamableHTTPServer.
225205
// It provides HTTP transport capabilities following the MCP Streamable HTTP specification.
226206
type StreamableHTTPServer struct {
@@ -231,7 +211,7 @@ type StreamableHTTPServer struct {
231211
endpoint string
232212
sessions sync.Map // Maps sessionID to ClientSession
233213
srv *http.Server
234-
contextFunc SSEContextFunc
214+
contextFunc HTTPContextFunc
235215
sessionIDGenerator func() string
236216
enableJSONResponse bool
237217
eventStore EventStore
@@ -255,19 +235,6 @@ func NewStreamableHTTPServer(server *MCPServer, opts ...StreamableHTTPOption) *S
255235
opt.applyToStreamableHTTP(s)
256236
}
257237

258-
// Apply the stored option values to our implementation
259-
if generatorFunc != nil {
260-
s.sessionIDGenerator = generatorFunc
261-
}
262-
s.statelessMode = statelessModeEnabled
263-
s.enableJSONResponse = enableJSONResponseFlag
264-
if customEventStore != nil {
265-
s.eventStore = customEventStore
266-
}
267-
if contextFunction != nil {
268-
s.contextFunc = contextFunction
269-
}
270-
271238
// If no event store is provided, create an in-memory one
272239
if s.eventStore == nil {
273240
s.eventStore = NewInMemoryEventStore()

0 commit comments

Comments
 (0)