SecureShell provides first-class support for the Model Context Protocol, allowing you to expose secure shell execution as an MCP tool for Claude Desktop and other AI applications.
Model Context Protocol (MCP) is a standard for connecting AI assistants to external tools and data sources. It enables Claude Desktop and other AI apps to safely interact with your local environment.
npm install @modelcontextprotocol/sdkcd cookbook/secureshell-ts
npx tsx mcp_server.tsSee the complete implementation in cookbook/secureshell-ts/mcp_server.ts.
Add SecureShell to Claude Desktop's configuration:
macOS/Linux: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"secureshell": {
"command": "npx",
"args": ["-y", "tsx", "/path/to/secureshell/cookbook/secureshell-ts/mcp_server.ts"],
"env": {
"OPENAI_API_KEY": "sk-..."
}
}
}
}The MCP tool exposes a single command:
Tool: execute_shell_command
Inputs:
command- Shell command to executereasoning- Why the command should run
Output: Command result or gatekeeper denial reason
User: "List files in my current directory"
Claude: [Calls execute_shell_command: "ls -la"]
SecureShell: [On Windows] DENY - Use 'dir' instead
Claude: [Calls execute_shell_command: "dir"]
SecureShell: ALLOW
[Returns directory listing]
Claude: "Here are your files: ..."
The gatekeeper helps Claude learn platform-specific commands.
When exposing shell execution via MCP, use strict security:
const shell = new SecureShell({
template: 'paranoid', // Maximum security
config: {
debugMode: true, // Monitor all commands
allowedPaths: ['/workspace'], // Restrict access
blockedPaths: ['/etc', '/sys']
}
});Try the interactive demo that shows an AI agent calling the MCP server:
cd cookbook/secureshell-ts
npx tsx mcp_client_demo.tsThe agent will:
- Connect to the MCP server
- List available tools
- Call
execute_shell_commandto list files and read package.json - Self-correct if commands are blocked
Enable debug logging:
const shell = new SecureShell({ config: { debugMode: true } });Check Claude Desktop logs:
- macOS:
~/Library/Logs/Claude/ - Windows:
%APPDATA%\Claude\logs\
Test server independently:
npx tsx mcp_server.ts
# Server should start without errorsServer not appearing in Claude:
- Check Claude Desktop logs
- Verify paths are absolute in config
- Test server manually
- Ensure environment variables are set
Commands always denied:
- Use less strict template (
developmentinstead ofparanoid) - Review gatekeeper reasoning in logs
- Ensure OS detection is working
- Start strict - Use
paranoidtemplate initially - Monitor logs - Review what's being executed
- Limit scope - Restrict paths with sandbox
- Test first - Try the demo before production use
- MCP Server:
cookbook/secureshell-ts/mcp_server.ts - AI Agent Demo:
cookbook/secureshell-ts/mcp_client_demo.ts - Claude Config:
mcp_config.json
- Security Templates - Configure security levels
- LangChain Integration - Alternative integration method
- Zero-Trust Gatekeeper - How security works