
Jenkins MCP
HTTP-SSEJenkins插件实现MCP服务器功能
Jenkins插件实现MCP服务器功能
The MCP (Model Context Protocol) Server Plugin for Jenkins implements the server-side component of the Model Context Protocol. This plugin enables Jenkins to act as an MCP server, providing context, tools, and capabilities to MCP clients, such as LLM-powered applications or IDEs.
McpServerExtension
interface.McpServerExtension
, providing default tools for interacting with Jenkins jobs and builds.This MCP Server is based on the MCP Java SDK version 0.11.0, which implements the MCP specification version 2025-03-26.
The MCP Server plugin automatically sets up necessary endpoints and tools upon installation, requiring no additional configuration.
The following system properties can be used to configure the MCP Server plugin:
io.jenkins.plugins.mcp.server.extensions.BuildLogsExtension.limit.max=10000
(default 10000)MCP clients can connect to the server using:
<jenkins-url>/mcp-server/mcp
<jenkins-url>/mcp-server/sse
<jenkins-url>/mcp-server/message
The MCP Server Plugin requires the same credentials as the Jenkins instance it's running on. To authenticate your MCP queries:
{ "mcpServers": { "jenkins": { "autoApprove": [ ], "disabled": false, "timeout": 60, "type": "streamableHttp", "url": "https://jenkins-host/mcp-server/mcp", "headers": { "Authorization": "Basic <user:token base64>" } } } }
Copilot doesn't work well with the Streamable transport as of now, and I'm still investigating the issues. Please continue to use the SSE endpoint.
{ "mcp": { "servers": { "jenkins": { "type": "sse", "url": "https://jenkins-host/mcp-server/sse", "headers": { "Authorization": "Basic <user:token base64>" } } } } }
{ "servers": { "jenkins": { "command": "npx", "args": [ "mcp-remote", "http://jenkins-host/mcp-server/mcp", "--header", "Authorization: Bearer ${AUTH_TOKEN}" ], "env": { "AUTH_TOKEN": "Basic <user:token base64>" } } } }
The plugin provides the following built-in tools for interacting with Jenkins:
getJob
: Get a Jenkins job by its full path.
getJobs
: Get a paginated list of Jenkins jobs, sorted by name.
triggerBuild
: Trigger a build of a job.
This tool supports parameterized builds. You can provide parameters as a JSON object where each key is the parameter name. For example:
{ "jobFullName": "my-job", "parameters": { "BRANCH": "main", "DEBUG_MODE": "true" } }
Note on Parameters:
getBuild
: Retrieve a specific build or the last build of a Jenkins job.updateBuild
: Update build display name and/or description.getBuildLog
: Retrieve log lines with pagination for a specific build or the last build.getJobScm
: Retrieve SCM configurations of a Jenkins job.getBuildScm
: Retrieve SCM configurations of a specific build.getBuildChangeSets
: Retrieve change log sets of a specific build.whoAmI
: Get information about the current user.Each tool accepts specific parameters to customize its behavior. For detailed usage instructions and parameter descriptions, refer to the API documentation or use the MCP introspection capabilities.
To use these tools, connect to the MCP server endpoint and make tool calls using your MCP client implementation.
To add new MCP tools or functionalities:
McpServerExtension
.@Tool
to expose methods as MCP tools.@ToolParam
to define and describe tool parameters.Example:
@Extension public class MyCustomMcpExtension implements McpServerExtension { @Tool(description = "My custom tool") public String myCustomTool(@ToolParam(description = "Input parameter") String input) { // Tool implementation } }
The MCP Server Plugin handles various result types with the following approach:
For serialization to text content:
@ExportedBean
(from org.kohsuke.stapler.export
), Jenkins' org.kohsuke.stapler.export.Flavor.JSON
exporting mechanism is used.@ExportedBean
annotation, Jackson is used for JSON serialization.This approach ensures flexible and efficient handling of different result types, accommodating both Jenkins-specific exported objects and standard Java objects. This flexible approach ensures that tool results are consistently and accurately represented in the MCP response, regardless of their complexity.
The MCP Server Plugin seamlessly integrates with GitHub Copilot, enhancing your development experience by providing direct access to Jenkins information within your IDE. This integration allows you to interact with Jenkins jobs and builds using natural language queries.
As shown in the screenshot:
This integration streamlines your workflow by allowing you to access Jenkins information without leaving your development environment.
For more details on the Model Context Protocol and its Java SDK:
Contributions to the MCP Server plugin are welcome. Please refer to the Jenkins contribution guidelines for more information.
This project is licensed under the MIT License - see the LICENSE file for details.