Skip to main content
Glama
bpamiri

CockroachDB MCP Server

by bpamiri

show_jobs

Monitor and filter background jobs in CockroachDB clusters by type, status, or quantity to track operations like backups, restores, and imports.

Instructions

Show background jobs in the cluster.

Args:
    job_type: Filter by job type (BACKUP, RESTORE, IMPORT, etc.).
    status: Filter by status (running, succeeded, failed, etc.).
    limit: Maximum jobs to return.

Returns:
    List of jobs.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
job_typeNo
statusNo
limitNo

Implementation Reference

  • Core handler function that executes SQL query on crdb_internal.jobs with optional filters for job_type, status, and limit. Processes results into formatted job objects and returns them or an error.
    async def show_jobs(
        job_type: str | None = None,
        status: str | None = None,
        limit: int = 20,
    ) -> dict[str, Any]:
        """Show background jobs in the cluster.
    
        Args:
            job_type: Filter by job type (BACKUP, RESTORE, IMPORT, etc.).
            status: Filter by status (running, succeeded, failed, etc.).
            limit: Maximum jobs to return.
    
        Returns:
            List of jobs.
        """
        conn = await connection_manager.ensure_connected()
    
        try:
            query = """
                SELECT
                    job_id,
                    job_type,
                    status,
                    description,
                    created,
                    started,
                    finished,
                    fraction_completed,
                    error
                FROM crdb_internal.jobs
                WHERE 1=1
            """
    
            if job_type:
                query += f" AND job_type = '{job_type.upper()}'"
            if status:
                query += f" AND status = '{status.lower()}'"
    
            query += f" ORDER BY created DESC LIMIT {limit}"
    
            async with conn.cursor() as cur:
                await cur.execute(query)
                rows = await cur.fetchall()
    
            jobs = []
            for row in rows:
                jobs.append(
                    {
                        "job_id": str(row.get("job_id")),
                        "job_type": row.get("job_type"),
                        "status": row.get("status"),
                        "description": row.get("description"),
                        "created": str(row.get("created")) if row.get("created") else None,
                        "started": str(row.get("started")) if row.get("started") else None,
                        "finished": str(row.get("finished")) if row.get("finished") else None,
                        "progress": row.get("fraction_completed"),
                        "error": row.get("error"),
                    }
                )
    
            return {"jobs": jobs, "count": len(jobs)}
        except Exception as e:
            return {"status": "error", "error": str(e)}
  • MCP tool registration via @mcp.tool() decorator in the FastMCP server. This wrapper delegates execution to the cluster.show_jobs handler and adds error handling.
    @mcp.tool()
    async def show_jobs(
        job_type: str | None = None,
        status: str | None = None,
        limit: int = 20,
    ) -> dict[str, Any]:
        """Show background jobs in the cluster.
    
        Args:
            job_type: Filter by job type (BACKUP, RESTORE, IMPORT, etc.).
            status: Filter by status (running, succeeded, failed, etc.).
            limit: Maximum jobs to return.
    
        Returns:
            List of jobs.
        """
        try:
            return await cluster.show_jobs(job_type, status, limit)
        except Exception as e:
            return {"status": "error", "error": str(e)}

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/bpamiri/cockroachdb-mcp'

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