Class McpConnectionMetrics

java.lang.Object
io.jenkins.plugins.mcp.server.McpConnectionMetrics

@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public class McpConnectionMetrics extends Object
Tracks and exposes MCP connection metrics.

This endpoint requires authentication (unlike the health endpoint) and provides detailed statistics about MCP connections for monitoring and debugging.

Endpoint: /mcp-server/health/metrics

Response format:

 {
   "sseConnectionsTotal": 42,
   "sseConnectionsActive": 3,
   "streamableRequestsTotal": 150,
   "connectionErrorsTotal": 2,
   "uptimeSeconds": 3600,
   "startTime": "2025-01-28T10:00:00Z"
 }
 
  • Field Details

  • Constructor Details

    • McpConnectionMetrics

      public McpConnectionMetrics()
  • Method Details

    • handleMetricsRequest

      public static void handleMetricsRequest(jakarta.servlet.http.HttpServletResponse response) throws IOException
      Handles GET requests to the metrics endpoint. Requires authentication (checks Jenkins.READ permission). This method is called directly from the HttpServletFilter.
      Parameters:
      response - the HTTP response to send
      Throws:
      IOException - if writing the response fails
    • recordSseConnectionStart

      public static void recordSseConnectionStart()
      Records a new SSE connection starting.
    • recordSseConnectionEnd

      public static void recordSseConnectionEnd()
      Records an SSE connection ending.
    • recordStreamableRequest

      public static void recordStreamableRequest()
      Records a Streamable HTTP request.
    • recordConnectionError

      public static void recordConnectionError()
      Records a connection error.
    • getActiveSseConnections

      public static long getActiveSseConnections()
      Returns the current number of active SSE connections.
      Returns:
      active SSE connection count
    • getTotalSseConnections

      public static long getTotalSseConnections()
      Returns the total number of SSE connections since startup.
      Returns:
      total SSE connection count
    • getTotalStreamableRequests

      public static long getTotalStreamableRequests()
      Returns the total number of Streamable HTTP requests since startup.
      Returns:
      total Streamable request count
    • getTotalConnectionErrors

      public static long getTotalConnectionErrors()
      Returns the total number of connection errors since startup.
      Returns:
      total connection error count