mcp-terminal-runner
v0.2.2
Published
MCP server for executing shell commands safely
Readme
MCP Terminal Runner
An MCP server that allows AI agents to execute terminal commands on the host system.
Features
- Execute Command: Run shell commands and retrieve stdout, stderr, and exit code. Supports pipes, redirects, and command chaining (e.g.,
&&). - Security: Strict allowlist system via
ALLOWED_COMMANDSenvironment variable. - Cross-Platform: Works on Linux, macOS, and Windows.
Prerequisites
- Node.js (version 18 or higher)
Configuration
Security: Allowed Commands
For security reasons, this server requires an explicit list of allowed commands. This is configured via the ALLOWED_COMMANDS environment variable.
- Format: Comma-separated list of command binaries (e.g.,
ls,cat,echo). - Wildcard: Set to
*to allow ALL commands (⚠️ DANGEROUS: Only use in trusted environments). - Validation: The server validates only the first command in the chain against the allowlist. For example, in
echo hello && ls, onlyechois checked.
Security (Optional): Allowed Working Directory Roots
If you enable cwd (see tool input below), you can optionally restrict which working directories are allowed via ALLOWED_CWD_ROOTS.
- Format: Comma-separated list of allowed root paths.
- Behavior:
- If unset or empty,
cwdis not restricted (any existing directory is allowed). - If set, the resolved and canonical
cwdmust be within at least one configured root. - If set and any configured root cannot be canonicalized (e.g., does not exist), requests that provide
cwdare rejected (configuration error).
- If unset or empty,
Usage
MCP Client Configuration
Add the following to your MCP client configuration (e.g., VS Code settings.json):
Basic Configuration
{
"mcpServers": {
"terminal-runner": {
"command": "npx",
"args": ["-y", "mcp-terminal-runner"],
"env": {
"ALLOWED_COMMANDS": "ls,cat,grep,echo"
}
}
}
}Configuration with Allowed Working Directories
{
"mcpServers": {
"terminal-runner": {
"command": "npx",
"args": ["-y", "mcp-terminal-runner"],
"env": {
"ALLOWED_COMMANDS": "ls,cat,grep,echo",
"ALLOWED_CWD_ROOTS": "/home/user/projects,/tmp"
}
}
}
}Available Tools
execute_command
Executes a shell command.
- Input:
command(string): The full command string to execute (e.g.,ls -la src).cwd(string, optional): Working directory to execute the command within.
- Output:
- Returns a YAML-formatted string containing:
exit_code: The command's exit code.stdout: Standard output.stderr: Standard error.
- Returns a YAML-formatted string containing:
Development
Setup
- Clone the repository:
git clone <repository-url>
cd mcp-terminal-runner- Install dependencies:
npm install- Build the project:
npm run buildAvailable Scripts
npm run build- Build the TypeScript projectnpm run dev- Run in development modenpm start- Run the built JavaScript versionnpm run check- Check code with Ultracitenpm test- Run tests with Vitest
Project Structure
mcp-terminal-runner/
├── src/
│ └── index.ts # Main server implementation
├── dist/ # Built JavaScript files
├── .husky/ # Git hooks
├── biome.json # Biome configuration
├── tsconfig.json # TypeScript configuration
├── package.json # Project dependencies and scripts
└── README.md # This fileLicense
MIT License - see LICENSE file for details.
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Run
npm run qualityto ensure code quality - Commit your changes (Husky will run pre-commit hooks)
- Push to your branch
- Create a Pull Request
Troubleshooting
Common Issues
- Server not starting: Ensure all dependencies are installed and the project is built
- Tools not appearing: Check that the MCP client configuration points to the correct path
- Permission errors: Make sure the built JavaScript file has execute permissions
Debug Mode
To enable debug logging, set the environment variable:
DEBUG=mcp* npm start