Prerelease This site documents an alpha of libtmux. Its structure, URLs and APIs are subject to change.

TypeScript MCP examples

Edit this page on GitHub

@libtmux/mcp 0.1.0-alpha.10 · Source

Connect the server using the setup guide, then call list_sessions from your MCP client.

List sessionsLink to section

This is the params object for an MCP tools/call request. Send it through the connected client:

{
"name": "list_sessions",
"arguments": {}
}

Use the returned session IDs when choosing a window or pane. The tool reference describes this port’s result and optional arguments.

InternalsLink to section

The following examples are for applications that embed or extend the server. Installing and connecting an MCP client does not require this code.

The port’s mcp-agent example connects an MCP client and server with linked in-memory transports. The same tool names and arguments are used over stdio.

Connect an embedded clientLink to section

This function comes from the agent example. It accepts an existing libtmux Server.

import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { InMemoryTransport } from "@modelcontextprotocol/sdk/inMemory.js";
import { createTmuxMcpServer } from "@libtmux/mcp";
import type { Server } from "libtmux/server";
export async function connectAgent(server: Server): Promise<Client> {
const client = new Client({ name: "example", version: "0.0.0" });
const [clientSide, serverSide] = InMemoryTransport.createLinkedPair();
await Promise.all([
createTmuxMcpServer(server, {
environment: { LIBTMUX_TOOLSETS: "inspect,execute" },
}).connect(serverSide),
client.connect(clientSide),
]);
return client;
}

The caller owns the returned client. Close it after use. The complete example adds helpers for run_shell_command, wait_for_text, capture_since, and topology creation.

Run the example’s checksLink to section

From the TypeScript repository after installing its dependencies:

Terminal window
$ bun test examples/mcp-agent

The example tests start real tmux on an isolated socket and drive it through the MCP client. They cover exit status, echoed command text, waits, and successive cursor reads. Rendering this excerpt does not execute those tests.

For declarative application code, see Workspace builder examples.

Esc

Type to search.