Skip to main content
Glama
nickgnd
by nickgnd

list-sessions

Retrieve all active tmux sessions to view, manage, and interact with terminal environments through the Tmux MCP Server.

Instructions

List all active tmux sessions

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • src/index.ts:27-50 (registration)
    Registers the MCP tool 'list-sessions' with server.tool(). The inline async handler fetches sessions using tmux.listSessions() and returns JSON-formatted text content or error.
    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 }; } } );
  • Core handler logic for listing tmux sessions: executes tmux 'list-sessions' with custom format, parses output into TmuxSession array.
    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) }; }); }
  • Type definition (schema) for TmuxSession objects returned by listSessions().
    export interface TmuxSession { id: string; name: string; attached: boolean; windows: number; }
  • Utility helper to execute arbitrary tmux commands, used by listSessions().
    export async function executeTmux(tmuxCommand: string): Promise<string> { try { const { stdout } = await exec(`tmux ${tmuxCommand}`); return stdout.trim(); } catch (error: any) { throw new Error(`Failed to execute tmux command: ${error.message}`); } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/nickgnd/tmux-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server