diff --git a/README.md b/README.md index 6214599..86cc89c 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,20 @@ When enforcing the validation, the header value must match the configured Jenkin If receiving the header is mandatory the system property `io.jenkins.plugins.mcp.server.Endpoint.requireOriginHeader=true` will make it mandatory as well. +#### Jenkins Root URL Configuration + +MCP tools rely on the Jenkins root URL being correctly configured. This is required for generating accurate links within tool responses and for the proper functioning of certain features (for example, origin header validation). + +If the Jenkins root URL is not configured, MCP tool invocations will fail immediately with a clear error message explaining how to resolve the issue. + +To configure the Jenkins root URL: + +1. Navigate to **Manage Jenkins** in your Jenkins instance. +2. Go to **Configure System**. +3. Locate the **Jenkins URL** field and enter the full URL of your Jenkins instance (for example, `http://your-jenkins.example.com/`). +4. Click **Save**. + + #### Transport Endpoints The MCP Server plugin provides three transport endpoints, all enabled by default: diff --git a/src/main/java/io/jenkins/plugins/mcp/server/tool/McpToolWrapper.java b/src/main/java/io/jenkins/plugins/mcp/server/tool/McpToolWrapper.java index 352a0ec..92b21c6 100644 --- a/src/main/java/io/jenkins/plugins/mcp/server/tool/McpToolWrapper.java +++ b/src/main/java/io/jenkins/plugins/mcp/server/tool/McpToolWrapper.java @@ -266,8 +266,14 @@ String getToolDescription() { return getToolName(); } - McpSchema.CallToolResult toMcpResult(Object result, String tree) { + private static void ensureRootUrlConfigured() { + if (Jenkins.get().getRootUrl() == null) { + throw new IllegalStateException( + "The Jenkins root URL is not configured. Please set it in 'Manage Jenkins -> Configure System' to use MCP tools."); + } + } + McpSchema.CallToolResult toMcpResult(Object result) { var builder = new ToolResponse.ToolResponseBuilder().status(ToolResponse.Status.COMPLETED); if (result == null) { @@ -310,6 +316,7 @@ private McpSchema.CallToolResult call(McpTransportContext mcpTransportContext, M var jenkinsMcpContext = JenkinsMcpContext.get()) { // need Jenkins.READ at least Jenkins.get().checkPermission(Jenkins.READ); + ensureRootUrlConfigured(); if (log.isTraceEnabled()) { log.trace( "Tool call: {} as user '{}', arguments: {}",