show_jobs
Monitor and filter background jobs in a CockroachDB cluster by type and status 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
| Name | Required | Description | Default |
|---|---|---|---|
| job_type | No | ||
| status | No | ||
| limit | No |
Implementation Reference
- src/cockroachdb_mcp/server.py:464-484 (handler)MCP tool handler for 'show_jobs', registered via @mcp.tool() decorator. Delegates to cluster.show_jobs implementation.@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)}
- Core implementation of show_jobs that executes SQL query against crdb_internal.jobs table, applies filters, and formats results.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)}