@@ -178,11 +178,39 @@ func (s *Service) registerPrompts() {
178178 prompts .RegisterHealthPrompts (s .mcpServer , s .cfg )
179179}
180180
181+ // healthHandler provides a simple health check endpoint
182+ func (s * Service ) healthHandler () http.HandlerFunc {
183+ return func (w http.ResponseWriter , r * http.Request ) {
184+ if r .Method != http .MethodGet {
185+ http .Error (w , "Method not allowed" , http .StatusMethodNotAllowed )
186+ return
187+ }
188+
189+ response := map [string ]interface {}{
190+ "status" : "healthy" ,
191+ "version" : version .GetVersion (),
192+ "transport" : s .cfg .Transport ,
193+ "oauth" : map [string ]interface {}{
194+ "enabled" : s .cfg .OAuthConfig .Enabled ,
195+ },
196+ }
197+
198+ w .Header ().Set ("Content-Type" , "application/json" )
199+ if err := json .NewEncoder (w ).Encode (response ); err != nil {
200+ http .Error (w , "Failed to encode response" , http .StatusInternalServerError )
201+ return
202+ }
203+ }
204+ }
205+
181206// createCustomHTTPServerWithHelp404 creates a custom HTTP server that provides
182207// helpful 404 responses for the MCP server
183208func (s * Service ) createCustomHTTPServerWithHelp404 (addr string ) * http.Server {
184209 mux := http .NewServeMux ()
185210
211+ // Register health check endpoint (always available)
212+ mux .HandleFunc ("/health" , s .healthHandler ())
213+
186214 // Register OAuth endpoints if OAuth is enabled
187215 if s .cfg .OAuthConfig .Enabled {
188216 if s .endpointManager == nil {
@@ -194,7 +222,7 @@ func (s *Service) createCustomHTTPServerWithHelp404(addr string) *http.Server {
194222
195223 // Handle all other paths with a helpful 404 response
196224 mux .HandleFunc ("/" , func (w http.ResponseWriter , r * http.Request ) {
197- if r .URL .Path != "/mcp" {
225+ if r .URL .Path != "/mcp" && r . URL . Path != "/health" {
198226 w .Header ().Set ("Content-Type" , "application/json" )
199227 w .WriteHeader (http .StatusNotFound )
200228
@@ -206,6 +234,7 @@ func (s *Service) createCustomHTTPServerWithHelp404(addr string) *http.Server {
206234 "requests" : "POST /mcp - Send MCP requests (requires Mcp-Session-Id header)" ,
207235 "listen" : "GET /mcp - Listen for notifications (requires Mcp-Session-Id header)" ,
208236 "terminate" : "DELETE /mcp - Terminate session (requires Mcp-Session-Id header)" ,
237+ "health" : "GET /health - Health check" ,
209238 },
210239 }
211240
@@ -216,7 +245,6 @@ func (s *Service) createCustomHTTPServerWithHelp404(addr string) *http.Server {
216245 "auth-server-metadata" : "GET /.well-known/oauth-authorization-server - Authorization server metadata" ,
217246 "client-registration" : "POST /oauth/register - Dynamic client registration" ,
218247 "token-introspection" : "POST /oauth/introspect - Token introspection" ,
219- "health" : "GET /health - Health check" ,
220248 }
221249 for k , v := range oauthEndpoints {
222250 response ["endpoints" ].(map [string ]string )[k ] = v
@@ -241,6 +269,9 @@ func (s *Service) createCustomHTTPServerWithHelp404(addr string) *http.Server {
241269func (s * Service ) createCustomSSEServerWithHelp404 (sseServer * server.SSEServer , addr string ) * http.Server {
242270 mux := http .NewServeMux ()
243271
272+ // Register health check endpoint (always available)
273+ mux .HandleFunc ("/health" , s .healthHandler ())
274+
244275 // Register OAuth endpoints if OAuth is enabled
245276 if s .cfg .OAuthConfig .Enabled {
246277 if s .endpointManager == nil {
@@ -266,7 +297,7 @@ func (s *Service) createCustomSSEServerWithHelp404(sseServer *server.SSEServer,
266297
267298 // Handle all other paths with a helpful 404 response
268299 mux .HandleFunc ("/" , func (w http.ResponseWriter , r * http.Request ) {
269- if r .URL .Path != "/sse" && r .URL .Path != "/message" {
300+ if r .URL .Path != "/sse" && r .URL .Path != "/message" && r . URL . Path != "/health" {
270301 w .Header ().Set ("Content-Type" , "application/json" )
271302 w .WriteHeader (http .StatusNotFound )
272303
@@ -276,6 +307,7 @@ func (s *Service) createCustomSSEServerWithHelp404(sseServer *server.SSEServer,
276307 "endpoints" : map [string ]string {
277308 "sse" : "GET /sse - Establish SSE connection for real-time notifications" ,
278309 "message" : "POST /message - Send MCP JSON-RPC messages" ,
310+ "health" : "GET /health - Health check" ,
279311 },
280312 }
281313
@@ -292,7 +324,6 @@ func (s *Service) createCustomSSEServerWithHelp404(sseServer *server.SSEServer,
292324 "auth-server-metadata" : "GET /.well-known/oauth-authorization-server - Authorization server metadata" ,
293325 "client-registration" : "POST /oauth/register - Dynamic client registration" ,
294326 "token-introspection" : "POST /oauth/introspect - Token introspection" ,
295- "health" : "GET /health - Health check" ,
296327 }
297328 for k , v := range oauthEndpoints {
298329 response ["endpoints" ].(map [string ]string )[k ] = v
0 commit comments