SSH MCP Server

SSH MCP Server

Enables AI assistants to execute commands an

Category
访问服务器

README

SSH MCP Server

Python 3.8+ License: MIT

An MCP (Model Context Protocol) server that provides SSH client functionality for remote Linux server management. This server enables AI assistants to execute commands on remote Linux hosts via SSH, solving the limitations of built-in tools when working with remote systems.

Why SSH MCP Server?

Built-in MCP tools are limited to local operations. This server extends AI capabilities to remote Linux systems by providing:

  • Remote Command Execution: Execute any command on remote Linux hosts
  • System Administration: Manage services, check system health, monitor processes
  • Secure Authentication: Multiple secure credential storage options
  • Enterprise Integration: Works with domain-joined systems and enterprise environments

Features

  • SSH Command Execution: Execute arbitrary commands on remote Linux hosts
  • Sudo Support: Run commands with elevated privileges (secure password handling)
  • System Information: Get system stats, processes, disk usage, and services
  • Secure Credentials: Secure credential storage (currently macOS Keychain, expanding to other providers)
  • Connection Management: Automatic connection handling with timeouts
  • Error Handling: Comprehensive error reporting and recovery
  • Puppet Integration: Run Puppet agent in no-op mode for configuration management

Installation

From PyPI (when published)

pip install ssh-mcp-server

From Source

git clone https://github.com/rorymcmahon/ssh-mcp-server.git
cd ssh-mcp-server
pip install -e .

Development Installation

git clone https://github.com/rorymcmahon/ssh-mcp-server.git
cd ssh-mcp-server
pip install -e ".[dev]"

Configuration

MCP Client Configuration

Add to your MCP client configuration (e.g., Claude Desktop, Q CLI):

{
  "mcpServers": {
    "ssh": {
      "command": "ssh-mcp-server",
      "args": []
    }
  }
}

Credential Management

The server uses secure credential storage - never plain text environment variables or configuration files.

Current: macOS Keychain (v0.1.0)

Credentials are securely stored in macOS Keychain with TouchID/password protection:

# Store domain credentials (triggers TouchID/password prompt)
security add-generic-password -s "domain-company.local" -a "your_username" -w
# You'll be prompted to enter the password securely

# Credentials are retrieved automatically when needed (triggers TouchID)

Planned: Additional Secure Providers

  • AWS Secrets Manager: Enterprise-grade secret management
  • HashiCorp Vault: Multi-cloud secret management
  • Azure Key Vault: Azure-native secret storage
  • 1Password/Bitwarden: Personal password manager integration
  • SSH Key Authentication: Key-based authentication (no passwords)

Available Tools

Core SSH Operations

execute_ssh(hostname: str, command: str)

Execute a command on a remote Linux host via SSH.

Parameters:

  • hostname: Target hostname (e.g., "server.company.local")
  • command: Command to execute

Returns:

{
  "status": 0,
  "stdout": "total 24\ndrwxr-xr-x 3 user user 4096 ...",
  "stderr": ""
}

Or on error:

{
  "error": "SSH connection or authentication failed"
}

execute_sudo(hostname: str, command: str)

Execute a command with sudo privileges. Automatically handles password input securely.

Returns: Same format as execute_ssh

System Information Tools

ssh_get_system_info(hostname: str)

Get basic system information (OS, kernel, memory, root disk usage).

get_running_processes(hostname: str)

Get top 10 CPU-consuming processes.

get_disk_usage(hostname: str)

Get disk usage for all mounted filesystems.

get_services(hostname: str)

Get top 20 running systemd services.

ssh_puppet_noop(hostname: str)

Run Puppet agent in no-op mode (dry run) with verbose output.

Usage Examples

Basic Command Execution

# Execute a simple command
result = execute_ssh("server.company.local", "uptime")
if "error" not in result:
    print(result["stdout"])  # System uptime information

System Administration

# Check system health
system_info = ssh_get_system_info("server.company.local")
disk_usage = get_disk_usage("server.company.local")
processes = get_running_processes("server.company.local")

# Restart a service with sudo
result = execute_sudo("server.company.local", "systemctl restart nginx")

Error Handling

result = execute_ssh("server.company.local", "invalid_command")
if "error" in result:
    print(f"Error: {result['error']}")
elif result["status"] != 0:
    print(f"Command failed with exit code {result['status']}")
    print(f"Error output: {result['stderr']}")

Security Considerations

  • Credential Storage: Uses secure credential storage (Keychain, future: Vault, AWS Secrets Manager)
  • Network Security: Ensure SSH connections are over secure networks
  • Access Control: Limit SSH user permissions on target hosts
  • Audit Logging: Monitor SSH access and command execution
  • TouchID Protection: macOS Keychain integration requires TouchID/password for access
  • Password Security: Sudo passwords are passed securely via stdin, not visible in process lists

Development

Running Tests

pytest

Code Formatting

black src/ tests/
isort src/ tests/

Type Checking

mypy src/

Coverage Report

pytest --cov=ssh_mcp_server --cov-report=html

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Add tests for new functionality
  5. Ensure all tests pass (pytest)
  6. Format code (black and isort)
  7. Commit changes (git commit -m 'Add amazing feature')
  8. Push to branch (git push origin feature/amazing-feature)
  9. Open a Pull Request

Roadmap

  • [ ] SSH key-based authentication
  • [ ] AWS Secrets Manager credential provider
  • [ ] HashiCorp Vault credential provider
  • [ ] Azure Key Vault credential provider
  • [ ] Connection pooling and reuse
  • [ ] File transfer operations (SCP/SFTP)
  • [ ] Interactive shell sessions
  • [ ] Connection health monitoring
  • [ ] Batch command execution
  • [ ] Custom SSH client configuration
  • [ ] Windows support (additional credential providers)

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

Changelog

v0.1.0 (Initial Release)

  • Basic SSH command execution with secure credential management
  • macOS Keychain credential support
  • System information and administration tools
  • Puppet integration for configuration management
  • Comprehensive test suite and documentation

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选