ssh-admin

ssh-admin

MCP server for managing SSH connections to remote servers, providing host registry, session pool, and secure command execution with read-only protection.

Category
访问服务器

README

ssh-admin

MCP (Model Context Protocol) server for managing SSH connections to remote servers. Provides host registry, session pool, and secure command execution with read-only protection.

Features

  • Server Registry: Add, list, update, delete SSH server configurations with mtime-based caching
  • Connection Pool: Automatic session deduplication (max 1 per host), graceful reconnect
  • Command Execution: Run shell commands on active SSH sessions with whitelist + write pattern detection
  • Raw Command Execute: Unfiltered command execution with changelog logging and user approval
  • Readonly Mode: Optional strict read-only mode that blocks all write operations and registry mutations
  • Secure Credentials: Passwords stored in environment variables, never in the registry
  • Graceful Shutdown: SIGTERM/SIGINT handling with clean session teardown

Installation

npm install
npm run build

Configuration

Adding Servers

Use the registry_add_server tool to add servers:

{
  "name": "registry_add_server",
  "arguments": {
    "alias": "prod-web",
    "host": "192.168.1.100",
    "port": 22,
    "username": "deploy",
    "authMethod": "key",
    "keyPath": "~/.ssh/id_ed25519"
  }
}

For password auth:

{
  "name": "registry_add_server",
  "arguments": {
    "alias": "staging-db",
    "host": "10.0.0.50",
    "port": 2222,
    "username": "admin",
    "authMethod": "password"
  }
}

Then set the password via environment variable:

export SSH_PASSWORD_STAGING_DB="your_password_here"

Running the Server

# Development mode
npm run dev

# Production mode
npm run build && npm start

# Readonly mode (blocks registry writes + all command modifications)
MCP_SSH_READONLY=true npm run dev

MCP Tools

Registry Tools

Tool Description
registry_add_server Add a new SSH server to the registry
registry_list_servers List all registered servers (credentials hidden)
registry_get_server Get details of a specific server
registry_update_server Update server properties (cannot change host/port)
registry_delete_server Remove a server from the registry

Connection Tools

Tool Description
connection_open Open an SSH connection, returns sessionId
connection_close Close an open SSH session
connection_list List all active sessions

Command Tools

Tool Description
command_execute Execute command on an open session (whitelist + write pattern protected)
command_execute_raw Execute commands without filtering (changelog logging + user approval required)
instruction Returns system prompt / agent instructions (call first)

Usage Flow

1. instruction                              → get agent instructions
2. registry_list_servers                    → see available hosts
3. connection_open(alias="prod")            → get sessionId
4. command_execute(sessionId, "uptime")     → run first command
5. command_execute(sessionId, "df -h")      → run second command on same session
6. command_execute_raw(sessionId, "systemctl restart nginx") → modify system
7. connection_close(sessionId)              → close session

~/server-info/ Structure

Each server has persistent information stored in its ~/server-info/ directory. These files are updated and read by the AI.

Files

  • services.md — Installed services and their status
  • packages.md — Installed critical packages
  • rules.md — Server constraints and rules
  • decisions.md — Decisions made and their rationale
  • architecture.md — Architecture notes and configuration details
  • changelog.log — Commands executed via command_execute_raw (auto-append)

Directories

  • knowledge/ — Knowledge files (.md) created and maintained by the AI
    • Each .md file represents a topic or knowledge domain
    • AI adds or updates files as it learns new server information
  • scripts/ — Reusable scripts for frequently performed operations
    • Store automation scripts here to speed up common tasks
    • AI creates and maintains scripts based on recurring operational patterns

Usage Rules

  • Read operations: Use command_execute (protected by whitelist + write pattern detection)
  • Permanent changes: Use command_execute_raw (unfiltered + user approval required)
    • Read-only commands are blocked in command_execute_raw → use command_execute instead
  • Files are updated by AI when system changes occur
  • AI reads these files to get server information when needed

Security

Command Protection

Every command goes through a three-layer defense:

  1. Whitelist — Unknown commands are blocked (e.g., python, node, perl, ruby, mount, screen, tmux, dd, zip, gzip)
  2. Write Argument Detection — Even whitelisted commands are checked for write flags (e.g., tar cf, systemctl restart, docker run, git add)
  3. Redirection Detection — File write operators (>, >>) are blocked

No bypass is possible. No permanent modifications can be made through command_execute.

Readonly Mode

When MCP_SSH_READONLY=true:

  • Registry write tools (registry_add_server, registry_update_server, registry_delete_server) are disabled
  • All commands pass through whitelist + write pattern checks
  • No permanent changes can be made to any server

Credentials & Storage

  • Passwords are never stored in the registry
  • Use environment variables: SSH_PASSWORD_<ALIAS> (uppercase alias)
  • Key-based auth is recommended for production use
  • Registry directory: ~/.ssh-admin/ with mode 0700
  • Registry file: hosts.json with mode 0600
  • Password memory is wiped immediately after credential verification

Configuration

Setting Default Description
Connection timeout 5000ms SSH connection establishment timeout
Command timeout 60000ms Command execution timeout
Keepalive interval max(10s, timeout/3) SSH keepalive interval
Keepalive count 10 Number of failed keepalives before disconnect
Verification timeout max(30s, timeout) Connection verification timeout
forceIPv4 false Force IPv4 connections (set per host in registry)

Development

npm install          # Install dependencies
npm run dev          # Watch mode via tsx
npm test             # Run tests (477 tests)
npm run build        # TypeScript compile + bundle

License

MIT

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选