MCPconceptHome

Choose documentation 3

latest

Current version

latest
English

Early release libtmux is released, and its APIs may still change between releases. This site's structure and URLs may change too.

MoreLess about this notice

Concept example A working example of the core library. It can change without notice. What concept means

Edit this page on GitHub

tmux MCP, built in Swift

tmux terminal control for AI agents, built on libtmux for Swift with its own implementation of the Model Context Protocol. This server maps tmux's object hierarchy — sessions, windows, panes — into MCP tools grouped by the operation they request. The server enforces the selected groups at the MCP tool boundary.

tmux through MCP

Replay Hover a call to preview the tmux state after it. Use its pin button to hold it. With the replay focused, the arrow keys, Home and End step through the calls.

tmux before the first call.

tmux window of 1 pane
%0 sh
[checks] 0:sh*

tmux after create_session.

tmux window of 1 pane
%0 sh
[checks] 0:sh*

tmux after list_panes: unchanged, the call only reads.

tmux window of 2 panes
%0 sh
%1 sh
[checks] 0:sh*

tmux after split_window.

tmux window of 2 panes
%0 sh
%1 sh
[checks] 0:sh*

tmux after get_tmux_variables: unchanged, the call only reads.

tmux window of 2 panes
%0 sh
$ pytest -q
..                               [100%]
2 passed in 0.00s
%1 sh
[checks] 0:sh*

tmux after run_shell_command.

tmux window of 2 panes
%0 sh
$ pytest -q
..                               [100%]
2 passed in 0.00s
%1 sh
$ cat checks.log
2026-01-01 checks started
2026-01-01 checks finished
[checks] 0:sh*

tmux after run_shell_command.

No sessions

tmux after kill_session.

You

Create a tmux session called checks, split its window into two panes, run pytest -q in one and show checks.log in the other, show me the results, then remove the session.

AgentCreate the session.

create_session Execute {"name":"checks"}
Result
{
"isAttached": false,
"id": "$0",
"windowCount": 1,
"ref": "tmux1_AWXw31wwjyXoEaqBo3la-V4mtPL0vRI4iGVS1yE78h4Y",
"createdAt": 1795061804,
"name": "checks"
}

AgentList the panes in the new session.

list_panes Inspect {"session":"checks"}
Result
{
"panes": [
{
"currentPath": "/home/user/project",
"windowID": "@0",
"isActive": true,
"isAtTop": true,
"isAtBottom": true,
"width": 80,
"isAtRight": true,
"isAtLeft": true,
"ref": "tmux1_BGXw31wwjyXoEaqBo3la-V4QetAYfM5JN9hpsAyrKwx3",
"height": 24,
"currentCommand": "sh",
"isDead": false,
"…": "4 more"
}
]
}

AgentSplit the pane the list returned (%0) in two.

split_window Execute {"paneId":"%0","direction":"right"}
Result
{
"id": "%1",
"height": 24,
"isDead": false,
"ref": "tmux1_BGXw31wwjyXoEaqBo3la-V6jHcgKRph3CM6YZTGyd4fB",
"isAtLeft": false,
"isActive": false,
"windowID": "@0",
"isSynchronized": false,
"width": 39,
"isAtRight": true,
"isAtBottom": true,
"modeCount": 0,
"…": "4 more"
}

AgentRead the window's layout through the pane the list returned (%0).

get_tmux_variables Inspect {"names":["window_layout"],"paneId":"%0"}
Result
{
"values": {
"window_layout": "8205,80x24,0,0{40x24,0,0,0,39x24,41,0,1}"
}
}

AgentRun the tests in the pane the list returned (%0).

run_shell_command Execute {"paneId":"%0","command":"pytest -q"}
Result
{
"pane": "%0",
"droppedLines": 0,
"seconds": 0.449415896,
"exitStatus": 0,
"effectiveTimeout": 30,
"paneRef": "tmux1_BGXw31wwjyXoEaqBo3la-V4QetAYfM5JN9hpsAyrKwx3",
"linesMissed": false,
"output": [
".. [100%]",
"2 passed in 0.00s"
],
"timedOut": false
}

AgentShow the log in the new pane the split returned (%1).

