Skip to main content
Glama
mr-wolf-gb

Smart Shell MCP Server

by mr-wolf-gb

Execute a project-aware command

executeCommand

Executes project-specific commands by translating them for the target operating system and applying configured overrides. Supports custom CLI arguments, shell selection, and virtual environment activation.

Instructions

Executes a command after applying project overrides and OS translation

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
projectNameYesProject name used to select overrides
commandKeyYesLogical command key, e.g. install, run, test
argsNoExtra CLI args to append
optionsNo

Implementation Reference

  • src/server.ts:263-381 (registration)
    Registration of the 'executeCommand' tool via server.registerTool() with schema definition
    server.registerTool(
      "executeCommand",
      {
        title: "Execute a project-aware command",
        description: "Executes a command after applying project overrides and OS translation",
        inputSchema: {
          projectName: z.string().describe("Project name used to select overrides"),
          commandKey: z.string().describe("Logical command key, e.g. install, run, test"),
          args: z.array(z.string()).optional().describe("Extra CLI args to append"),
          options: z.object({
            shell: z.enum(["auto", "cmd", "powershell", "bash"]).optional(),
            activateVenv: z.enum(["auto", "on", "off"]).optional(),
            venvPath: z.string().optional(),
            cwd: z.string().optional(),
            env: z.record(z.string()).optional()
          }).optional()
        }
      },
      async ({ projectName, commandKey, args, options }) => {
        const os = getOS();
        const cmdMap = await loadJson<any>(COMMAND_MAP_PATH, { base: {} });
        const projectCmd = await resolveProjectCommand(projectName, commandKey);
        const flavor = await detectProjectFlavor();
    
        if (!projectCmd) {
          const result = {
            errorCode: "COMMAND_NOT_FOUND",
            message: `No command mapping found for key "${commandKey}"`,
            suggestion: undefined as string | undefined
          };
          return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
        }
    
        const translated = translateCommandForOS(projectCmd, os, cmdMap);
        const fullBase = [translated, ...(args || []).map(quoteArg)].filter(Boolean).join(" ");
    
        const cwd = options?.cwd || process.cwd();
        const selShell = (options?.shell || "auto") as "auto" | "cmd" | "powershell" | "bash";
        const activatePref = (options?.activateVenv || "auto") as "auto" | "on" | "off";
    
        function findVenv(base?: string) {
          const candidates = base ? [base] : [".venv", "venv", "env"];
          for (const c of candidates) {
            const p = path.resolve(cwd, c);
            if (!fssync.existsSync(p)) continue;
            const posix = path.join(p, "bin", "activate");
            const winCmd = path.join(p, "Scripts", "activate.bat");
            const winPwsh = path.join(p, "Scripts", "Activate.ps1");
            const out: any = { root: p };
            if (fssync.existsSync(posix)) out.posix = posix;
            if (fssync.existsSync(winCmd)) out.winCmd = winCmd;
            if (fssync.existsSync(winPwsh)) out.winPwsh = winPwsh;
            if (out.posix || out.winCmd || out.winPwsh) return out;
          }
          return undefined;
        }
    
        const venvInfo = findVenv(options?.venvPath);
        const containsPy = /\b(python|pip|uvicorn|pytest|flask|django|poetry|pipenv)\b/i.test(fullBase);
        const shouldActivate = activatePref === "on" || (activatePref === "auto" && !!venvInfo && containsPy);
    
        function escapePwsh(s: string) {
          return s.replace(/`/g, "``").replace(/"/g, "`\"");
        }
    
        let final = fullBase;
        if (shouldActivate && venvInfo) {
          if (os === "windows") {
            if (selShell === "powershell") {
              const act = venvInfo.winPwsh || venvInfo.winCmd;
              if (act && venvInfo.winPwsh) {
                final = `powershell -NoProfile -ExecutionPolicy Bypass -Command "& { . '${venvInfo.winPwsh.replace(/\\/g, "/")}'; ${escapePwsh(fullBase)} }"`;
              } else if (act && venvInfo.winCmd) {
                final = `call \"${venvInfo.winCmd}\" && ${fullBase}`;
              } else {
                final = `powershell -NoProfile -ExecutionPolicy Bypass -Command "${escapePwsh(fullBase)}"`;
              }
            } else {
              if (venvInfo.winCmd) {
                final = `call "${venvInfo.winCmd}" && ${fullBase}`;
              }
            }
          } else {
            if (venvInfo.posix) {
              final = `. "${venvInfo.posix}" && ${fullBase}`;
            }
          }
        } else {
          if (os === "windows" && selShell === "powershell") {
            final = `powershell -NoProfile -ExecutionPolicy Bypass -Command "${escapePwsh(fullBase)}"`;
          } else if (os !== "windows" && selShell === "bash") {
            final = `/bin/bash -lc ${quoteArg(fullBase)}`;
          }
        }
    
        const run = await runShell(final);
        if (run.exitCode !== 0) {
          const suggestion = buildSuggestion(projectCmd, run.stderr, flavor, commandKey);
          const result = {
            errorCode: "COMMAND_FAILED",
            message: `Command failed with exit code ${run.exitCode}`,
            suggestion,
            resolvedCommand: final,
            stdout: run.stdout,
            stderr: run.stderr,
            exitCode: run.exitCode
          };
          return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
        }
    
        const output = {
          stdout: run.stdout,
          stderr: run.stderr,
          exitCode: run.exitCode,
          resolvedCommand: final
        };
        return { content: [{ type: "text", text: JSON.stringify(output, null, 2) }] };
      }
    );
  • Input schema for executeCommand: defines projectName, commandKey, args, and options (shell, activateVenv, venvPath, cwd, env)
    {
      title: "Execute a project-aware command",
      description: "Executes a command after applying project overrides and OS translation",
      inputSchema: {
        projectName: z.string().describe("Project name used to select overrides"),
        commandKey: z.string().describe("Logical command key, e.g. install, run, test"),
        args: z.array(z.string()).optional().describe("Extra CLI args to append"),
        options: z.object({
          shell: z.enum(["auto", "cmd", "powershell", "bash"]).optional(),
          activateVenv: z.enum(["auto", "on", "off"]).optional(),
          venvPath: z.string().optional(),
          cwd: z.string().optional(),
          env: z.record(z.string()).optional()
        }).optional()
      }
  • Handler function for executeCommand: resolves project command, translates for OS, handles venv activation, runs shell command, and returns result/suggestion
    async ({ projectName, commandKey, args, options }) => {
      const os = getOS();
      const cmdMap = await loadJson<any>(COMMAND_MAP_PATH, { base: {} });
      const projectCmd = await resolveProjectCommand(projectName, commandKey);
      const flavor = await detectProjectFlavor();
    
      if (!projectCmd) {
        const result = {
          errorCode: "COMMAND_NOT_FOUND",
          message: `No command mapping found for key "${commandKey}"`,
          suggestion: undefined as string | undefined
        };
        return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
      }
    
      const translated = translateCommandForOS(projectCmd, os, cmdMap);
      const fullBase = [translated, ...(args || []).map(quoteArg)].filter(Boolean).join(" ");
    
      const cwd = options?.cwd || process.cwd();
      const selShell = (options?.shell || "auto") as "auto" | "cmd" | "powershell" | "bash";
      const activatePref = (options?.activateVenv || "auto") as "auto" | "on" | "off";
    
      function findVenv(base?: string) {
        const candidates = base ? [base] : [".venv", "venv", "env"];
        for (const c of candidates) {
          const p = path.resolve(cwd, c);
          if (!fssync.existsSync(p)) continue;
          const posix = path.join(p, "bin", "activate");
          const winCmd = path.join(p, "Scripts", "activate.bat");
          const winPwsh = path.join(p, "Scripts", "Activate.ps1");
          const out: any = { root: p };
          if (fssync.existsSync(posix)) out.posix = posix;
          if (fssync.existsSync(winCmd)) out.winCmd = winCmd;
          if (fssync.existsSync(winPwsh)) out.winPwsh = winPwsh;
          if (out.posix || out.winCmd || out.winPwsh) return out;
        }
        return undefined;
      }
    
      const venvInfo = findVenv(options?.venvPath);
      const containsPy = /\b(python|pip|uvicorn|pytest|flask|django|poetry|pipenv)\b/i.test(fullBase);
      const shouldActivate = activatePref === "on" || (activatePref === "auto" && !!venvInfo && containsPy);
    
      function escapePwsh(s: string) {
        return s.replace(/`/g, "``").replace(/"/g, "`\"");
      }
    
      let final = fullBase;
      if (shouldActivate && venvInfo) {
        if (os === "windows") {
          if (selShell === "powershell") {
            const act = venvInfo.winPwsh || venvInfo.winCmd;
            if (act && venvInfo.winPwsh) {
              final = `powershell -NoProfile -ExecutionPolicy Bypass -Command "& { . '${venvInfo.winPwsh.replace(/\\/g, "/")}'; ${escapePwsh(fullBase)} }"`;
            } else if (act && venvInfo.winCmd) {
              final = `call \"${venvInfo.winCmd}\" && ${fullBase}`;
            } else {
              final = `powershell -NoProfile -ExecutionPolicy Bypass -Command "${escapePwsh(fullBase)}"`;
            }
          } else {
            if (venvInfo.winCmd) {
              final = `call "${venvInfo.winCmd}" && ${fullBase}`;
            }
          }
        } else {
          if (venvInfo.posix) {
            final = `. "${venvInfo.posix}" && ${fullBase}`;
          }
        }
      } else {
        if (os === "windows" && selShell === "powershell") {
          final = `powershell -NoProfile -ExecutionPolicy Bypass -Command "${escapePwsh(fullBase)}"`;
        } else if (os !== "windows" && selShell === "bash") {
          final = `/bin/bash -lc ${quoteArg(fullBase)}`;
        }
      }
    
      const run = await runShell(final);
      if (run.exitCode !== 0) {
        const suggestion = buildSuggestion(projectCmd, run.stderr, flavor, commandKey);
        const result = {
          errorCode: "COMMAND_FAILED",
          message: `Command failed with exit code ${run.exitCode}`,
          suggestion,
          resolvedCommand: final,
          stdout: run.stdout,
          stderr: run.stderr,
          exitCode: run.exitCode
        };
        return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
      }
    
      const output = {
        stdout: run.stdout,
        stderr: run.stderr,
        exitCode: run.exitCode,
        resolvedCommand: final
      };
      return { content: [{ type: "text", text: JSON.stringify(output, null, 2) }] };
    }
  • runShell helper: spawns a shell command and collects stdout/stderr/exitCode
    async function runShell(command: string): Promise<{ stdout: string; stderr: string; exitCode: number; }>{
      return new Promise((resolve) => {
        const child = spawn(command, { shell: true, windowsHide: true });
        let stdout = "";
        let stderr = "";
        child.stdout.on("data", (d: Buffer) => { stdout += d.toString(); });
        child.stderr.on("data", (d: Buffer) => { stderr += d.toString(); });
        child.on("close", (code: number | null) => {
          resolve({ stdout, stderr, exitCode: code ?? 0 });
        });
      });
    }
  • translateCommandForOS helper: translates a command string for the current OS using command map overrides
    function translateCommandForOS(raw: string, os: "windows" | "linux" | "darwin", map: any): string {
      const segments = splitPipelines(raw);
      return segments
        .map((seg) => {
          if (["&&", "||", "|", ";"].includes(seg)) return seg;
          return translateSingle(seg, os, map);
        })
        .join(" ");
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations provided; description discloses only that overrides and OS translation occur, but lacks details on safety, error cases, or side effects, which is insufficient for a command execution tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Single sentence, no wasted words, but could benefit from brief usage guidelines to improve without sacrificing conciseness.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a tool with 4 parameters, nested options, no annotations, and no output schema, the description lacks information on return value, parameter roles, and behavioral details like error handling, making it incomplete.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Description does not elaborate on any parameters; only the schema provides descriptions. With 75% schema coverage, description could have clarified missing option parameter semantics but did not. Thus no added semantic value.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool executes a command with project overrides and OS translation, distinguishing it from sibling tools like getProjectCommands which retrieves commands. It provides a specific verb and resource.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No usage guidelines provided; description does not advise when to use this tool versus sibling tools like translateCommand or getProjectCommands.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/mr-wolf-gb/smart-shell-mcp'

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