Single tool 'run_command' with critical definition deficiencies. No output schema documented. No error handling guidance. This tool exposes a DESTRUCTIVE risk (shell command execution) with minimal guardrails in the definition itself.
Tool name 'run_command' is generic and does not follow verb_noun convention with a specific action. Guidance says avoid generic names like 'run', 'process', 'handle'. Baseline first-word distribution shows get, list, create, search, update, who. 'execute_shell_command' or 'shell_execute' would be clearer.
No output schema documented. LLM cannot reason about what fields to expect (stdout, stderr, exit code, etc.) or plan downstream operations. Violates pattern:tool and mxe:response-shaper.
run_command
Recommendations
Expand tool description to 50-200 characters: explain what the tool does (executes shell commands), when to use it (run system commands safely), any prerequisites (command must be whitelisted), and what it returns (stdout, stderr, exit code). Example: 'Execute a shell command and return stdout/stderr. Supports only whitelisted commands from the security-approved command set. Returns structured output with stdout, stderr, and exit code.'
Add description to 'command' parameter in inputSchema: 'A shell command string to execute. Must be a whitelisted command (e.g., ls, grep, find, curl). Commands are validated against the allowlist before execution. Pass parameters as part of the command string.'
Document output schema explicitly. Add a response field mapping: 'Returns { type: "object", properties: { stdout: string, stderr: string, exit_code: integer } }' so LLM knows what to expect.
Rename tool from 'run_command' to 'execute_shell_command' or 'shell_execute' to follow verb_noun convention and match baseline tool naming patterns.
Implement allowlist-based command filtering instead of blocklist. Define a whitelist of safe commands (e.g., ls, grep, find, curl, git, tar, echo) and reject anything not on it. Return clear error: 'Command not in whitelist. Allowed commands: ls, grep, find, curl, git, tar, echo. For help, ask the user what they need.'
Add error categorization and recovery guidance. Instead of returning raw error strings, structure errors as: { isRetryable: boolean, userFixable: boolean, message: string, suggestion: string }. Example for 'Command not found': { isRetryable: false, userFixable: true, message: 'ls: command not found', suggestion: 'Check if the command is installed or in PATH. Try listing whitelisted commands.' }
Error handling returns error strings in a generic text field with no categorization. No guidance for LLM on whether error is retryable, user-fixable, or fatal. Violates pattern:recovery-guide and pattern:error-classification.
No dry-run or confirmation mechanism for destructive operations. Tool executes arbitrary shell commands immediately. Violates pattern:confirmation-request for irreversible operations.
Blacklist-based command filtering (blocklist approach) is security anti-pattern. Allows all commands not on the list, inviting bypass via aliases, shell builtins, or unblock-able escapes (e.g., '/bin/sh -c rm'). Should use allowlist (whitelist) approach or deny by default. Violates pattern:tool-gateway.
No audit logging of who invoked the tool, what command was run, and what happened. Shell command execution is irreversible and high-risk, must be fully traceable per pattern:audit-trail.
run_command
Implement a confirmation step for high-risk commands (anything modifying files or system state). Add optional 'confirm' parameter or return result with 'input_required' for user confirmation before executing destructive operations (write, delete, modify files).
Add comprehensive audit logging: log to stderr (or structured logger) every invocation with timestamp, calling user/context, requested command, validation result, and exit status. Example: '[AUDIT] 2024-12-15T10:30:45Z user=agent cmd='ls /home' valid=true exit=0'.
Add rate limiting to prevent runaway agents from overwhelming the system with command invocations. Reject if >100 commands per minute from same agent. Return: 'Rate limit exceeded: max 100 commands/min. Try again in X seconds.'
Strip sensitive data from stderr/stdout (API keys, passwords, tokens). If stdout contains patterns like 'api_key=xxx' or 'token=xxx', redact before returning to LLM.