loading…
Search for a command to run...
loading…
A secure MCP server for shell operations, terminal management, and process control, enabling AI assistants to safely execute commands and manage interactive ses
A secure MCP server for shell operations, terminal management, and process control, enabling AI assistants to safely execute commands and manage interactive sessions.
CI License: MIT TypeScript Node.js MCP npm
A secure and comprehensive Model Context Protocol (MCP) server for shell operations, terminal management, and process control.
Choose your preferred installation method:
npm install -g @mako10k/mcp-shell-server
After installation, verify the CLI:
mcp-shell-server --version
mcp-shell-server --help
git clone https://github.com/mako10k/mcp-shell-server.git
cd mcp-shell-server
npm install
npm run build
You can also link locally for user-level usage without sudo:
npm link
mcp-shell-server --help
{
"mcpServers": {
"mcp-shell-server": {
"command": "mcp-shell-server"
}
}
}
Note: After global installation, you can use mcp-shell-server directly or npx @mako10k/mcp-shell-server
Create .vscode/mcp.json:
{
"servers": {
"mcp-shell-server": {
"type": "stdio",
"command": "mcp-shell-server",
"env": {
"MCP_SHELL_SECURITY_MODE": "enhanced",
"MCP_SHELL_ELICITATION": "true"
}
}
}
}
Add to MCP settings:
{
"servers": {
"mcp-shell-server": {
"type": "stdio",
"command": "mcp-shell-server"
}
}
}
📚 Detailed Setup Guides | 📁 Configuration Examples
✅ COMPLETE - The MCP Shell Server is fully implemented and ready for production use.
input_output_id parameter# Clone the repository
git clone https://github.com/mako10k/mcp-shell-server.git
cd mcp-shell-server
# Install dependencies
npm install
# Build the project
npm run build
# Start the MCP server
npm start
# Or run in development mode
npm run dev
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
const transport = new StdioClientTransport({
command: 'node',
args: ['dist/index.js']
});
const client = new Client(
{ name: 'mcp-client', version: '1.0.0' },
{ capabilities: {} }
);
await client.connect(transport);
// Execute a shell command
const result = await client.request({
method: 'tools/call',
params: {
name: 'shell_execute',
arguments: {
command: 'echo "Hello from MCP Shell Server!"',
execution_mode: 'foreground'
}
}
});
console.log(result);
Automatic guidance when commands transition to background execution:
// When a command times out or exceeds size limits, get helpful guidance
const result = await client.request({
method: 'tools/call',
params: {
name: 'shell_execute',
arguments: {
command: 'find /usr -name "*.so"',
execution_mode: 'adaptive',
max_output_size: 1024
}
}
});
// Response includes guidance for pipeline processing
console.log(result.guidance.pipeline_usage);
// "Background process active. Use "input_output_id": "xyz" for real-time processing"
Smart cleanup suggestions and automated maintenance:
// Get cleanup suggestions
const suggestions = await client.request({
method: 'tools/call',
params: {
name: 'get_cleanup_suggestions',
arguments: {
max_age_hours: 24,
max_size_mb: 50
}
}
});
// Perform automatic cleanup with retention policies
const cleanup = await client.request({
method: 'tools/call',
params: {
name: 'perform_auto_cleanup',
arguments: {
dry_run: false,
max_age_hours: 24,
preserve_recent: 10
}
}
});
// Send Ctrl+C to interrupt a process
await client.request({
method: 'tools/call',
params: {
name: 'terminal_send_input',
arguments: {
terminal_id: 'terminal_123',
input: '^C',
control_codes: true
}
}
});
// Send ANSI escape sequences for colored output
await client.request({
method: 'tools/call',
params: {
name: 'terminal_send_input',
arguments: {
terminal_id: 'terminal_123',
input: '\\x1b[31mRed Text\\x1b[0m',
control_codes: true
}
}
});
// Only allow input to bash processes
await client.request({
method: 'tools/call',
params: {
name: 'terminal_send_input',
arguments: {
terminal_id: 'terminal_123',
input: 'echo "secure command"',
send_to: 'bash',
execute: true
}
}
});
// Target specific process by PID
await client.request({
method: 'tools/call',
params: {
name: 'terminal_send_input',
arguments: {
terminal_id: 'terminal_123',
input: '^C',
send_to: 'pid:12345',
control_codes: true
}
}
});
npm start
mcp-shell-server --help
mcp-shell-server --version
The server supports various environment variables (see sections below), such as:
BACKOFFICE_ENABLED, BACKOFFICE_PORTEXECUTION_BACKEND and EXECUTOR_* for remote executorMCP_SHELL_DEFAULT_WORKDIR, MCP_SHELL_ALLOWED_WORKDIRSMCP_DISABLED_TOOLS, LOG_LEVELnpm run dev
npm run build
npm test
The server can be configured through environment variables or by calling the security restriction tools at runtime.
Set MCP_DISABLED_TOOLS to a comma-separated list of tool names to disable.
Disabled tools will not appear in the tool list and cannot be called.
The server supports the following environment variables for configuration:
MCP_DISABLED_TOOLS: Comma-separated list of tool names to disableexport MCP_DISABLED_TOOLS="terminal_create,process_terminate"
MCP_SHELL_DEFAULT_WORKDIR: Set the default working directory for all command executionsexport MCP_SHELL_DEFAULT_WORKDIR="/home/user/projects"
MCP_SHELL_ALLOWED_WORKDIRS: Comma-separated list of allowed working directoriesexport MCP_SHELL_ALLOWED_WORKDIRS="/home/user,/tmp,/var/log"
MCP_SHELL_SECURITY_MODE: Set the default security mode (permissive, restrictive, enhanced, enhanced-fast, or custom)export MCP_SHELL_SECURITY_MODE="enhanced"
MCP_SHELL_ELICITATION: Enable user intent elicitation for complex scenarios (for enhanced modes)export MCP_SHELL_ELICITATION="true"
MCP_SHELL_LLM_API_KEY: API key for LLM-based safety evaluation (optional, falls back to MCP sampling)MCP_SHELL_LLM_TIMEOUT: Timeout for LLM evaluation in seconds (default: 30)MCP_SHELL_MAX_EXECUTION_TIME: Default maximum execution time in secondsexport MCP_SHELL_MAX_EXECUTION_TIME="300"
MCP_SHELL_MAX_MEMORY_MB: Default maximum memory usage in MBexport MCP_SHELL_MAX_MEMORY_MB="1024"
# Security settings
export MCP_SHELL_SECURITY_MODE="restrictive"
export MCP_SHELL_MAX_EXECUTION_TIME="300"
export MCP_SHELL_MAX_MEMORY_MB="1024"
# Working directory settings
export MCP_SHELL_DEFAULT_WORKDIR="/home/user/projects"
export MCP_SHELL_ALLOWED_WORKDIRS="/home/user,/tmp"
# Tool restrictions
export MCP_DISABLED_TOOLS="process_terminate,delete_execution_outputs"
# Start the server
npm start
Note: Additional configuration options can be set at runtime using the security_set_restrictions tool for more granular control over allowed/blocked commands, directories, and other security parameters.
Use the security_set_restrictions tool to dynamically configure security settings:
{
"security_mode": "custom",
"allowed_commands": ["ls", "cat", "grep"],
"blocked_commands": ["rm", "sudo"],
"allowed_directories": ["/tmp", "/home/user"],
"max_execution_time": 300,
"max_memory_mb": 1024
}
Security Modes:
permissive: Allow most commands with basic safety checksrestrictive: Only allow read-only commands (ls, cat, grep, etc.)enhanced: AI-powered safety evaluation with LLM-based analysis (recommended)enhanced-fast: Optimized enhanced mode for better performancecustom: Use detailed configuration with allowed/blocked commandsshell_executeExecute shell commands with various execution modes. Can also create new interactive terminal sessions.
Parameters:
command (required): Command to executeexecution_mode: Execution strategy for the command:'foreground': Wait for command completion within timeout_seconds. Best for quick commands'background': Run asynchronously, monitor via process_list. Best for long-running processes'detached': Fire-and-forget execution, minimal monitoring. Best for independent processes'adaptive' (default): Start foreground for foreground_timeout_seconds, then switch to background if needed. Best for unknown execution timesinput_output_id: Use output from another command as input (Pipeline feature)working_directory: Working directoryenvironment_variables: Environment variablestimeout_seconds: Maximum execution timeout (all modes respect this limit)foreground_timeout_seconds: For adaptive mode: initial foreground phase timeout (default: 10s)return_partial_on_timeout: Return partial output on timeoutmax_output_size: Maximum output sizecreate_terminal: Create new interactive terminal sessionterminal_shell: Shell type for new terminal ('bash', 'zsh', 'fish', etc.)terminal_dimensions: Terminal dimensions {width, height}Examples:
Regular command execution:
{
"command": "ls -la",
"execution_mode": "foreground"
}
Adaptive execution with intelligent background transition:
{
"command": "long-running-process",
"execution_mode": "adaptive",
"foreground_timeout_seconds": 10,
"timeout_seconds": 300,
"return_partial_on_timeout": true
}
Pipeline Feature - Command Chaining: The MCP Shell Server supports command chaining through the Pipeline feature, allowing output from one command to be used as input for another command:
// Step 1: Execute first command and get output_id
{
"command": "cat input.txt",
"execution_mode": "foreground"
}
// Response includes: "output_id": "abc123..."
// Step 2: Use output from first command as input for second command
{
"command": "grep 'pattern'",
"execution_mode": "foreground",
"input_output_id": "abc123..."
}
Important Notes:
|)shell_execute calloutput_id from first command's response as input_output_id for second commandAdaptive Mode Features:
foreground_timeout_seconds is reachedmax_output_size is reached (for efficiency)transition_reason in response: "foreground_timeout" or "output_size_limit"timeout_seconds limit for background phaseCreate new terminal session:
{
"command": "vim file.txt",
"create_terminal": true,
"terminal_shell": "bash",
"terminal_dimensions": {"width": 120, "height": 40}
}
process_get_executionGet detailed information about a command execution.
shell_set_default_workdirSet the default working directory for command execution.
process_listList running processes with filtering options.
process_terminateSafely terminate processes with signal control.
process_monitorStart real-time process monitoring.
terminal_createCreate interactive terminal sessions.
terminal_send_inputSend input to terminals.
terminal_get_outputGet terminal output with ANSI support.
terminal_get_infoGet detailed terminal information.
terminal_resizeResize terminal dimensions.
terminal_closeClose terminal sessions.
list_execution_outputsList managed output files with filtering.
read_execution_outputRead output file contents safely.
delete_execution_outputsDelete output files with confirmation.
security_set_restrictionsConfigure security restrictions.
monitoring_get_statsGet system-wide statistics.
mcp-shell-server/
├── src/
│ ├── core/ # Core managers
│ │ ├── process-manager.ts
│ │ ├── terminal-manager.ts
│ │ ├── file-manager.ts
│ │ └── monitoring-manager.ts
│ ├── security/ # Security components
│ │ └── manager.ts
│ ├── tools/ # MCP tool handlers
│ │ └── shell-tools.ts
│ ├── types/ # Type definitions
│ │ ├── index.ts
│ │ └── schemas.ts
│ ├── utils/ # Utilities
│ │ ├── errors.ts
│ │ └── helpers.ts
│ ├── server.ts # Main MCP server
│ └── index.ts # Entry point
└── docs/
└── specification.md
The server provides comprehensive error handling with categorized error codes:
AUTH_*: Authentication and authorization errorsPARAM_*: Parameter validation errors RESOURCE_*: Resource not found or limit errorsEXECUTION_*: Command execution errorsSYSTEM_*: System and internal errorsSECURITY_*: Security policy violationsMIT License - see LICENSE file for details.
Run in your terminal:
claude mcp add mcp-shell-server -- npx Security
Low riskAutomated heuristic from public metadata — not a security guarantee.