mcp-longjobs
This server provides durable background task execution and resumable file transfers over MCP, without requiring native Tasks support.
Run long-running jobs asynchronously via
generate-report; it returns immediately with a task id instead of blocking.Poll task progress with
durable_task_getuntil completed or failed, including live progress updates.Answer mid-flight questions with
durable_task_respondwhen a task pauses for input.Cancel tasks cooperatively with
durable_task_cancel; tasks stop at checkpoints.Create resumable upload/download sessions with
file_transfer_open, optionally declaring size and sha256 for verification.Write chunks with offset validation via
file_transfer_write; wrong offsets return repairable errors.Read chunks via
file_transfer_read, supporting resume cursors and final sha256 integrity checks.Commit uploads with
file_transfer_committo verify and finalize the transfer.Inspect transfer sessions with
file_transfer_status, useful after client or server restarts.
mcp-longjobs
Durable, resumable operations for MCP — long-running tasks and large files that survive timeouts, disconnects, and client restarts. On every client, today.
The problem
Three things break every MCP server that does real work:
Long-running tool calls time out. Clients impose per-call timeouts (often 10–60s). A crawl, a build, a batch job fails — and the model's "retry" restarts the whole operation from scratch.
Failures are unrepairable. A failed call returns a freeform error, so the model guesses: retry blindly, or give up. It can't fix one parameter and resume.
Large files have no transfer story. Binary content is base64-in-JSON (33% overhead, hard message-size caps) or a bare URL with zero conventions — no chunking, no resume, no integrity checks.
The 2026-07-28 MCP spec added Tasks — async execution with mid-flight input and durable handles. But no client supports it yet, and the spec requires servers to refuse tasks for clients that didn't opt in. Every long-running server therefore needs a fallback path that works on today's clients. That is this package.
Related MCP server: Simple Streamable HTTP MCP Server
What you get
import { z } from "zod";
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { JsonFileSessionStore, withTasks, withFileTransfer, asToolRegistrar } from "mcp-longjobs";
const mcp = new McpServer({ name: "my-server", version: "1.0.0" });
const registrar = asToolRegistrar(mcp);
const store = new JsonFileSessionStore("./state/sessions.json");
const tasks = withTasks(registrar, { store });
tasks.taskTool("crawl-site", {
description: "Crawl a site and produce a report (takes minutes)",
inputSchema: { url: z.string(), maxPages: z.number().default(50) },
}, async (args, ctx) => {
for (const page of pages) {
if (ctx.signal.aborted) throw new Error("cancelled");
await ctx.progress(`Crawled ${page.url}`, done / total);
if (needsConfirmation(page)) {
const answer = await ctx.needInput({ prompt: `Include ${page.url}?`, choices: ["yes", "no"] });
if (answer === "no") continue;
}
}
return { summary, reportPath }; // small result for the model; big artifacts go through file transfer
});
withFileTransfer(registrar, { store, storageDir: "./state/blobs" });What the model experiences on today's clients (no Tasks support required):
crawl-sitereturns instantly with ataskIdand instructions to polldurable_task_get— no more timeouts.Polls show live progress:
{ "status": "working", "progress": { "message": "Crawled /pricing", "fraction": 0.4 } }.Mid-flight questions pause the task as
input_required; the model answers viadurable_task_respondand the task continues where it stopped.Client crash? New session?
durable_task_getwith the sametaskIdstill works — state lives in the store, not in the connection.durable_task_cancelaborts the work cooperatively at its next checkpoint.
Failures are data, not protocol errors — a structured envelope the model can repair in one round-trip:
{
"status": "failed",
"error": {
"code": "offset_mismatch",
"message": "Expected offset 131072, got 0.",
"retryable": true,
"recoveryHint": "Do NOT resend the whole file. Re-send this chunk starting at offset 131072.",
"partial": { "cursor": 131072 }
}
}Packages (subpath exports)
Import | Purpose |
|
|
|
|
| Session model, pluggable stores (memory, JSON file), structured error envelope |
Design notes
Bytes never flow through the model. The model sees metadata only: handle, size, sha256, progress. Chunks through tool calls are for small-to-medium payloads; large files should move out-of-band (TUS endpoint planned) with the model verifying integrity.
The model is the director, not the courier. Facade tool results carry their own instructions ("call
durable_task_getwith this id", "resume at offset N"), so any capable model can drive the protocol with zero host-side support.Failures are repairable data. Every failure carries
code,retryable,recoveryHint, andpartial.cursor— what went wrong, whether a retry can work, what to do instead, and what already succeeded.Lifecycle vocabulary matches the spec.
working / input_required / completed / failed / cancelled, so the native adapter can slot in later without breaking changes.
Status
Component | Status |
Tasks fallback facade (progress / input / cancel) | ✅ implemented |
Durable session stores (memory, JSON file, SQLite) | ✅ implemented |
Session TTL expiry (lazy, repairable envelope) | ✅ implemented |
Chunked file transfer with resume + checksums | ✅ implemented |
Native ext-tasks adapter ( | 🔜 tracks the SDK's experimental Tasks API |
TUS 1.0 out-of-band endpoint for large files | 🔜 planned — see mcp#189 |
Redis store, Python port | 🔜 planned |
Quickstart
git clone https://github.com/ljppanda/mcp-longjobs
cd mcp-longjobs
npm install && npm run build
node dist/examples/report-generator.js(Once published to npm, the same server runs with a single command: npx mcp-longjobs.)
Point your client at it (stdio):
{
"mcpServers": {
"report-generator": {
"command": "node",
"args": ["/absolute/path/to/mcp-longjobs/dist/examples/report-generator.js"]
}
}
}Then ask: "Generate a report on EV batteries with 3 sections." Watch the model start the job, poll durable_task_get, and pick up the result. Kill the client mid-run, restart it, and ask for the same taskId — it resumes.
Development
npm install
npm test # vitest
npm run build # tsc -> dist/
npm run example # build + run the demo serverContributing
PRs welcome — especially: store backends (SQLite/Redis), the native ext-tasks adapter, and the TUS endpoint. Please open an issue first for anything larger.
License
Available Tools
9 toolsdurable_task_cancelCancel a durable taskA
Cooperatively cancel a running task. The task stops at its next checkpoint.
Inputs: taskId (required).
durable_task_getGet durable task statusA
Poll a long-running task created by this server. Repeat until status is "completed" or "failed".
Inputs: taskId (required).
durable_task_respondAnswer a durable task's questionA
Deliver input that a paused task (status input_required) asked for.
Inputs: taskId (required), response (required).
file_transfer_commitFinalize an upload sessionA
Verify size and sha256 (when declared), then move the staged file to its destination.
Inputs: handle (required).
file_transfer_openOpen a resumable file transferA
Open a chunked upload or download session. Upload: send chunks with file_transfer_write starting at offset 0, then file_transfer_commit. Download: fetch chunks with file_transfer_read until eof. Sessions survive server restarts — resume at the reported nextOffset.
Inputs: path (required), direction (required), size, sha256.
file_transfer_readRead one chunk from a download sessionA
Fetch a byte range as base64. Repeat with nextOffset until eof; the final response carries the whole-file sha256.
Inputs: handle (required), length, offset.
file_transfer_statusInspect a transfer sessionA
Report direction, status, bytes received so far, and destination — useful after a restart.
Inputs: handle (required).
file_transfer_writeWrite one chunk to an upload sessionA
Append a base64 chunk at the session's expected offset. A wrong offset returns a repairable error with the correct cursor instead of failing the transfer.
Inputs: data (required), handle (required), offset (required).
generate-reportGenerate a market reportA
Simulates a slow job (~2s per section). Demonstrates background execution, progress polling, restart-safe state, and cooperative cancellation.
Inputs: topic (required), sections.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 9 tools
Each tool maps to a distinct action within its domain: durable_task_get/respond/cancel are clearly separate task lifecycle operations, and file_transfer_open/write/read/commit/status cover distinct phases of a transfer. generate-report is the only job-creation tool and does not overlap with the polling or transfer tools.
Most tools follow a clear prefix_verb snake_case pattern, such as durable_task_get and file_transfer_open, but generate-report breaks this by using a hyphenated verb-noun style. The group prefixes help readability, but the mixed conventions prevent a higher score.
Nine tools is well within the ideal range, and each appears to serve a specific necessity for either durable task coordination or chunked file transfer. The count feels focused and purposeful rather than bloated.
The task lifecycle is well covered with get, respond, and cancel, and the file transfer flow covers open, read/write, commit, and status. Minor gaps exist: there is no explicit file transfer cancellation/abort tool, and task creation is only demonstrated through generate-report rather than a generic create tool.
Maintenance
Related MCP Connectors
MCP server for the FFmpeg Micro video transcoding API — create, monitor, download transcodes.
Public MCP server for discovering open jobs. Search, filter, and get application links.
Hosted MCP server for task-first delegation to remote workstations and workers.
QuLab MCP remote server (Streamable HTTP) for computational science and lab tools.
Related MCP Servers
- AlicenseAqualityCmaintenanceAsync MCP server for running long-running AI tasks with real-time progress monitoring, enabling users to start, monitor, and manage complex AI workflows across multiple models.650 npm5MIT
- AlicenseNot gradedqualityDmaintenanceA reference implementation demonstrating proper MCP server patterns with HTTP transport, featuring session management, progress notifications, and example tools for testing server functionality. Serves as a clean template for building MCP servers with streamable responses and comprehensive error handling.7MIT
- AlicenseAqualityBmaintenanceA fire-and-poll MCP server that lets Claude Code run long background jobs without hitting tool-call timeouts.3MIT
- FlicenseNot gradedqualityBmaintenanceRemote MCP server that launches user-supplied scripts inside disposable Docker containers, returning task IDs for async tracking and bounded output tails.-