Skip to main content
Glama
nickgnd

Tmux MCP Server

by nickgnd

create-window

Create a new named window within a tmux session to organize terminal workspaces and manage multiple command-line tasks.

Instructions

Create a new window in a tmux session

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sessionIdYesID of the tmux session
nameYesName for the new window

Implementation Reference

  • src/index.ts:200-228 (registration)
    Registration of the MCP 'create-window' tool, including input schema and inline handler function that calls tmux.createWindow
    server.tool(
      "create-window",
      "Create a new window in a tmux session",
      {
        sessionId: z.string().describe("ID of the tmux session"),
        name: z.string().describe("Name for the new window")
      },
      async ({ sessionId, name }) => {
        try {
          const window = await tmux.createWindow(sessionId, name);
          return {
            content: [{
              type: "text",
              text: window
                ? `Window created: ${JSON.stringify(window, null, 2)}`
                : `Failed to create window: ${name}`
            }]
          };
        } catch (error) {
          return {
            content: [{
              type: "text",
              text: `Error creating window: ${error}`
            }],
            isError: true
          };
        }
      }
    );
  • Input schema for create-window tool using Zod validation
    {
      sessionId: z.string().describe("ID of the tmux session"),
      name: z.string().describe("Name for the new window")
    },
  • MCP tool handler for create-window, which delegates to tmux.createWindow and formats response
    async ({ sessionId, name }) => {
      try {
        const window = await tmux.createWindow(sessionId, name);
        return {
          content: [{
            type: "text",
            text: window
              ? `Window created: ${JSON.stringify(window, null, 2)}`
              : `Failed to create window: ${name}`
          }]
        };
      } catch (error) {
        return {
          content: [{
            type: "text",
            text: `Error creating window: ${error}`
          }],
          isError: true
        };
      }
  • Core implementation of createWindow: executes tmux new-window command and retrieves the new window info
    export async function createWindow(sessionId: string, name: string): Promise<TmuxWindow | null> {
      const output = await executeTmux(`new-window -t '${sessionId}' -n '${name}'`);
      const windows = await listWindows(sessionId);
      return windows.find(window => window.name === name) || null;
    }
  • Helper function listWindows used by createWindow to find the newly created window
    export async function listWindows(sessionId: string): Promise<TmuxWindow[]> {
      const format = "#{window_id}:#{window_name}:#{?window_active,1,0}";
      const output = await executeTmux(`list-windows -t '${sessionId}' -F '${format}'`);
    
      if (!output) return [];
    
      return output.split('\n').map(line => {
        const [id, name, active] = line.split(':');
        return {
          id,
          name,
          active: active === '1',
          sessionId
        };
      });
    }

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