This project provides a secure Model-Context-Protocol (MCP) server that allows terminal command execution in a controlled environment. It's designed to be used with AI assistants and other clients that need terminal access while keeping confidential information protected.
- Path Restrictions: Only allows command execution in pre-configured directories
- Command Filtering: Optional allowlist/blocklist for commands
- Output Sanitization: Automatically redacts sensitive information
- Resource Limits: Configurable timeouts and output size limits
- Docker Ready: Run in an isolated container for enhanced security
# Install globally
npm install -g terminal-mcp-server
# Or install locally in your project
npm install terminal-mcp-server
# Initialize configuration (creates terminal-tool.json and terminal-security.json)
terminal-mcp-server --init
# Edit the configuration files to specify allowed paths and security settings
# Start the server
terminal-mcp-server
The server includes two levels of security configuration:
-
Basic Path Restriction (
terminal-tool.json
):{ "allowedPaths": [ "/public/data", "/public/scripts" ] }
-
Enhanced Security (
terminal-security.json
):{ "allowedPaths": [ "/public/data", "/public/scripts" ], "commandSecurity": { "enabled": true, "allowedCommands": ["ls", "cat", "grep", "find"], "blockedCommands": ["curl", "wget", "ssh"], "timeoutSeconds": 5 }, "outputFiltering": { "enabled": true } }
# Pull the image
docker pull your-org/terminal-only-mcp-server:latest
# Run with default settings
docker run -d \
-e PUBLIC_DIR_1=/public/data \
-e PUBLIC_DIR_2=/public/scripts \
-v /path/on/host/data:/public/data \
-v /path/on/host/scripts:/public/scripts \
your-org/terminal-only-mcp-server:latest
Any MCP-compatible client can connect to this server. Example with the official SDK:
import { Client } from '@modelcontextprotocol/sdk/client';
import { createCliTransport } from '@modelcontextprotocol/sdk/client/cli';
async function connectToTerminalServer() {
const transport = createCliTransport('/path/to/terminal-only-mcp-server');
const client = new Client();
await client.connect(transport);
// List available tools
const tools = await client.listTools();
console.log(tools);
// Execute a terminal command
const result = await client.callTool('terminal', {
command: 'ls -la',
workingDir: '/public/data'
});
console.log(result.content[0].text);
}
- Isolated Environments: Run the server in a container or virtual machine
- Least Privilege: Allow only necessary paths and commands
- Regular Updates: Keep the server and dependencies updated
- Audit Logs: Monitor the logs for suspicious activity
- Content Review: Validate all files in shared directories
MIT
Contributions are welcome! Please feel free to submit a Pull Request.