Skip to main content
Glama

translateCommand

Adapts shell commands for different operating systems by translating generic commands into OS-specific syntax for cross-platform execution.

Instructions

Show how a generic command would be adapted for the current OS

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
rawCommandYes

Implementation Reference

  • The main execution logic for the 'translateCommand' tool: loads the command map, translates the raw command for the current OS using the helper translateCommandForOS, and returns the original and translated commands.
    async ({ rawCommand }) => { const os = getOS(); const cmdMap = await loadJson<any>(COMMAND_MAP_PATH, { base: {} }); const translated = translateCommandForOS(rawCommand, os, cmdMap); return { content: [{ type: "text", text: JSON.stringify({ os, original: rawCommand, translated }, null, 2) }] }; }
  • Input schema defining the required 'rawCommand' string parameter for the tool.
    { title: "Translate a raw command for this OS", description: "Show how a generic command would be adapted for the current OS", inputSchema: { rawCommand: z.string() } },
  • src/server.ts:422-435 (registration)
    Registers the 'translateCommand' tool on the MCP server with its schema and handler function.
    server.registerTool( "translateCommand", { title: "Translate a raw command for this OS", description: "Show how a generic command would be adapted for the current OS", inputSchema: { rawCommand: z.string() } }, async ({ rawCommand }) => { const os = getOS(); const cmdMap = await loadJson<any>(COMMAND_MAP_PATH, { base: {} }); const translated = translateCommandForOS(rawCommand, os, cmdMap); return { content: [{ type: "text", text: JSON.stringify({ os, original: rawCommand, translated }, null, 2) }] }; } );
  • Helper function that performs the OS-specific command translation by splitting pipelines and mapping individual commands using the provided map.
    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(" "); }

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