Skip to main content
Glama
nickgnd

Tmux MCP Server

by nickgnd

find-session

Locate a specific tmux session by its name to enable AI assistants to interact with terminal content and manage session control.

Instructions

Find a tmux session by name

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYesName of the tmux session to find

Implementation Reference

  • The primary handler function for the "find-session" MCP tool. It takes the session name, calls the tmux helper to find it, and returns formatted JSON or error text.
    async ({ name }) => {
      try {
        const session = await tmux.findSessionByName(name);
        return {
          content: [{
            type: "text",
            text: session ? JSON.stringify(session, null, 2) : `Session not found: ${name}`
          }]
        };
      } catch (error) {
        return {
          content: [{
            type: "text",
            text: `Error finding tmux session: ${error}`
          }],
          isError: true
        };
      }
    }
  • Input schema using Zod for the tool's 'name' parameter.
    {
      name: z.string().describe("Name of the tmux session to find")
    },
  • src/index.ts:53-78 (registration)
    Registration of the "find-session" tool on the MCP server, specifying name, description, schema, and handler.
    server.tool(
      "find-session",
      "Find a tmux session by name",
      {
        name: z.string().describe("Name of the tmux session to find")
      },
      async ({ name }) => {
        try {
          const session = await tmux.findSessionByName(name);
          return {
            content: [{
              type: "text",
              text: session ? JSON.stringify(session, null, 2) : `Session not found: ${name}`
            }]
          };
        } catch (error) {
          return {
            content: [{
              type: "text",
              text: `Error finding tmux session: ${error}`
            }],
            isError: true
          };
        }
      }
    );
  • Supporting helper function that implements the session lookup logic by listing all sessions and filtering by name.
    export async function findSessionByName(name: string): Promise<TmuxSession | null> {
      try {
        const sessions = await listSessions();
        return sessions.find(session => session.name === name) || null;
      } catch (error) {
        return null;
      }
    }
  • TypeScript interface defining the structure of a TmuxSession object returned by the tool.
    export interface TmuxSession {
      id: string;
      name: string;
      attached: boolean;
      windows: number;
    }

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