Skip to main content
Glama
nanoseil

MCP Background Task Server

by nanoseil

Run Background Task

run-background-task

Execute long-running shell commands like development servers in the background while maintaining interactive control through the MCP Background Task Server.

Instructions

Runs a long-running command (like 'npm run dev') in background. When the command is running, you can interact with it using other tools.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYesUnique name of the task
shellYesShell command to run in background

Implementation Reference

  • The handler function for the 'run-background-task' tool. Creates and starts a background child process using the Child class if no existing task with the same name is running, stores it in the global processes map, and returns a confirmation message including the process PID.
    async ({ name, shell }) => {
      if (processes.has(name)) {
        throw new Error(`Task with name "${name}" is already running.`);
      }
    
      const child = new Child(shell);
    
      processes.set(name, child);
    
      return {
        content: [
          {
            type: "text",
            text: `Task "${name}" started with PID ${child.getPid()}.`,
          },
        ],
      };
    }
  • Input schema for the 'run-background-task' tool defining the required 'name' and 'shell' parameters using Zod validation.
    inputSchema: {
      name: z.string().describe("Unique name of the task"),
      shell: z.string().describe("Shell command to run in background"),
    },
  • src/index.ts:74-103 (registration)
    Registration of the 'run-background-task' tool on the McpServer instance, including name, schema (title, description, inputSchema), and handler function.
    server.registerTool(
      "run-background-task",
      {
        title: "Run Background Task",
        description:
          "Runs a long-running command (like 'npm run dev') in background. When the command is running, you can interact with it using other tools.",
        inputSchema: {
          name: z.string().describe("Unique name of the task"),
          shell: z.string().describe("Shell command to run in background"),
        },
      },
      async ({ name, shell }) => {
        if (processes.has(name)) {
          throw new Error(`Task with name "${name}" is already running.`);
        }
    
        const child = new Child(shell);
    
        processes.set(name, child);
    
        return {
          content: [
            {
              type: "text",
              text: `Task "${name}" started with PID ${child.getPid()}.`,
            },
          ],
        };
      }
    );
  • The Child class is a helper that wraps a Node.js child process spawned from a shell command. It captures stdout/stderr, tracks state, provides getters for output/PID/state, allows writing to stdin, and killing the process. Used by the background task tools.
    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";
      }
    }
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It discloses that the command is 'long-running' and runs 'in background', which implies non-blocking execution and potential for interaction via other tools. However, it lacks details on permissions, error handling, rate limits, or what happens if a task with the same name exists, leaving behavioral gaps for an agent.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is front-loaded with the core purpose in the first sentence and adds useful context in the second. Both sentences earn their place by clarifying the tool's role and interaction model without any wasted words, making it highly efficient and well-structured.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations and no output schema, the description provides basic purpose and usage context but lacks details on behavioral aspects like error responses, task lifecycle, or output format. For a tool that initiates background processes, more information on success/failure indicators or long-running implications would improve completeness, though it's minimally adequate.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents both parameters ('name' and 'shell'). The description adds no additional meaning beyond implying 'shell' is for commands like 'npm run dev', but this is redundant with the schema's 'Shell command to run' description. Baseline 3 is appropriate as the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('Runs') and resource ('a long-running command in background'), with specific examples like 'npm run dev'. It distinguishes from siblings by mentioning interaction with other tools, which implies this is the entry point for background execution versus monitoring/control tools.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context for when to use this tool ('Runs a long-running command in background') and hints at alternatives by stating 'you can interact with it using other tools', which references sibling tools like get-task-stderr or stop-background-task. However, it doesn't explicitly name alternatives or specify when not to use it, such as for short commands or immediate execution.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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