Background Jobs
Run long-running MCP operations in the background and manage them with jobs commands.
Overview
Some MCP tools take minutes or hours to complete — data exports, deployments, batch processing. Instead of blocking your terminal, use --background to submit the operation and get a job ID back immediately.
# Submit a background jobwork deploy --version 2.0 --background# → Job submitted: job_abc123 (task: task_xyz789)
# Check statuswork jobs show --latest# → status: running, remote status: running
# Wait for completionwork jobs wait --latest# → status: completed, result: { ... }The --background Flag
Any tool command supports --background:
work deploy --version 2.0 --backgroundwork export --dataset full --format parquet --backgroundwork batch-process --input data.csv --backgroundWhen --background is used:
- The request includes
_meta.taskto signal task augmentation - If the server supports tasks, it returns a
TaskAcceptedresponse with atask_id - mcp2cli creates a local job record linking the operation to the remote task
- The command returns immediately
Job Management
List Jobs
work jobs listjob_abc123 deploy running task_xyz789 2026-03-30T10:15:30Zjob_def456 export completed task_uvw012 2026-03-30T09:30:00ZShow Job Details
# By IDwork jobs show job_abc123
# Latest jobwork jobs show --latestWait for Completion
Block until the job finishes:
work jobs wait job_abc123work jobs wait --latestCancel a Job
work jobs cancel job_abc123work jobs cancel --latestWatch Job Progress
Stream real-time progress events:
work jobs watch job_abc123work jobs watch --latestHow It Works
sequenceDiagram
participant User
participant CLI as mcp2cli
participant Server as MCP Server
User->>CLI: deploy --version 2.0 --background
CLI->>Server: tools/call { _meta: { task: true } }
Server-->>CLI: TaskAccepted { task_id: "task_xyz" }
CLI->>CLI: Store JobRecord locally
CLI-->>User: Job submitted: job_abc123
Note over User: Later...
User->>CLI: jobs show --latest
CLI->>Server: tasks/get { task_id: "task_xyz" }
Server-->>CLI: Task { status: "running", data: {...} }
CLI-->>User: status: running
User->>CLI: jobs wait --latest
CLI->>Server: tasks/result { task_id: "task_xyz" }
Note over Server: Blocks until complete
Server-->>CLI: Task { status: "completed", result: {...} }
CLI-->>User: Deploy completed!
Task Protocol
The background jobs system uses the MCP task protocol:
| MCP Method | CLI Command | Purpose |
|---|---|---|
tasks/get | jobs show | Get current task status |
tasks/result | jobs wait | Block until task completes |
tasks/cancel | jobs cancel | Request task cancellation |
Task States
stateDiagram-v2
[*] --> Queued
Queued --> Running
Running --> Completed
Running --> Failed
Running --> Canceled
Completed --> [*]
Failed --> [*]
Canceled --> [*]
| State | Meaning |
|---|---|
queued | Server accepted the task, not yet started |
running | Task is actively executing |
completed | Task finished successfully |
failed | Task encountered an error |
canceled | Task was canceled by the client |
Job Records
Jobs are persisted to disk at instances/<name>/jobs/. Each job record contains:
- job_id — local identifier
- remote_task_id — server-assigned task ID
- capability — the tool that was called
- arguments — the arguments used
- status — current local status
- timestamps — creation and update times
JSON Output
All jobs commands support structured output:
work --json jobs list | jq '.[].status'work --json jobs show --latest | jq '.data.remote'work --json jobs wait --latest | jq '.data.result'Practical Examples
CI/CD Deployment Pipeline
#!/bin/bashset -e
# Submit deploymentRESULT=$(work --json deploy --version "$VERSION" --background)JOB_ID=$(echo "$RESULT" | jq -r '.data.job_id')
echo "Deployment submitted: $JOB_ID"
# Wait for completion with timeoutif ! timeout 600 work jobs wait "$JOB_ID"; then echo "Deployment timed out" work jobs cancel "$JOB_ID" exit 1fi
echo "Deployment complete"Parallel Background Operations
# Submit multiple jobswork export --dataset users --backgroundwork export --dataset orders --backgroundwork export --dataset analytics --background
# Monitor allwork jobs listServer Requirements
The background jobs system requires the MCP server to:
- Support the
taskscapability - Return
TaskAcceptedresponses when_meta.taskis present - Implement
tasks/get,tasks/result, andtasks/cancelmethods
If the server doesn’t support tasks, --background falls back to synchronous execution with a local job wrapper.
See Also
- Request Timeouts — for operations that should fail-fast rather than run in background
- Event System —
job_updateevents for monitoring - CLI Reference — full
jobssubcommand syntax