rex-mcp
Summary: An MCP bridge that lets an AI agent discover Rex terminal sessions, read block screens, type into terminals, and run commands with the local rex CLI.
Discover: list sessions (
list/ls),session ls/inspect,window ls/inspect,block ls/inspect/types,client ls/inspect, and read the server's control API surface (api ls/list/describe). Listing/inspection output is JSON for stable parsing.Read a screen:
capture -b BLOCKprints a block's screen astext,html, orvt(add--trim); explicit target required.Type into a terminal:
send/send-keywith an explicit target (-b BLOCK,-w WINDOW, or-s SESSION) — confirms typing, not completion.Run commands:
run -s SESSION -- CMDstarts a command in a new block;--waitreturns its exit status,--keep-openkeeps the block for latercapture.Wait:
wait TARGETblocks until a block, window, or session ends (capped at 90000 ms,REX_MCP_WAIT_MAX).Read docs:
help <command>for syntax;rex_skillreturns the full installed CLI guide verbatim (~20 KB).Invoke as: one
rexcall using exactly one ofargs(string array) orcommand(quote-only string, no shell operators).Not possible: no creating/closing/arranging/renaming blocks, no Lua
do, no app actions or keymaps, no config/server management, no-Srouting to other hosts — only discovery, reading, typing, and running.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@rex-mcp list my Rex terminal sessions"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
rex-mcp
Let an AI agent read, type into, and run commands in Rex terminal blocks on your own machine, through the rex CLI.
rex-mcp is an MCP server over stdio by default, with an optional HTTP mode (bearer token) for clients on other machines. Ask the agent to list your sessions, read a block's screen, type a command into a block, or run a command and wait for it to finish.
It follows the design of herdr-mcp: one passthrough tool that runs a fixed allowlist of CLI verbs, plus a skill tool that serves the CLI's own guide. The differences are the CLI underneath and the transports (stdio by default; HTTP with a bearer token when you enable it, where herdr-mcp is HTTP-only).
What you need
Rex installed, with its app or server available on this machine. The CLI finds the local server on its own; like plain
rex, a call may autostart a missing server. Rex publishes tostable,previewandsnapshotchannels, andstablehas no releases yet, so the surface this bridge wraps is the preview one (checked against0.1.0-preview.23).--jsonoutput and the allowlist follow that channel; snapshot adds commands and flags the allowlist does not cover.Node.js 22 or later.
rexon the PATH of the process that spawns the MCP server, orREX_MCP_BINARYpointing at it. Inside Rex terminals this is automatic; outside, checkwhich rex.macOS or Linux. The token file is checked for mode
0600and the bridge assumes unix sockets, so Windows is untested.
Related MCP server: mcp-interactive-terminal
Install
git clone <this repo> && cd rex-mcp
npm install
npm testRun it
The server speaks MCP over stdio, so a client spawns it; running it by hand just waits for JSON-RPC on stdin. Point a client's MCP config at it:
{
"mcpServers": {
"rex-mcp": {
"command": "node",
"args": ["/absolute/path/to/rex-mcp/bin/rex-mcp.mjs"]
}
}
}On startup it prints one probe result to stderr: the Rex server endpoint it will drive (a unix socket or a host address), the server version and session count. There is no HTTP host or port — if you see Rex server: not reachable, the first tool call may still autostart the local server, like plain rex does.
Or install the package and use the binary: npm install -g rex-mcp (or just link from a checkout), then set "command": "rex-mcp".
Optional environment variables:
Variable | Default | Meaning |
|
| Path to the |
|
| Wait ceiling in milliseconds for |
| unset | Set to |
|
| HTTP bind address ( |
|
| HTTP port ( |
|
| Bearer token file for HTTP mode, mode 0600, 64 hex chars. |
| empty | Comma-separated Origin allowlist for HTTP mode; empty allows all. |
HTTP mode for other machines
rex-mcp --http (or just serve) serves Streamable HTTP at /mcp with bearer auth instead of stdio. On first start it generates the token file (~/.config/rex-mcp/token, mode 0600); rex-mcp token prints a fresh token for rotation. Clients authenticate with a header:
Authorization: Bearer <token>A generic remote client config looks like:
{
"mcpServers": {
"rex-mcp": {
"url": "https://<host>.<tailnet>.ts.net:8443/mcp",
"headers": { "Authorization": "Bearer <token>" }
}
}
}Start it at login (macOS)
So a remote client always finds the endpoint, install the bridge as a per-user launchd agent from a checkout where rex is on PATH:
just service-install # writes ~/Library/LaunchAgents/com.rex-mcp.http.plist and bootstraps it
just service-uninstall # stops it and removes the filelaunchd gives a job a minimal PATH, so the installer records the absolute node and rex paths at install time and exports REX_MCP_BINARY. Output goes to ~/Library/Logs/rex-mcp.log; the agent restarts the bridge if it exits, throttled to once every ten seconds. Because the job points at this checkout, run just service-install again after moving the repository, changing the Node version, or upgrading Rex by hand.
Reaching it over Tailscale
Rex ships with its own Tailscale integration (rex server status shows the node), but the bridge is a separate process, so put it on the tailnet with tailscale serve:
rex-mcp --http & # binds 127.0.0.1:8791
tailscale serve --bg --https=8443 http://127.0.0.1:8791The remote instance then talks to https://<host>.<tailnet>.ts.net:8443/mcp with the token header — use the URL tailscale serve prints, since the node name there can differ from the one Rex's own integration shows (macOS can run two Tailscale nodes). Port 8443 keeps this clear of Rex's built-in Tailscale HTTPS, which occupies the node's default port. Traffic stays inside the tailnet: WireGuard-encrypted, invisible to the public internet.
On macOS the Tailscale CLI lives inside the app: /Applications/Tailscale.app/Contents/MacOS/Tailscale serve .... Serve targets must be on this machine (127.0.0.1), so bind the bridge to its default and let serve proxy it.
Alternatives:
Bind to the tailnet IP directly:
rex-mcp --http --host <tailscale-ip>. No proxy, plain HTTP inside the tailnet; fine for tailnet-only clients.Public internet:
tailscale funnel --bg --https=8443 http://127.0.0.1:8791exposes the URL beyond the tailnet. Only do this if a hosted client outside your tailnet needs it; the token is then the only gate.
To undo a serve rule: tailscale serve --https=8443 off.
Tasks
just drives everything; run just with no arguments to list recipes.
Recipe | What it does |
| Install dependencies. |
| Run the test suite, no Rex server needed. |
| Start the server on stdio. |
| Start the server in HTTP mode on 127.0.0.1:8791. |
| Install the HTTP bridge as a launchd agent so it starts at login (macOS). |
| Stop and remove that launchd agent. |
| End-to-end probe against the real Rex server (creates and closes two blocks). |
| Build the npm tarball into |
|
|
| Publish the current version to npm. |
| Remove |
Package and release
npm pack ships only bin/, src/, README and LICENSE (see the files field), and prepublishOnly runs the tests first.
CI (.github/workflows/ci.yml) runs the suite on push and pull requests across Ubuntu and macOS with Node 22 and 24.
Releases (.github/workflows/release.yml) run when you push a v* tag: tests, tarball, GitHub release with the tarball attached, then npm publish. Setup, once:
Push the repo to GitHub and
git init+ commit if you have not already.Create an npm automation token and add it as the repository secret
NPM_TOKEN.Cut a release:
npm version patch && git push --follow-tags.
For a local release without CI: just pack, then npm publish (or just publish).
Tools
rex runs one rex command. Supply exactly one of args (an array of strings) or command (a quote-only string; no shell operators, substitution, or expansion).
Allowed verbs, with what the bridge does to them:
Verb | Notes |
| List sessions. |
| Discovery. |
| Inspect and drive one block. |
| See connected clients. |
| Read the server's control API surface. |
| Print a block's screen ( |
| Type into a terminal. An explicit target is required: |
| Start a command in a new block; add |
| Block until a target ends. The bridge pins |
| Read command syntax. |
Listing and inspection calls get --json appended, so output is stable to parse. Failure envelopes carry a code, a message, and recovery advice in next. Rex's exit statuses map as: 2 invalid arguments, 3 target not found or ambiguous, 4 server unreachable, 130 cancelled.
The bridge runs outside any Rex terminal, so there is no default session or block: scope calls explicitly. Two patterns cover most work:
# Run a command and read its output
rex run -s SESSION --wait --keep-open -- CMD # exit status comes back; block stays open
rex capture -b BLOCK --trim # the command's output
# Work in an existing terminal
rex send -b BLOCK 'make test' # type; delivery is not completion
rex wait BLOCK --for 90s # exit status when the command endsrex_skill returns the installed CLI guide verbatim. Read it once before the first rex call.
Finding Rex answers
The bridge exposes the CLI, not Rex's concepts. When a call needs one, read the docs as an agent:
curl -s https://www.superlogical.com/rex/docs/llms.txt # every page with a summary
curl -s "https://www.superlogical.com/rex/docs/search.json?q=key+mode"Add .md to any page address for its Markdown, or read llms-full.txt for the lot. rex help <command> and rex api describe <method> stay authoritative for the server you are connected to.
What is disabled
do (Lua scripts), events, kill, cp, forward, new, split, focus, zoom, move, swap, resize, actions, keymap, whoami, version, home, hosts, config, server, login-server, skill, completion, and terminfo. Inside the allowed verbs, block new/close/focus/zoom/move/swap/rename/stream/call and api call are disabled too, as is -S server routing.
That leaves discovery, reading a screen, typing, and running a command. An agent cannot create, arrange, rename, or destroy anything, drive the app through client perform, or reach another host. Two consequences worth knowing: layout work needs do or the server API, and block inspect lists a block's methods (program_status, process, pwd, ports) that block call would invoke but the allowlist blocks.
Wait semantics
Rex blocks are terminals, not agents. wait TARGET returns when the target's child process exits, with that exit status; wait --for bounds the wait and returns non-zero on timeout. Rex itself can report whether a program is idle, working or waiting on the user, but that arrives through the block's program_status method and its program_status_changed event, and this bridge reaches neither. So from here there is no state to poll: to check on a running command, capture the block and read the screen; to wait for a command to finish, call wait again with the same target. On wait_timeout, capture first: the reply may already be on screen.
Risks
The rex tool types into your real terminals and starts real processes with the permissions of the MCP client. A malicious prompt or document can steer an agent into using that access. Terminal output may contain passwords, keys, or private work, and a capture can surface them into agent context. The allowlist reduces accidents, not intent; treat a connected agent as someone typing at your keyboard.
In HTTP mode the token is shell-equivalent access to this machine, as the user running the bridge. Rex's own documentation says the same about its listeners: "A connection to a server can do anything that server can, including starting programs as its account." Keep the endpoint tailnet-only unless a hosted client forces a funnel, keep the token out of chat and screenshots, and rotate it with rex-mcp token if it leaks, then update every client.
Development
just test
just liveThe tests cover argument splitting and allowlist rules, wait budgeting, exit-status mapping, the spawn runner, the token file semantics, a full MCP handshake over stdio, and a full bearer-authenticated HTTP session against a fake rex binary, so they run without a Rex server. scripts/live.mjs is the same handshake against your real Rex server; it creates two short-lived blocks and closes them at the end.
Credits
rex-mcp is inspired by herdr-mcp by Igor Warzocha, the MCP bridge for Herdr. The tool design (a passthrough CLI tool with an allowlist plus a skill tool) and parts of the bridge and HTTP code are adapted from it, under the MIT licence. rex-mcp targets Rex instead of Herdr, runs as a local stdio server by default (HTTP with a bearer token for remote machines), and waits on terminal process exits instead of agent state.
Licence
MIT © Edgardo Yoliani. Contains code adapted from herdr-mcp, MIT © Igor Warzocha; see the notice in LICENSE.
Available Tools
2 toolsrexRex CLIA
Run the rex CLI against the local Rex server. This bridge runs outside any Rex terminal, so there is no default session or block: scope every call explicitly. Discovery: list (sessions), then block ls -s SESSION or session inspect -s SESSION. Act: capture -b BLOCK reads a terminal screen; send or send-key types into a terminal and needs an explicit target (-b BLOCK, -w WINDOW or -s SESSION); run -s SESSION -- CMD starts a command in a new block, with --wait to block until it exits (its exit status becomes the call's exit status) and --keep-open to keep the block for capture afterwards; wait TARGET blocks until a block, window or session ends, capped at 90000 ms; help shows syntax; rex_skill reads the full guide. To run a command and read its output: run -s SESSION --wait --keep-open -- CMD, then capture -b BLOCK. On wait_timeout, capture the target (a reply may already be on screen) and repeat wait with the same target if the exit status is still needed; otherwise carry on and check back later. send confirms typing, not that a command finished. Supply exactly one of args (array of strings) or command (quote-only string). Disabled here: do (Lua), events, kill, cp, forward, new, split, focus, zoom, move, swap, resize, actions, keymap, version, home, hosts, config, server, login-server, skill; inside the allowed verbs, block new/close/focus/zoom/move/swap/rename/stream/call and api call; and -S server routing, because this bridge drives the local Rex server only.
Inputs: args, command.
rex_skillRex CLI guideA
Read the installed Rex CLI guide verbatim (about 20 KB). Read this before the first rex call; it documents commands, targets and flags for the installed Rex version.
Inputs: no named parameters.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 2 tools
The two tools are mostly distinct: rex executes CLI commands and rex_skill reads documentation. There is minor overlap in that rex's own `help <command>` verb and rex_skill both serve a discovery purpose, but the guidance to read rex_skill before the first call makes the boundary clear enough.
Both names share the `rex` prefix and use snake_case, forming a coherent family. The bare `rex` is a noun rather than a verb_noun action name, which is a minor deviation but predictable for a CLI passthrough.
Two tools is thin for a surface that spans sessions, blocks, capture, send, run, and wait; the entire domain is funneled through one heavily overloaded `rex` tool with dozens of hidden verbs and flags. Each tool does earn its place, but discoverability suffers with only an execution tool plus a docs tool.
Core agent workflows (list sessions, inspect, capture, send, run, wait) are covered, but a long list of verbs is explicitly disabled: no session creation (`new`), no `kill`, no events, no window/focus/move management, and no block lifecycle beyond new/close/focus. Agents cannot create or tear down sessions or subscribe to events, which are notable gaps for a terminal-bridge domain.
Maintenance
Related MCP Connectors
Remote MCP server exposing your Node Command fleet (files, shell, processes, browser) to AI hosts.
An MCP server that provides agents access to the KeldynAI platform
Remote MCP server for supportsheep: run AI interviews and manage support content for your blog.
Remote MCP server for supportsheep: run AI interviews and manage support content for your blog.
Related MCP Servers
- FlicenseAqualityDmaintenanceA lightweight MCP server that provides AI assistants with access to a system's terminal through a secure terminal tool. It enables users to execute shell commands and receive stdout, stderr, and exit codes directly within an MCP-compatible client.1-
- AlicenseAqualityDmaintenanceMCP server that gives AI agents real interactive terminal sessions for running REPLs, SSH, database clients, and any interactive CLI with clean text output and smart completion detection.779 npm20MIT
- FlicenseAqualityDmaintenanceA simple MCP server that exposes a terminal tool, allowing AI agents to execute shell commands.1-
- AlicenseAqualityCmaintenanceGives MCP-compatible AI agents a full local terminal over stdio, enabling shell command execution, file reads and writes, content search, background processes, and stateful tmux sessions with variable capture, auditing, and a configurable command denylist. Requires no deployment or cloud setup.15MIT