Skip to main content
Glama

local-terminal-mcp

An MCP (Model Context Protocol) server that gives AI agents multiple persistent local terminal sessions on the machine it runs on.

Each session is a real shell process. Working directory and environment variables survive between commands, so an agent can start a dev server in one terminal, run tests in another, and inspect logs in a third.

Features

  • Multiple concurrent shell sessions, each with its own process, buffer and lifecycle

  • Sessions survive MCP server restarts through a per-user background daemon

  • Persistent state: cd, export, virtualenv activation and similar commands stick

  • Incremental output reading with a sequence cursor, so nothing is read twice

  • Agent-friendly helpers: run a one-off command, wait for output to settle, send signals, close sessions

  • Zero native dependencies - plain Node.js child processes, works with npx

  • Output buffering with a configurable cap per session

  • Optional read-only mode for safer exploration

Related MCP server: Terminal MCP Server

Requirements

  • Node.js 18.17 or newer

  • macOS, Linux or Windows

Quick start

Run directly from GitHub with npx (no install step):

npx -y github:technicalheist/local-terminal-mcp

The server speaks MCP over stdio, so it is normally launched by an MCP client rather than by hand. By default it connects to a per-user background daemon that owns the terminal sessions, so restarting the MCP server or reconnecting the client keeps them alive. Pass --no-daemon to run everything in one process.

Demo

Run the built-in demo from a checkout:

npm run demo
# or point it at a project directory
npm run demo -- /path/to/project

It opens two terminal sessions, runs stateful shell commands, checks exit codes, pipes, unicode and a slow command, and runs read-only GitLab CLI checks when glab is installed. It prints a pass/fail table and exits non-zero on failure.

Client configuration

Claude Desktop

~/Library/Application Support/Claude/claude_desktop_config.json (macOS) or %APPDATA%\Claude\claude_desktop_config.json (Windows):

{
  "mcpServers": {
    "terminal": {
      "command": "npx",
      "args": ["-y", "github:technicalheist/local-terminal-mcp"]
    }
  }
}

Cursor

.cursor/mcp.json in a project or ~/.cursor/mcp.json globally:

{
  "mcpServers": {
    "terminal": {
      "command": "npx",
      "args": ["-y", "github:technicalheist/local-terminal-mcp"]
    }
  }
}

OpenCode

opencode.json:

{
  "mcp": {
    "terminal": {
      "type": "local",
      "command": ["npx", "-y", "github:technicalheist/local-terminal-mcp"],
      "enabled": true
    }
  }
}

Codex CLI

~/.codex/config.toml:

[mcp_servers.terminal]
command = "npx"
args = ["-y", "github:technicalheist/local-terminal-mcp"]

Tools

Tool

Purpose

terminal_spawn

Open a session. Optional name, shell, cwd, env. Returns an id.

terminal_list

List sessions with status, pid and buffer usage.

terminal_read

Read output. Pass since (the previous nextSince) to get only new output.

terminal_write

Write raw input to a session. Set wait: true to include the resulting output.

terminal_exec

Run a command in an existing session, wait for it to finish and return output plus exit code. Set waitForCompletion: false for REPLs or servers.

terminal_run

Run a one-off command in a fresh shell and return stdout, stderr and exit code.

terminal_signal

Send SIGINT, SIGTERM, SIGHUP or SIGKILL to a session's process group.

terminal_close

Stop and remove a session.

Example

1. terminal_spawn  { "name": "web",  "cwd": "~/project" }
2. terminal_spawn  { "name": "test", "cwd": "~/project" }
3. terminal_exec   { "id": "web",  "command": "npm run dev" }
4. terminal_exec   { "id": "test", "command": "npm test" }
5. terminal_read   { "id": "web", "since": 12 }
6. terminal_close  { "id": "web" }

CLI options

local-terminal-mcp [options]

--shell <path>         Shell executable for new sessions (default: $SHELL)
--cwd <path>           Default working directory (default: current directory)
--max-sessions <n>     Maximum concurrent sessions (default: 32)
--buffer-size <n>      Output buffer per session in characters (default: 1048576)
--read-only            Block spawn, write, exec, run, signal and close
--no-daemon            Run the MCP server in this process instead of the shared daemon
--quiet                Do not print the startup line to stderr
-h, --help             Show help
-v, --version          Print the version

How it works

The server launches each session as a child shell with piped stdio (no pseudo-terminal). Commands are written to stdin and stdout/stderr are captured into a per-session ring buffer. Every output chunk gets a sequence number so clients can poll incrementally with since / nextSince.

By default the stdio process is a thin proxy to a per-user background daemon. The daemon owns the shells and output buffers, so restarting the MCP server or reconnecting the client keeps sessions alive. terminal_list shows them again. The socket lives under ~/.local-terminal-mcp/ with user-only permissions. Use --no-daemon to keep all state inside the stdio process instead.

