Skip to content

Commit 008c44d

Browse files
committed
Honor baseurl in the sse /mcp error messages
1 parent 574a15d commit 008c44d

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

src/mcps/lib/http.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,14 @@ func (s *MCPServer) ServeHTTP(port string, basePath string, authEnabled bool) er
129129
// When authEnabled is true, each request must provide a Bearer token accepted by the authenticator.
130130
func (s *MCPServer) ServeSSE(port string, basePath string, authEnabled bool) error {
131131
s.authEnabled = authEnabled
132-
if basePath == "" {
133-
basePath = "/"
134-
}
132+
basePath = strings.TrimRight(basePath, "/")
135133

136-
// SSE endpoint
137134
ssePath := basePath + "/sse"
138135
mcpPath := basePath + "/mcp"
139136

140-
http.HandleFunc(ssePath, s.sseHandler)
137+
http.HandleFunc(ssePath, func(w http.ResponseWriter, r *http.Request) {
138+
s.sseHandler(w, r, mcpPath)
139+
})
141140
http.HandleFunc(mcpPath, s.sseMCPHandler)
142141

143142
log.Printf("Starting SSE server on port %s with SSE path %s and MCP path %s", port, ssePath, mcpPath)
@@ -170,7 +169,7 @@ func (s *MCPServer) ListenAndServe(listen string, authEnabled bool) error {
170169
}
171170

172171
// sseHandler handles SSE connections
173-
func (s *MCPServer) sseHandler(w http.ResponseWriter, r *http.Request) {
172+
func (s *MCPServer) sseHandler(w http.ResponseWriter, r *http.Request, mcpPath string) {
174173
if s.httpSecurityCheck(w, r) {
175174
return
176175
}
@@ -239,7 +238,7 @@ func (s *MCPServer) sseHandler(w http.ResponseWriter, r *http.Request) {
239238
}
240239
}()
241240

242-
endpointEvent := "event: endpoint\ndata: /mcp\n\n"
241+
endpointEvent := "event: endpoint\ndata: " + mcpPath + "\n\n"
243242
if _, err := w.Write([]byte(endpointEvent)); err != nil {
244243
return
245244
}

0 commit comments

Comments
 (0)