Class Endpoint
- All Implemented Interfaces:
ExtensionPoint,Action,ModelObject,RootAction,UnprotectedRootAction
Requests are served by Stapler (doDynamic(org.kohsuke.stapler.StaplerRequest2, org.kohsuke.stapler.StaplerResponse2)), which runs only after every
PluginServletFilter has had a chance to run. This class deliberately does not
implement HttpServletFilter: that extension is installed at the front of
PluginServletFilter and, if it handles the request, returns before authentication filters
registered later (OpenShift Login bearer tokens, Blue Ocean JWT, and anything added after startup)
can establish a user. Tool calls would then run as anonymous.
The URL is an UnprotectedRootAction so anonymous callers without Overall/Read still
reach the MCP layer, matching the previous filter-based behavior. Every tool invocation, including
programmatic McpServerExtension.getSyncTools() handlers, restores the caller captured on the
request and requires Overall/Read.
-
Nested Class Summary
Nested classes/interfaces inherited from interface hudson.ExtensionPoint
ExtensionPoint.LegacyInstancesAreScopedToHudson -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic booleanWhether anonymous MCP POSTs (noAuthorizationheader) may skip the CSRF crumb.static final Stringstatic booleanWhether to disable the SSE MCP endpoint.static booleanWhether to disable the stateless MCP endpoint.static booleanWhether to disable the streamable HTTP MCP endpoint.static final StringThe endpoint path for health checksstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final StringThe endpoint path for metricsstatic booleanWhether to require the Origin header in requests.static booleanWhether to require the Origin header to match the Jenkins root URL.static intHow often, in seconds, idle streamable HTTP sessions are dropped.static final Stringstatic intMaximum number of threads dedicated to processing SSE messages.static intMaximum time in seconds to wait for an SSE message to be processed before releasing the Jetty handler thread.static final Stringstatic final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddoDynamic(org.kohsuke.stapler.StaplerRequest2 req, org.kohsuke.stapler.StaplerResponse2 rsp) Stapler entry point for/mcp-server/**.static StringgetRequestedResourcePath(jakarta.servlet.http.HttpServletRequest httpServletRequest) protected voidinit()Builds the MCP transports once.booleanprocess(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, jakarta.servlet.FilterChain chain) Exempts MCP POSTs from CSRF crumbs without serving them.Methods inherited from class hudson.security.csrf.CrumbExclusion
all, processMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface hudson.model.RootAction
getBadge, isPrimaryAction
-
Field Details
-
MCP_SERVER
- See Also:
-
SSE_ENDPOINT
- See Also:
-
MCP_SERVER_SSE
- See Also:
-
STREAMABLE_ENDPOINT
- See Also:
-
MCP_SERVER_STREAMABLE
- See Also:
-
STATELESS_ENDPOINT
- See Also:
-
MCP_SERVER_STATELESS
- See Also:
-
MCP_SERVER_MESSAGE
- See Also:
-
HEALTH_ENDPOINT
The endpoint path for health checks- See Also:
-
MCP_SERVER_HEALTH
- See Also:
-
METRICS_ENDPOINT
The endpoint path for metrics- See Also:
-
MCP_SERVER_METRICS
- See Also:
-
AUTHENTICATION
-
HTTP_SERVLET_REQUEST
-
SESSION_SWEEP_INTERVAL
public static int SESSION_SWEEP_INTERVALHow often, in seconds, idle streamable HTTP sessions are dropped. A session with no open stream that has gone this long without a request is closed: that is a client that went away without sending DELETE. Default is 1800 (30 minutes), same as the SDK. Set to 0 to keep sessions forever, which is how the plugin used to run out of file descriptors. It's not static final on purpose to allow dynamic configuration via script console. -
REQUIRE_ORIGIN_HEADER
public static boolean REQUIRE_ORIGIN_HEADERWhether to require the Origin header in requests. Default is false, can be overridden by setting the system propertyio.jenkins.plugins.mcp.server.Endpoint.requireOriginHeader=true. -
REQUIRE_ORIGIN_MATCH
public static boolean REQUIRE_ORIGIN_MATCHWhether to require the Origin header to match the Jenkins root URL. Default is true, can be overridden by setting the system propertyio.jenkins.plugins.mcp.server.Endpoint.requireOriginMatch=false. The header will be validated only if present. -
DISABLE_MCP_STATELESS
public static boolean DISABLE_MCP_STATELESSWhether to disable the stateless MCP endpoint. Default is false (enabled). The stateless endpoint is available at /mcp-server/stateless -
DISABLE_MCP_SSE
public static boolean DISABLE_MCP_SSEWhether to disable the SSE MCP endpoint. Default is false (enabled). The SSE endpoint is available at /mcp-server/sse -
DISABLE_MCP_STREAMABLE
public static boolean DISABLE_MCP_STREAMABLEWhether to disable the streamable HTTP MCP endpoint. Default is false (enabled). The streamable endpoint is available at /mcp-server/mcp -
SSE_MESSAGE_TIMEOUT_SECONDS
public static int SSE_MESSAGE_TIMEOUT_SECONDSMaximum time in seconds to wait for an SSE message to be processed before releasing the Jetty handler thread. The MCP Java SDK'sHttpServletSseServerTransportProvider.doPost()callsMono.block()without a timeout, which can permanently leak Jetty threads if the reactive publisher never completes (e.g., due to unclean SSE client disconnects). Set to 0 to disable the timeout (not recommended). -
SSE_MESSAGE_MAX_THREADS
public static int SSE_MESSAGE_MAX_THREADSMaximum number of threads dedicated to processing SSE messages. This bounds the impact of hungMono.block()calls to this pool rather than the Jetty thread pool. -
ALLOW_UNAUTHENTICATED_MCP
public static boolean ALLOW_UNAUTHENTICATED_MCPWhether anonymous MCP POSTs (noAuthorizationheader) may skip the CSRF crumb. Default isfalse. Requests that sendAuthorizationstay exempt, because a cross-site page cannot set that header. Setio.jenkins.plugins.mcp.server.Endpoint.allowUnauthenticatedMcp=trueonly when anonymous agents must call MCP without a crumb. That weakens CSRF protection: the Origin check allows a missingOrigin, and does nothing when the Jenkins root URL is unset.mvn hpi:runsets the property so a local controller can be called without a crumb.
-
-
Constructor Details
-
Endpoint
public Endpoint()
-
-
Method Details
-
getRequestedResourcePath
public static String getRequestedResourcePath(jakarta.servlet.http.HttpServletRequest httpServletRequest) -
process
public boolean process(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, jakarta.servlet.FilterChain chain) throws IOException, jakarta.servlet.ServletException Exempts MCP POSTs from CSRF crumbs without serving them.CrumbFilterruns beforePluginServletFilter. Returningtruewithout callingchain.doFilterwould swallow the request there, so authentication filters registered later would never see it. Continuing the chain lets those filters run; Stapler then dispatches todoDynamic(org.kohsuke.stapler.StaplerRequest2, org.kohsuke.stapler.StaplerResponse2).The path comes from
HttpServletRequest.getPathInfo(). For POST requestsCrumbFilterwraps the request so that value is the canonical path (SECURITY-1774). A raw URI such as/mcp-server/mcp/../../scriptis therefore seen as/scriptand keeps its crumb check.- Overrides:
processin classCrumbExclusion- Throws:
IOExceptionjakarta.servlet.ServletException
-
init
protected void init() throws jakarta.servlet.ServletExceptionBuilds the MCP transports once. The unsynchronized read ofinitializedavoids taking the lock on every request; the second check runs while holding the monitor.- Throws:
jakarta.servlet.ServletException
-
doDynamic
public void doDynamic(org.kohsuke.stapler.StaplerRequest2 req, org.kohsuke.stapler.StaplerResponse2 rsp) throws IOException, jakarta.servlet.ServletException Stapler entry point for/mcp-server/**. Invoked only after the servlet filter chain, including everyPluginServletFilter, has completed.@RequirePOSTcannot be used: MCP clients are not browsers, and the SSE and streamable endpoints must accept GET. POST requests are exempted from crumbs byprocess(jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse, jakarta.servlet.FilterChain). Each tool and the metrics endpoint check permissions themselves.- Throws:
IOExceptionjakarta.servlet.ServletException
-
getIconFileName
- Specified by:
getIconFileNamein interfaceAction
-
getDisplayName
- Specified by:
getDisplayNamein interfaceAction- Specified by:
getDisplayNamein interfaceModelObject
-
getUrlName
- Specified by:
getUrlNamein interfaceAction
-