list-sessions
Displays all active tmux sessions for interaction or management, enabling users to monitor and control terminal sessions efficiently via the Tmux MCP Server.
Instructions
List all active tmux sessions
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:32-49 (handler)The handler function for the 'list-sessions' tool. It calls tmux.listSessions() to get the list of sessions and returns them formatted as JSON text content, with error handling.try { const sessions = await tmux.listSessions(); return { content: [{ type: "text", text: JSON.stringify(sessions, null, 2) }] }; } catch (error) { return { content: [{ type: "text", text: `Error listing tmux sessions: ${error}` }], isError: true }; } }
- src/index.ts:27-50 (registration)Registration of the 'list-sessions' tool using server.tool(), including name, description, empty input schema, and inline handler.server.tool( "list-sessions", "List all active tmux sessions", {}, async () => { try { const sessions = await tmux.listSessions(); return { content: [{ type: "text", text: JSON.stringify(sessions, null, 2) }] }; } catch (error) { return { content: [{ type: "text", text: `Error listing tmux sessions: ${error}` }], isError: true }; } } );
- src/tmux.ts:82-97 (helper)Helper function listSessions() that executes the tmux 'list-sessions' command, parses the output into TmuxSession objects, and returns the array of sessions.export async function listSessions(): Promise<TmuxSession[]> { const format = "#{session_id}:#{session_name}:#{?session_attached,1,0}:#{session_windows}"; const output = await executeTmux(`list-sessions -F '${format}'`); if (!output) return []; return output.split('\n').map(line => { const [id, name, attached, windows] = line.split(':'); return { id, name, attached: attached === '1', windows: parseInt(windows, 10) }; }); }
- src/tmux.ts:8-13 (schema)TypeScript interface defining the structure of a TmuxSession, used as the output type for listSessions() and thus the tool response.export interface TmuxSession { id: string; name: string; attached: boolean; windows: number; }