Class HealthEndpoint

java.lang.Object
io.jenkins.plugins.mcp.server.HealthEndpoint
All Implemented Interfaces:
ExtensionPoint, Action, ModelObject, RootAction, UnprotectedRootAction

@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) @Extension public class HealthEndpoint extends Object implements UnprotectedRootAction
Lightweight health endpoint specifically for MCP Server status monitoring.

This endpoint provides MCP clients a quick way to check if the MCP server is available and accepting connections, without the overhead of the full MCP protocol handshake. It's accessible without authentication to enable health checking from load balancers and monitoring systems.

Unlike a generic Jenkins health endpoint, this endpoint returns MCP-specific information such as active connection counts and server shutdown state, allowing MCP clients to make informed decisions about connection management and reconnection.

Endpoint: /mcp-health

Response format:

 {
   "mcpServerStatus": "ok" | "shutting_down",
   "activeConnections": 5,
   "shuttingDown": false,
   "timestamp": "2025-01-28T10:30:00Z"
 }
 
  • Field Details

    • URL_NAME

      public static final String URL_NAME
      See Also:
    • SHUTDOWN_GRACE_PERIOD_SECONDS

      public static final int SHUTDOWN_GRACE_PERIOD_SECONDS
      Grace period in seconds for clients to detect shutdown before full termination.
      See Also:
  • Constructor Details

    • HealthEndpoint

      public HealthEndpoint()
  • Method Details

    • getIconFileName

      public String getIconFileName()
      Specified by:
      getIconFileName in interface Action
    • getDisplayName

      public String getDisplayName()
      Specified by:
      getDisplayName in interface Action
      Specified by:
      getDisplayName in interface ModelObject
    • getUrlName

      public String getUrlName()
      Specified by:
      getUrlName in interface Action
    • doIndex

      public void doIndex(org.kohsuke.stapler.StaplerRequest2 req, org.kohsuke.stapler.StaplerResponse2 rsp) throws IOException
      Handles GET requests via Stapler.
      Parameters:
      req - the Stapler request
      rsp - the Stapler response
      Throws:
      IOException - if writing the response fails
    • handleHealthRequest

      public static void handleHealthRequest(jakarta.servlet.http.HttpServletResponse response) throws IOException
      Handles GET requests to the MCP health endpoint. Returns MCP-specific status information including active connection counts. This method can be called directly or via Stapler.
      Parameters:
      response - the HTTP response to send
      Throws:
      IOException - if writing the response fails
    • setShuttingDown

      public static void setShuttingDown(boolean shutdown)
      Sets the shutdown state of the MCP server. Called by McpServerShutdownListener when Jenkins begins shutdown.
      Parameters:
      shutdown - true if Jenkins is shutting down
    • isShuttingDown

      public static boolean isShuttingDown()
      Returns whether the MCP server is in shutdown state.
      Returns:
      true if shutting down