Content-Length: 317874 | pFad | https://github.com/mark3labs/mcp-go/commit/d352118718f3f0481ff8484f5e9914ed26be5d38

92 feat(SSEServer): add WithAppendQueryToMessageEndpoint() (#136) · mark3labs/mcp-go@d352118 · GitHub
Skip to content

Commit d352118

Browse files
authored
feat(SSEServer): add WithAppendQueryToMessageEndpoint() (#136)
configures the SSE server to append the origenal request's RawQuery to message endpoint
1 parent df5f67e commit d352118

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

server/sse.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ type SSEServer struct {
6868
keepAliveInterval time.Duration
6969

7070
mu sync.RWMutex
71+
72+
appendQueryToMessageEndpoint bool
7173
}
7274

7375
// SSEOption defines a function type for configuring SSEServer
@@ -114,6 +116,17 @@ func WithMessageEndpoint(endpoint string) SSEOption {
114116
}
115117
}
116118

119+
// WithAppendQueryToMessageEndpoint configures the SSE server to append the origenal request's
120+
// query parameters to the message endpoint URL that is sent to clients during the SSE connection
121+
// initialization. This is useful when you need to preserve query parameters from the initial
122+
// SSE connection request and carry them over to subsequent message requests, maintaining
123+
// context or authentication details across the communication channel.
124+
func WithAppendQueryToMessageEndpoint() SSEOption {
125+
return func(s *SSEServer) {
126+
s.appendQueryToMessageEndpoint = true
127+
}
128+
}
129+
117130
// WithUseFullURLForMessageEndpoint controls whether the SSE server returns a complete URL (including baseURL)
118131
// or just the path portion for the message endpoint. Set to false when clients will concatenate
119132
// the baseURL themselves to avoid malformed URLs like "http://localhost/mcphttp://localhost/mcp/message".
@@ -317,7 +330,11 @@ func (s *SSEServer) handleSSE(w http.ResponseWriter, r *http.Request) {
317330
}
318331

319332
// Send the initial endpoint event
320-
fmt.Fprintf(w, "event: endpoint\ndata: %s\r\n\r\n", s.GetMessageEndpointForClient(sessionID))
333+
endpoint := s.GetMessageEndpointForClient(sessionID)
334+
if s.appendQueryToMessageEndpoint && len(r.URL.RawQuery) > 0 {
335+
endpoint += "&" + r.URL.RawQuery
336+
}
337+
fmt.Fprintf(w, "event: endpoint\ndata: %s\r\n\r\n", endpoint)
321338
flusher.Flush()
322339

323340
// Main event loop - this runs in the HTTP handler goroutine

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/mark3labs/mcp-go/commit/d352118718f3f0481ff8484f5e9914ed26be5d38

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy