send-to-task-stdin
Send input data directly to the standard input of an active background task managed by the MCP server, enabling dynamic interaction with long-running processes.
Instructions
Sends data to the stdin of a running background task.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| data | Yes | Data to send to the task's stdin | |
| name | Yes | Unique name of the task |
Implementation Reference
- src/index.ts:261-296 (handler)Handler function that retrieves the background task by name and sends the provided data to its stdin via child.writeToStdin, handling errors and returning appropriate responses.async ({ name, data }) => { const child = processes.get(name); if (!child) { return { content: [ { type: "text", text: `No task found with name "${name}".`, }, ], }; } try { child.writeToStdin(data); return { content: [ { type: "text", text: `Data sent to task "${name}" stdin.`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Failed to send data to task "${name}" stdin: ${ error instanceof Error ? error.message : String(error) }`, }, ], }; } }
- src/index.ts:253-260 (schema)Input schema definition for the tool, specifying 'name' and 'data' parameters using Zod.{ title: "Send to Task Stdin", description: "Sends data to the stdin of a running background task.", inputSchema: { name: z.string().describe("Unique name of the task"), data: z.string().describe("Data to send to the task's stdin"), }, },
- src/index.ts:251-297 (registration)Registration of the 'send-to-task-stdin' tool on the MCP server with title, description, input schema, and handler function.server.registerTool( "send-to-task-stdin", { title: "Send to Task Stdin", description: "Sends data to the stdin of a running background task.", inputSchema: { name: z.string().describe("Unique name of the task"), data: z.string().describe("Data to send to the task's stdin"), }, }, async ({ name, data }) => { const child = processes.get(name); if (!child) { return { content: [ { type: "text", text: `No task found with name "${name}".`, }, ], }; } try { child.writeToStdin(data); return { content: [ { type: "text", text: `Data sent to task "${name}" stdin.`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Failed to send data to task "${name}" stdin: ${ error instanceof Error ? error.message : String(error) }`, }, ], }; } } );
- src/index.ts:49-54 (helper)Helper method in the Child class that writes data to the child process's stdin, throwing an error if stdin is not available.public writeToStdin(data: string): void { if (this.process.stdin) { this.process.stdin.write(data); } else { throw new Error("Child process stdin is not available."); }