Skip to main content
Glama
nanoseil
by nanoseil

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
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • 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")}`, }, ], }; } }
  • 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")}`, }, ], }; } } );
  • The 'processes' Map that stores all background tasks, used by the handler to list running tasks.
    const processes = new Map<string, Child>();
  • 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"; } }

Other Tools

Related Tools

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/nanoseil/mcp-bgtask'

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