stop-background-task
Stop a running background task by its unique name to manage long-running processes like development servers or builds within MCP-compatible clients.
Instructions
Stops a running background task by its name.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Unique name of the task to stop |
Implementation Reference
- src/index.ts:114-138 (handler)The main handler function for the 'stop-background-task' tool. It looks up the task by name in the processes Map, calls kill() on the Child instance if found, removes it from the map, and returns a text response.async ({ name }) => { const child = processes.get(name); if (!child) { return { content: [ { type: "text", text: `No task found with name "${name}".`, }, ], }; } child.kill(); processes.delete(name); return { content: [ { type: "text", text: `Task "${name}" has been stopped.`, }, ], }; }
- src/index.ts:107-112 (schema)The tool metadata and input schema definition, specifying title, description, and Zod schema for the 'name' parameter.{ title: "Stop Background Task", description: "Stops a running background task by its name.", inputSchema: { name: z.string().describe("Unique name of the task to stop"), },
- src/index.ts:105-139 (registration)The full registration of the 'stop-background-task' tool using McpServer.registerTool, including name, schema, and inline handler function.server.registerTool( "stop-background-task", { title: "Stop Background Task", description: "Stops a running background task by its name.", inputSchema: { name: z.string().describe("Unique name of the task to stop"), }, }, async ({ name }) => { const child = processes.get(name); if (!child) { return { content: [ { type: "text", text: `No task found with name "${name}".`, }, ], }; } child.kill(); processes.delete(name); return { content: [ { type: "text", text: `Task "${name}" has been stopped.`, }, ], }; } );
- src/index.ts:56-62 (helper)The kill() method in the Child class that terminates the child process using process.kill() and updates the state to 'stopped'. This is called by the tool handler.public kill(): void { if (this.process.killed) { return; } this.process.kill(); this.state = "stopped"; }