Skip to main content
Glama
Node Terminal MCP

Node Terminal MCP

by henryzhz
README.md
# Node Terminal MCP

[![npm](https://img.shields.io/npm/v/@hazzel-cn/node-terminal-mcp)](https://www.npmjs.com/package/@hazzel-cn/node-terminal-mcp)
[![GitHub](https://img.shields.io/github/license/henryzhz/node-terminal-mcp)](https://github.com/henryzhz/node-terminal-mcp)

A local MCP server for persistent terminal sessions. It uses [node-pty](https://github.com/microsoft/node-pty) and communicates with its MCP client over stdio. Each session keeps its own shell state, including its working directory.

## Install

Use Node.js 18 or newer. On Windows, use Windows 10 version 1809 or newer. For an MCP client with JSON stdio configuration, launch the existing npm package with `npx`.

```json
{
  "mcpServers": {
    "node-terminal-mcp": {
      "command": "npx",
      "args": ["-y", "@hazzel-cn/node-terminal-mcp"]
    }
  }
}
```

You can also run `npm install -g @hazzel-cn/node-terminal-mcp` and set the client's command to `node-terminal-mcp` with an empty arguments list. See [SETUP.md](SETUP.md) for Gemini CLI, local builds, and connection troubleshooting. Google ADK uses [`StdioConnectionParams`](https://google.github.io/adk-docs/tools-custom/mcp-tools/) for the same command and arguments.

The shell starts in the MCP server's working directory and inherits its environment and OS permissions. Connect the server to a trusted local client. Output is raw terminal text and may include ANSI control sequences.

## Tools

| Tool | What it does |
| --- | --- |
| `terminal_create` | Start a session with a unique active `sessionId`. You can supply a shell executable and initial dimensions. |
| `terminal_write` | Send an `input` string verbatim. Submit a line by including a newline or sending Enter separately. |
| `terminal_send_key` | Send a named key such as `enter`, `backspace`, `esc`, `up`, or `ctrl+c`. |
| `terminal_read` | Read and clear pending output for one session. |
| `terminal_resize` | Set the columns and rows of an active session. |
| `terminal_list` | List active session IDs. |
| `terminal_close` | Close a session and discard its unread output. |

The server uses `SHELL` when it is set and `/bin/bash` otherwise. Pass a shell executable explicitly on Windows. Terminals start at 80 columns by 24 rows.

For example, create `demo`, write `echo hello`, send `enter`, and read from `demo`. Output may arrive after the write finishes. Reading clears the pending output, and an exited session is removed. Closing a session releases its ID immediately and starts PTY cleanup in the background. The server also reaps managed PTYs when the client closes stdin.

## Develop

```sh
git clone https://github.com/henryzhz/node-terminal-mcp.git
cd node-terminal-mcp
npm ci
npm test
npm run test:package
```

`npm test` builds the project and exercises the MCP server and a local PTY. `npm run test:package` packs the CLI, installs it into a fresh directory, and opens a PTY from that installation. CI runs these checks on Linux, macOS, and Windows.

This release pins [`node-pty@1.2.0-beta.18`](https://www.npmjs.com/package/node-pty/v/1.2.0-beta.18) on all platforms. For a source build, see [node-pty's native build prerequisites](https://github.com/microsoft/node-pty#dependencies).

The prepack step copies the extra compiled paths from `compat-dist/` into `dist/`. Those files come byte-for-byte from the published 1.0.7 package to preserve direct imports.

## Releases

GitHub Actions builds and tests the package. npm releases are issued separately by a maintainer of `@hazzel-cn/node-terminal-mcp`. Before releasing, confirm the npm account with `npm whoami`, run the tests, and inspect the tarball with `npm pack --dry-run`.

Keep the npm package name and executable stable. If [npm trusted publishing](https://docs.npmjs.com/trusted-publishers/) is configured later, use `henryzhz/node-terminal-mcp` and the exact publish workflow filename in the npm settings.

## License

[MIT](LICENSE)

TDQS

A3.7/5.0

Scored across 7 tools

Disambiguation4/5

Each tool maps to a distinct lifecycle action on a terminal session, and descriptions clearly separate input (terminal_write) from special key sequences (terminal_send_key). The write vs. send_key boundary is the only place an agent could hesitate, but the descriptions resolve it well enough.

Naming Consistency5/5

Every tool uses the identical terminal_<verb> snake_case pattern with a single, unambiguous verb (create, write, send_key, read, resize, list, close). No mixed conventions or vague names.

Tool Count5/5

Seven tools is a tight, well-scoped set that covers exactly the operations needed to manage persistent terminal sessions without filler. Nothing appears redundant or missing at the count level.

Completeness4/5

Full session lifecycle is covered: create, interact (write/send_key/read), resize, list, and close. A convenience exec-style tool for one-shot command execution or explicit exit-status retrieval would round it out, but agents can work around this via write+read.