run_shell_command Execute {"paneId":"%1","command":"cat checks.log"}
Result
{
"pane": "%1",
"effectiveTimeout": 30,
"seconds": 0.085019186,
"timedOut": false,
"droppedLines": 0,
"exitStatus": 0,
"paneRef": "tmux1_BGXw31wwjyXoEaqBo3la-V6jHcgKRph3CM6YZTGyd4fB",
"linesMissed": false,
"output": [
"2026-01-01 checks started",
"2026-01-01 checks finished"
]
}

AgentRemove the session once the result is read.

kill_session Teardown {"session":"checks"}
Result
{
"deleted": true,
"sessionId": "$0"
}
Agent

pytest printed 2 passed and checks.log ends with checks finished. I removed the checks session.

1/7

Install

Choose your client and configuration scope, then run the command or paste the configuration.

Terminal
Terminal
Terminal
claude_desktop_config.json
Terminal
.codex/config.toml
Terminal
Terminal
.cursor/mcp.json
~/.cursor/mcp.json
Terminal
Terminal
~/.gemini/config/mcp_config.json
Terminal
libtmux-mcp concept Swift Package Index
First
$ swift build --product libtmux-mcp
$ claude mcp add tmux -- /absolute/path/to/.build/debug/libtmux-mcp
First
$ swift build --product libtmux-mcp
$ claude mcp add tmux --scope user -- /absolute/path/to/.build/debug/libtmux-mcp
First
$ swift build --product libtmux-mcp
$ claude mcp add tmux \
    --scope project \
    -- /absolute/path/to/.build/debug/libtmux-mcp
First
$ swift build --product libtmux-mcp
{
    "mcpServers": {
        "tmux": {
            "command": "/absolute/path/to/.build/debug/libtmux-mcp"
        }
    }
}
First
$ swift build --product libtmux-mcp
$ codex mcp add tmux -- /absolute/path/to/.build/debug/libtmux-mcp
First
$ swift build --product libtmux-mcp
[mcp_servers.tmux]
command = "/absolute/path/to/.build/debug/libtmux-mcp"
First
$ swift build --product libtmux-mcp
$ gemini mcp add --scope user tmux /absolute/path/to/.build/debug/libtmux-mcp
First
$ swift build --product libtmux-mcp
$ gemini mcp add --scope project tmux /absolute/path/to/.build/debug/libtmux-mcp
First
$ swift build --product libtmux-mcp
{
    "mcpServers": {
        "tmux": {
            "command": "/absolute/path/to/.build/debug/libtmux-mcp"
        }
    }
}
First
$ swift build --product libtmux-mcp
{
    "mcpServers": {
        "tmux": {
            "command": "/absolute/path/to/.build/debug/libtmux-mcp"
        }
    }
}
First
$ swift build --product libtmux-mcp
$ grok mcp add --scope user tmux -- /absolute/path/to/.build/debug/libtmux-mcp
First
$ swift build --product libtmux-mcp
$ grok mcp add --scope project tmux -- /absolute/path/to/.build/debug/libtmux-mcp
First
$ swift build --product libtmux-mcp
{
    "mcpServers": {
        "tmux": {
            "command": "/absolute/path/to/.build/debug/libtmux-mcp"
        }
    }
}
First
$ swift build --product libtmux-mcp
$ opencode mcp add tmux -- /absolute/path/to/.build/debug/libtmux-mcp

Writes ~/.claude.json (this project).

Nothing publishes this server as a binary yet. The server takes no flags — which tmux it talks to is environment, so the client config is where you say so.

Writes ~/.claude.json (all projects).

Nothing publishes this server as a binary yet. The server takes no flags — which tmux it talks to is environment, so the client config is where you say so.

Writes .mcp.json (in repo, version-controlled).

Nothing publishes this server as a binary yet. The server takes no flags — which tmux it talks to is environment, so the client config is where you say so.

Nothing publishes this server as a binary yet. The server takes no flags — which tmux it talks to is environment, so the client config is where you say so.

Writes ~/.codex/config.toml.

Nothing publishes this server as a binary yet. The server takes no flags — which tmux it talks to is environment, so the client config is where you say so.

Codex's CLI doesn't support project scope yet — paste this into .codex/config.toml at the repo root.

Nothing publishes this server as a binary yet. The server takes no flags — which tmux it talks to is environment, so the client config is where you say so.

Writes ~/.gemini/settings.json.

Nothing publishes this server as a binary yet. The server takes no flags — which tmux it talks to is environment, so the client config is where you say so.

