list-background-tasks
View all active background tasks on the MCP Background Task Server to monitor and manage long-running processes efficiently.
Instructions
Lists all currently running background tasks.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:148-178 (handler)The handler function for the 'list-background-tasks' tool. It checks the 'processes' Map and returns a list of running tasks with their name, PID, and state if any exist, or a message indicating none are running.async () => { if (processes.size === 0) { return { content: [ { type: "text", text: "No background tasks are currently running.", }, ], }; } else { const tasks = Array.from(processes.entries()).map(([name, child]) => ({ name, pid: child.getPid(), state: child.getState(), })); return { content: [ { type: "text", text: `Currently running tasks:\n${tasks .map( (task) => `- ${task.name} (PID: ${task.pid}, State: ${task.state})` ) .join("\n")}`, }, ], }; } }
- src/index.ts:143-147 (schema)The schema definition for the 'list-background-tasks' tool, specifying the title, description, and empty input schema (no parameters required).{ title: "List Background Tasks", description: "Lists all currently running background tasks.", inputSchema: {}, },
- src/index.ts:141-179 (registration)The registration of the 'list-background-tasks' tool on the MCP server, including the tool name, schema, and handler function.server.registerTool( "list-background-tasks", { title: "List Background Tasks", description: "Lists all currently running background tasks.", inputSchema: {}, }, async () => { if (processes.size === 0) { return { content: [ { type: "text", text: "No background tasks are currently running.", }, ], }; } else { const tasks = Array.from(processes.entries()).map(([name, child]) => ({ name, pid: child.getPid(), state: child.getState(), })); return { content: [ { type: "text", text: `Currently running tasks:\n${tasks .map( (task) => `- ${task.name} (PID: ${task.pid}, State: ${task.state})` ) .join("\n")}`, }, ], }; } } );
- src/index.ts:71-71 (helper)The 'processes' Map that stores all background tasks, used by the handler to list running tasks.const processes = new Map<string, Child>();
- src/index.ts:6-63 (helper)The 'Child' class that manages individual background processes, providing methods like getPid(), getState(), etc., used by the background task tools including list-background-tasks.class Child { process: childProcess.ChildProcess; state: "running" | "stopped" = "running"; stopCode: number | null = null; stdout: string = ""; stderr: string = ""; constructor(shell: string) { const child = childProcess.spawn(shell, { shell: true, }); child.stdout?.on("data", (data) => { this.stdout += data.toString(); }); child.stderr?.on("data", (data) => { this.stderr += data.toString(); }); child.on("exit", (code) => { this.state = "stopped"; this.stopCode = code; }); this.process = child; } public getStdout(): string { return this.stdout; } public getStderr(): string { return this.stderr; } public getState(): "running" | "stopped" { return this.state; } public getStopCode(): number | null { return this.stopCode; } public getPid(): number { return this.process.pid || -1; } public writeToStdin(data: string): void { if (this.process.stdin) { this.process.stdin.write(data); } else { throw new Error("Child process stdin is not available."); } } public kill(): void { if (this.process.killed) { return; } this.process.kill(); this.state = "stopped"; } }