Skip to main content
Glama
xhuaustc

Jenkins MCP Tool

search_jobs_by_scenario

Find Jenkins jobs by scenario name or index to retrieve job information for specific automation workflows.

Instructions

Get the specified Jenkins job directly by scenario.

Args:
    scenario: Scenario name or index

Returns:
    List of job info matching the scenario

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
scenarioYes

Implementation Reference

  • MCP tool handler for 'search_jobs_by_scenario'. This decorated function serves as the entry point for the tool, delegating the core logic to ScenarioManager.
    @mcp.tool()
    def search_jobs_by_scenario(scenario: str) -> List[JobInfo]:
        """Get the specified Jenkins job directly by scenario.
    
        Args:
            scenario: Scenario name or index
    
        Returns:
            List of job info matching the scenario
        """
        return ScenarioManager.search_jobs_by_scenario(scenario)
  • Core helper function implementing the search logic: resolves scenario from config, fetches job info via JenkinsAPIClient, and enriches with scenario metadata.
    def search_jobs_by_scenario(scenario: str) -> List[JobInfo]:
        """Get the specified Jenkins job directly by scenario.
    
        Args:
            scenario: Scenario name or index
    
        Returns:
            List of job info matching the scenario
    
        Raises:
            JenkinsConfigurationError: Scenario configuration error
            JenkinsError: API request failed
        """
        scenario_mapping = get_scenario_mapping()
    
        # Parse scenario name
        resolved_scenario = ScenarioManager._resolve_scenario_name(
            scenario, scenario_mapping
        )
    
        if resolved_scenario not in scenario_mapping:
            available_scenarios = ", ".join(scenario_mapping.keys())
            raise JenkinsConfigurationError(
                f"Unknown scenario '{scenario}'. Available scenarios: {available_scenarios}"
            )
    
        config = scenario_mapping[resolved_scenario]
        server_name = config["server"]
        job_path = config["job_path"].strip("/")
    
        logger.info(
            f"Searching jobs for scenario '{resolved_scenario}' on server '{server_name}'"
        )
    
        try:
            # Use Jenkins API client to get job info
            client = JenkinsAPIClient(server_name)
            job_info = client.get_job_info(job_path)
    
            # Add scenario-related info
            job_info["scenario"] = resolved_scenario
            job_info["scenario_match"] = True
    
            return [job_info]
    
        except Exception as e:
            logger.error(f"Failed to get job for scenario '{resolved_scenario}': {e}")
            if "404" in str(e) or "not found" in str(e).lower():
                raise JenkinsConfigurationError(
                    f"Job path '{job_path}' for scenario '{resolved_scenario}' not found on server '{server_name}'"
                ) from e
            else:
                raise JenkinsError(
                    f"Failed to get job for scenario '{resolved_scenario}': {e}"
                ) from e
  • Tool registration via @mcp.tool() decorator in the MCP tools module.
    @mcp.tool()
    def search_jobs_by_scenario(scenario: str) -> List[JobInfo]:
        """Get the specified Jenkins job directly by scenario.
    
        Args:
            scenario: Scenario name or index
    
        Returns:
            List of job info matching the scenario
        """
        return ScenarioManager.search_jobs_by_scenario(scenario)

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