terminal-mcp-server
Enables secure remote and local command execution via SSH, with session management and environment variable support.
README
Terminal MCP Server
The Terminal MCP Server is a Model Context Protocol (MCP) server designed to facilitate remote and local command execution, with robust SSH capabilities. It allows your AI models or other applications to securely execute commands on remote hosts via SSH or locally, providing a powerful way to interact with various systems.
Highlights
- Secure SSH Command Execution: Execute commands on remote servers securely using SSH, with support for SSH alias config file parsing. Automatically parses your
~/.ssh/configfile to retrieve connection details like HostName, User, IdentityFile, Passphrase, and Port, simplifying SSH management. - Local Command Execution: Run commands directly on the local machine where the MCP server is running.
- Session Management with Timeout: Maintains persistent SSH sessions with configurable timeouts for efficient command execution and resource management.
- Environment Variable Support: Pass environment variables to both remote and local commands.
- Default Directory for Local Commands: Configure a
DEFAULT_DIRenvironment variable to specify the starting directory for local command execution.
Features
- Remote Command Execution: Connects to remote hosts via SSH and executes specified commands.
- Local Command Execution: Executes commands on the local machine.
- SSH Configuration Parsing: Reads and interprets
~/.ssh/configfor streamlined connection setup. - Connection Pooling: Reuses existing SSH connections to minimize overhead.
- Error Handling and Retries: Implements retry mechanisms for connection attempts and robust error reporting.
Usage
Installation
- Clone the repository:
git clone https://github.com/ptbsare/terminal-mcp-server.git cd terminal-mcp-server - Install dependencies:
npm install - Build the project:
npm run build
Running the Server
To start the MCP server:
npm start
The server will listen for incoming MCP requests.
SSH Configuration
Ensure your SSH configuration (~/.ssh/config) is set up correctly for the hosts you wish to connect to. The server will automatically parse this file.
Example ~/.ssh/config:
Host my_remote_server
HostName your_remote_server_ip_or_hostname
User your_username
IdentityFile ~/.ssh/id_rsa
Port 22
# Passphrase your_passphrase (uncomment and set if your key is encrypted)
Using with Claude (or other AI models)
To integrate this MCP server with Claude, you need to configure Claude to connect to a local MCP server.
-
Start the Terminal MCP Server as described above.
-
Configure Claude: In your Claude environment, you will typically add a tool definition that points to this MCP server. The exact configuration steps depend on the Claude interface or API you are using.
To configure the MCP server for Claude, you would typically create a JSON file (e.g.,
mcp_server.json) with the following structure:{ "mcpServers": { "terminal-mcp-server": { "command": "npm", "args": [ "--prefix", "/path/to/terminal-mcp-server", "run", "start" ] } } }This server provides a single tool:
execute_command.Tool:
execute_command- Description: Executes a shell command on a remote host via SSH or locally.
- Parameters:
command(string, required): The shell command to execute.host(string, optional): The SSH host alias from your~/.ssh/configto execute the command on. If not provided, the command will be executed locally.env(object, optional): Environment variables to set for the command execution. Keys and values should be strings.
Save this JSON content as
mcp_server.json(or any other name) and provide it to Claude's MCP configuration. The exact method for providing this configuration depends on your Claude environment (e.g., via a specific UI, API call, or configuration file).
Local Command Default Directory
You can set an environment variable DEFAULT_DIR before starting the terminal-mcp-server to specify the default working directory for local commands.
Example:
DEFAULT_DIR="/workdir" npm start
This will make all local commands executed via the MCP server start in /workdir unless explicitly overridden.
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.