run_command
Execute allowed shell commands including clasp, npm, git, and directory operations to manage Google Apps Script projects and development workflows for revenue tracking systems.
Instructions
Execute allowed shell commands (clasp, npm, git, dir). For clasp commands, run from apps-script folder.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| command | Yes | Command to run (must be in allowed list) | |
| workingDirectory | No | Directory to run command in (optional, defaults to revenue-engine-mcp) |
Implementation Reference
- index.js:595-612 (registration)Registration of the 'run_command' tool including name, description, and input schema definition.{ name: "run_command", description: "Execute allowed shell commands (clasp, npm, git, dir). For clasp commands, run from apps-script folder.", inputSchema: { type: "object", properties: { command: { type: "string", description: "Command to run (must be in allowed list)" }, workingDirectory: { type: "string", description: "Directory to run command in (optional, defaults to revenue-engine-mcp)" } }, required: ["command"] } }
- index.js:850-875 (handler)Main execution logic for the 'run_command' tool. Validates command and directory, executes via child_process.execAsync, returns stdout and stderr.case "run_command": { const { command, workingDirectory } = args; if (!isCommandAllowed(command)) { throw new Error(`Command not allowed: ${command}. Allowed commands: ${Object.keys(ALLOWED_COMMANDS).join(', ')}`); } const cwd = workingDirectory || 'C:\\Users\\Node1\\revenue-engine-mcp'; if (!isPathAllowed(cwd)) { throw new Error(`Working directory not allowed: ${cwd}`); } debugLog(`Running command: ${command} in ${cwd}`); const { stdout, stderr } = await execAsync(command, { cwd }); result = { success: true, command: command, workingDirectory: cwd, stdout: stdout, stderr: stderr }; break; }
- index.js:35-55 (helper)Configuration object defining all allowed commands for the run_command tool.const ALLOWED_COMMANDS = { 'clasp push': 'Sync local files to Google Apps Script', 'clasp pull': 'Sync Google Apps Script to local files', 'clasp deploy': 'Deploy Apps Script as web app', 'clasp status': 'Check sync status', 'clasp list': 'List Apps Script projects', 'npm install': 'Install node packages', 'git status': 'Check git status', 'git add': 'Stage changes', 'git commit': 'Commit changes', 'git init': 'Initialize git repository', 'git remote': 'Manage remote repositories', 'git push': 'Push to remote', 'git branch': 'Manage branches', 'mkdir': 'Create directory', 'md': 'Create directory (Windows)', 'dir': 'List directory contents', 'ls': 'List directory contents', 'del': 'Delete files (Windows)', 'rm': 'Remove files (Unix)', };
- index.js:66-71 (helper)Helper function that checks if a given command starts with any allowed prefix from ALLOWED_COMMANDS.function isCommandAllowed(command) { const cmd = command.trim(); return Object.keys(ALLOWED_COMMANDS).some(allowed => cmd.startsWith(allowed) ); }
- index.js:58-63 (helper)Helper function that validates if a path (used for working directory) is within allowed directories.function isPathAllowed(filePath) { const normalized = filePath.replace(/\//g, '\\'); return ALLOWED_PATHS.some(allowedPath => normalized.startsWith(allowedPath) ); }