Writes .gemini/settings.json (in repo).

Nothing publishes this server as a binary yet. The server takes no flags — which tmux it talks to is environment, so the client config is where you say so.

Nothing publishes this server as a binary yet. The server takes no flags — which tmux it talks to is environment, so the client config is where you say so.

Nothing publishes this server as a binary yet. The server takes no flags — which tmux it talks to is environment, so the client config is where you say so.

Writes ~/.grok/config.toml.

Nothing publishes this server as a binary yet. The server takes no flags — which tmux it talks to is environment, so the client config is where you say so.

Writes ./.grok/config.toml (in repo).

Nothing publishes this server as a binary yet. The server takes no flags — which tmux it talks to is environment, so the client config is where you say so.

Nothing publishes this server as a binary yet. The server takes no flags — which tmux it talks to is environment, so the client config is where you say so.

Writes ~/.config/opencode/opencode.jsonc.

Nothing publishes this server as a binary yet. The server takes no flags — which tmux it talks to is environment, so the client config is where you say so.

libtmux-mcp is the Swift stdio executable. LibTmuxMCP is the SwiftPM library product for embedding the same tools. They expose tmux discovery, captures, waits, input, configuration, and process control.

The package requires Swift 6.2 or newer and supports Linux and macOS. The documented Darwin dependency build uses Xcode’s Swift 6.3 toolchain. tmux is required at runtime.

Start here

  • Install points an MCP client at this server.
  • Tools lists the MCP operations, arguments, and results.
  • Guides build the executable and configure its environment.
  • Topics explain toolsets, command waits, and capability discovery.
  • Examples call a tool, then explore server internals.
  • Language API documents embedding and implementation types.

The executable defaults to inspection, management, and execution; a verified dedicated daemon can also receive teardown tools. The embedding initializer defaults to inspection alone. Read tmux://capabilities for the startup selection.

Workspace Manager is a separate library product. The current MCP catalog does not include a workspace-file operation.

Library contract and platform requirements.

Tools by tier

The Swift server groups its tools by what they request. A tier badge tells you how far a call reaches before you approve it. Set LIBTMUX_TOOLSETS to a comma-separated list of tiers, such as inspect,manage, to offer only those tools.

Inspect

Request tmux state and terminal output.

Manage

Change tmux structure or presentation.

  • move_window Manage Move one window appearance to another session.
  • rename_session Manage Set a literal-safe session name.
  • rename_window Manage Set a literal-safe window name.
  • resize_pane Manage Resize one pane by dimensions or a directional amount.
  • resize_window Manage Resize the terminal dimensions reported for one window.
  • select_layout Manage Apply a named layout, a unique abbreviation for the running tmux version, or a checksummed saved layout.
  • select_pane Manage Select one pane as active.
  • select_window Manage Select one exact window appearance.
  • set_history_limit Manage Set the default retained scrollback line limit.
  • set_mouse_enabled Manage Set the global tmux mouse option through a boolean.
  • set_pane_title Manage Set one literal-safe pane title.
  • signal_channel Manage Signal one tmux wait-for channel.
  • swap_pane Manage Swap two panes without changing their identities.
  • wait_for_channel Manage Wait within one deadline for a tmux channel signal.

Execute

Start or drive pane processes, or store state that can control later execution.

  • create_session Execute Create a detached session with a configured pane process.
  • create_window Execute Create a window with a configured pane process.
  • paste_text Execute Paste literal text and an optional newline target-only after two state checks.
  • respawn_pane Execute Restart only the pane's configured process.
  • run_shell_command Execute Run a shell command in a pane with your user's permissions.
  • send_keys Execute Send keys after checking the effective synchronized-pane cohort.
  • send_keys_batch Execute Send an ordered bounded batch with a fresh check for every row.
  • set_synchronize_panes Execute Set the window input default.
  • split_window Execute Create a configured-process pane without accepting command or environment data.

Teardown

Delete tmux objects or retained scrollback. Not reversible.

  • clear_pane_scrollback Teardown Irreversibly discard retained scrollback for one pane.
  • kill_pane Teardown Delete one pane and its running process.
  • kill_session Teardown Delete one session and every window it owns.
  • kill_window Teardown Delete one window and every pane it owns.

Browse every tool, with its arguments, result and protocol data.

Esc
Search in

Type to search.

Reference previewOpen reference