Skip to main content
Glama
xhuaustc

Jenkins MCP Tool

stop_build

Stop a running Jenkins build by specifying server, job, and build number. Automatically checks build status and handles permission errors for reliable termination.

Instructions

Stop Jenkins build.

Intelligently handles permission errors and will automatically check build status to confirm if it has already been terminated.

Args:
    server_name: Jenkins server name
    job_full_name: Full job name
    build_number: Build number
    ctx: MCP context (for logging)

Returns:
    Stop result

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
server_nameYes
job_full_nameYes
build_numberYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYes
statusYes

Implementation Reference

  • MCP tool handler and registration for 'stop_build' via @mcp.tool() decorator. Creates JenkinsAPIClient and calls its stop_build method, with logging via ctx.
    @mcp.tool()
    def stop_build(
        server_name: str, job_full_name: str, build_number: int, ctx: Context = None
    ) -> StopResult:
        """Stop Jenkins build.
    
        Intelligently handles permission errors and will automatically check build status to confirm if it has already been terminated.
    
        Args:
            server_name: Jenkins server name
            job_full_name: Full job name
            build_number: Build number
            ctx: MCP context (for logging)
    
        Returns:
            Stop result
        """
        client = JenkinsAPIClient(server_name)
    
        if ctx:
            ctx.log(
                "info",
                f"Stopping build #{build_number} for {job_full_name} on {server_name}",
            )
    
        try:
            result = client.stop_build(job_full_name, build_number)
    
            if ctx:
                if result["status"] == "ALREADY_TERMINATED":
                    ctx.log("info", "Build was already terminated")
                elif result["status"] == "STOP_REQUESTED":
                    ctx.log("info", "Stop request sent successfully")
                elif result["status"] == "NOT_FOUND":
                    ctx.log("warning", "Build not found")
    
            return result
    
        except Exception as e:
            if ctx:
                ctx.log("error", f"Failed to stop build: {e}")
            raise
  • Output schema definition for StopResult, a TypedDict specifying the return type structure.
    class StopResult(TypedDict):
        """Stop build result."""
    
        status: Literal["STOP_REQUESTED", "ALREADY_TERMINATED", "NOT_FOUND"]
        url: Optional[str]
  • Core helper method in JenkinsAPIClient that performs the HTTP POST to the Jenkins stop endpoint, handles 404 and 403 responses.
    def stop_build(self, job_full_name: str, build_number: int) -> StopResult:
        """Stop build.
    
        Args:
            job_full_name: Full job name
            build_number: Build number
    
        Returns:
            Stop result
    
        Raises:
            JenkinsError: Stop failed
        """
        job_url = self._build_job_url(job_full_name)
        stop_url = f"{job_url}/{build_number}/stop"
    
        response = self._make_request("POST", stop_url)
    
        if response.status_code == 404:
            return {"status": "NOT_FOUND", "url": None}
    
        if response.status_code == 403:
            # Permission error, check build status
            return self._handle_stop_permission_error(job_full_name, build_number)
    
        response.raise_for_status()
        return {"status": "STOP_REQUESTED", "url": stop_url}
  • Helper method to handle 403 permission errors by polling the build status up to 10 times to check if already terminated.
    def _handle_stop_permission_error(
        self, job_full_name: str, build_number: int
    ) -> StopResult:
        """Handle permission error when stopping build.
    
        Args:
            job_full_name: Full job name
            build_number: Build number
    
        Returns:
            Stop result
        """
        # Loop to check build status, confirm if already terminated
        for attempt in range(10):
            try:
                build_info = self.get_build_status(job_full_name, build_number)
                if not build_info.get("building", True):
                    return {"status": "ALREADY_TERMINATED", "url": None}
            except (JenkinsBuildNotFoundError, JenkinsError):
                # Build not found or query failed, consider as terminated
                return {"status": "ALREADY_TERMINATED", "url": None}
    
            if attempt < 9:
                time.sleep(1)
    
        # Still building after 10 checks, raise permission error
        raise JenkinsPermissionError("stop build", f"{job_full_name}#{build_number}")
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden. It adds valuable behavioral context about 'intelligently handling permission errors' and 'automatically checking build status to confirm termination,' which goes beyond just stating the action. However, it doesn't mention important aspects like whether this is a destructive operation, what happens to queued builds, or error handling specifics.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with clear sections (purpose, behavioral notes, args, returns) and uses only essential sentences. The front-loaded purpose statement is effective, though the 'Args' and 'Returns' sections could be slightly more detailed without sacrificing conciseness.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given 3 parameters with 0% schema coverage and no annotations, the description provides basic parameter semantics and some behavioral context. However, for a mutation tool that stops builds, it lacks details on permissions, side effects, error scenarios, and the output schema's content ('Stop result' is vague). The presence of an output schema helps but doesn't fully compensate.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 0%, so the description must compensate. It lists all 3 parameters with brief explanations, which adds meaning beyond the bare schema. However, the explanations are minimal ('Jenkins server name,' 'Full job name,' 'Build number') and don't provide format examples, constraints, or relationship context.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with a specific verb ('Stop') and resource ('Jenkins build'), making it immediately understandable. However, it doesn't explicitly differentiate from sibling tools like 'get_build_status' or 'trigger_build' beyond the obvious action difference.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. There's no mention of prerequisites, when not to use it, or how it relates to sibling tools like 'get_build_status' (which might be needed before stopping) or 'trigger_build' (which starts builds).

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/xhuaustc/jenkins-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server