terminal_exec appends a small hidden marker after each command to capture the exit code and detect completion. It waits up to two minutes by default and gives silent commands up to 30 seconds to start producing output. It removes the marker from the output and from the session buffer. If completed is false, the command is still running or waiting for input; poll with terminal_read.

Because there is no PTY:

  • Full-screen interactive programs such as vim, top or htop will not render correctly.

  • Line-oriented interactive programs (Python/Node REPLs, prompts) work through terminal_write with newline: false, or through terminal_exec with waitForCompletion: false.

  • A command that reads stdin consumes the completion marker; use terminal_write for those commands.

Security

This server grants full shell access to the user account that runs it. Only connect it to MCP clients and models you trust. The daemon socket is readable/writable only by your user, but any process running as you can connect to it. Use --read-only to block new sessions and command execution, and run it inside a container or VM when experimenting with untrusted agents.

Install from GitHub Packages

The package is also published as @technicalheist/local-terminal-mcp on GitHub Packages. GitHub requires authentication for its npm registry, even for public packages:

export NODE_AUTH_TOKEN="$(gh auth token)"
npx --yes --registry=https://npm.pkg.github.com @technicalheist/local-terminal-mcp

Or install globally from the repository:

npm install -g github:technicalheist/local-terminal-mcp
local-terminal-mcp

Development

git clone https://github.com/technicalheist/local-terminal-mcp.git
cd local-terminal-mcp
npm install
npm test
node bin/local-terminal-mcp.js --help

License

MIT

Available Tools

8 tools
terminal_closeClose a terminal sessionA
DestructiveIdempotent

Terminate a session and remove it from the session list. Running child processes in its process group are stopped too.

Inputs: id (required).

terminal_execRun a command in a sessionA

Type a command into an existing session, wait for it to finish and return its output and exit code. The session keeps its working directory and environment, so use this for multi-step work. Waits up to 2 minutes by default. Set waitForCompletion to false for interactive programs or long-running servers.

Inputs: id (required), command (required), raw, idleMs, +2 more.

terminal_listList terminal sessionsA
Read-onlyIdempotent

List all terminal sessions with their id, name, shell, initial working directory, process id, status, exit code and buffer size.

Inputs: no named parameters.

terminal_readRead terminal outputA
Read-onlyIdempotent

Read buffered output from a session. Without "since", returns the last "lines" lines. Pass the previously returned nextSince value to get only new output since that point.

Inputs: id (required), raw, lines, since.

terminal_runRun a one-off commandA
Destructive

Run a command in a fresh non-interactive shell and wait for it to finish. Returns stdout, stderr, exit code and duration. Use this for short commands when no persistent session state is needed.

Inputs: command (required), cwd, shell, timeoutMs, +1 more.

terminal_signalSend a signal to a sessionA
Destructive

Send a POSIX signal to the session process group. Use SIGINT to interrupt a running command, SIGTERM to ask it to stop, or SIGKILL to force it. On Windows the process tree is terminated.

Inputs: id (required), signal.

terminal_spawnOpen a terminal sessionA

Open a new persistent local shell session. The session keeps its working directory and environment between commands. Returns the session id used by the other terminal tools.

Inputs: cwd, env, name, shell.

terminal_writeWrite to a terminalA

Write raw input to a running session. By default a newline is appended so the shell executes it. Set wait to true to also return the output produced by this write.

Inputs: id (required), input (required), wait, idleMs, +2 more.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A4.2/5.0

    Scored across 8 tools

    Disambiguation4/5

    Most tools have clearly distinct roles: spawn/list/read/close/signal/write are unambiguous. However, terminal_write with wait=true, terminal_exec, and terminal_run all execute commands and return output, so their boundaries overlap somewhat; the descriptions do clarify the differences (raw input vs. existing session vs. fresh shell), preventing serious confusion.

    Naming Consistency5/5

    All eight tools follow a strict terminal_<verb> snake_case pattern: spawn, list, read, close, signal, write, exec, run. The naming is predictable and consistent throughout.

    Tool Count5/5

    Eight tools is well-scoped for a persistent terminal session manager. Each tool covers a distinct lifecycle operation or interaction mode, and none feels redundant or missing.

    Completeness5/5

    The surface covers the full session lifecycle: creation, listing, output reading with incremental streaming, input writing, command execution, signals, and termination. Combined with terminal_run for one-off commands, there are no obvious dead ends for terminal automation workflows.

    Maintenance

    ActivityMaintained
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables LLMs to create and manage persistent, interactive shell sessions with full terminal emulation and PTY support. It allows for sequential command execution and supports interactive programs like vim or htop through specialized streaming and snapshot output modes.
      5
      MIT
    • A
      license
      A
      quality
      B
      maintenance
      Enables AI assistants to spawn and control persistent local shells, SSH sessions, REPLs, debuggers, and serial/UART devices with zero-loss output capture, timestamped history, and atomic expect matching for command execution and prompt synchronization.
      12
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Gives AI agents a persistent, interactive PTY shell with multiple concurrent named sessions, supporting SSH and interactive prompts instead of one-shot exec.
      MIT