cli-mcp-server
CLI MCP 服务器
安全的模型上下文协议 (MCP) 服务器实现,用于执行具有全面安全功能的受控命令行操作。
目录
概述
此 MCP 服务器支持安全的命令行执行,并具备强大的安全措施,包括命令白名单、路径验证和执行控制。非常适合在保证安全性的同时,为 LLM 应用程序提供受控的 CLI 访问。
Related MCP server: Windows CLI MCP Server
特征
🔒 通过严格验证来确保命令执行的安全
⚙️ 可配置命令和标志白名单,带有“全部”选项
🛡️ 路径遍历预防和验证
🚫 Shell 运算符注入保护
⏱️ 执行超时和长度限制
📝 详细的错误报告
🔄 异步操作支持
🎯 工作目录限制和验证
配置
使用环境变量配置服务器:
多变的 | 描述 | 默认 |
| 命令执行的基本目录(必需) | 无(必填) |
| 允许的命令的逗号分隔列表或“全部” |
|
| 允许标志的逗号分隔列表或“全部” |
|
| 最大命令字符串长度 |
|
| 命令执行超时(秒) |
|
| 允许 shell 运算符(&&、 |
注意:将ALLOWED_COMMANDS或ALLOWED_FLAGS设置为“all”将分别允许任何命令或标志。
安装
要通过Smithery自动为 Claude Desktop 安装 CLI MCP 服务器:
npx @smithery/cli install cli-mcp-server --client claude可用工具
运行命令
在允许的目录内执行白名单中的 CLI 命令。
输入模式:
{
"command": {
"type": "string",
"description": "Single command to execute (e.g., 'ls -l' or 'cat file.txt')"
}
}安全说明:
Shell 运算符(&&、|、>、>>)默认不受支持,但可以通过
ALLOW_SHELL_OPERATORS=true启用除非 ALLOWED_COMMANDS='all',否则命令必须列入白名单
除非 ALLOWED_FLAGS='all',否则必须将标志列入白名单
所有路径均经过验证,位于 ALLOWED_DIR 范围内
显示安全规则
显示当前的安全配置和限制,包括:
工作目录
允许的命令
允许的标志
安全限制(最大命令长度和超时)
与 Claude Desktop 一起使用
添加到您的~/Library/Application\ Support/Claude/claude_desktop_config.json :
开发/未发布的服务器配置
{
"mcpServers": {
"cli-mcp-server": {
"command": "uv",
"args": [
"--directory",
"<path/to/the/repo>/cli-mcp-server",
"run",
"cli-mcp-server"
],
"env": {
"ALLOWED_DIR": "</your/desired/dir>",
"ALLOWED_COMMANDS": "ls,cat,pwd,echo",
"ALLOWED_FLAGS": "-l,-a,--help,--version",
"MAX_COMMAND_LENGTH": "1024",
"COMMAND_TIMEOUT": "30",
"ALLOW_SHELL_OPERATORS": "false"
}
}
}
}已发布的服务器配置
{
"mcpServers": {
"cli-mcp-server": {
"command": "uvx",
"args": [
"cli-mcp-server"
],
"env": {
"ALLOWED_DIR": "</your/desired/dir>",
"ALLOWED_COMMANDS": "ls,cat,pwd,echo",
"ALLOWED_FLAGS": "-l,-a,--help,--version",
"MAX_COMMAND_LENGTH": "1024",
"COMMAND_TIMEOUT": "30",
"ALLOW_SHELL_OPERATORS": "false"
}
}
}
}如果它不起作用或不显示在 UI 中,请通过
uv clean清除缓存。
安全功能
✅ 使用“全部”选项执行白名单命令
✅ 使用“全部”选项标记验证
✅ 路径遍历预防和规范化
✅ Shell 操作员阻止(通过
ALLOW_SHELL_OPERATORS=true选择加入支持)✅ 命令长度限制
✅ 执行超时
✅ 工作目录限制
✅ 符号链接解析和验证
错误处理
服务器提供以下详细的错误消息:
安全违规(CommandSecurityError)
命令超时(CommandTimeoutError)
无效的命令格式
路径安全违规
执行失败(CommandExecutionError)
常规命令错误(CommandError)
发展
先决条件
Python 3.10+
MCP 协议库
构建和发布
准备分发包:
同步依赖项并更新锁文件:
uv sync构建软件包分发版:
uv build这将在
dist/目录中创建源和轮子分布。发布到 PyPI:
uv publish --token {{YOUR_PYPI_API_TOKEN}}
调试
由于 MCP 服务器通过 stdio 运行,调试起来可能比较困难。为了获得最佳调试体验,我们强烈建议使用MCP Inspector 。
您可以使用以下命令通过npm启动 MCP Inspector:
npx @modelcontextprotocol/inspector uv --directory {{your source code local directory}}/cli-mcp-server run cli-mcp-server启动后,检查器将显示一个 URL,您可以在浏览器中访问该 URL 以开始调试。
执照
该项目根据 MIT 许可证获得许可 - 有关详细信息,请参阅LICENSE文件。
如需更多信息或支持,请在项目存储库上打开一个问题。
Available Tools
2 toolsrun_commandA
Allows command (CLI) execution in the directory: /app
Available commands: pwd, ls, cat Available flags: -l, --help, -a
Shell operators (&&, ||, |, >, >>, <, <<, ;) are not supported. Set ALLOW_SHELL_OPERATORS=true to enable.
| Name | Required | Description | Default |
|---|---|---|---|
| command | Yes | Single command to execute (example: 'ls -l' or 'cat file.txt') |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations provided, the description carries full burden and does well by disclosing: execution directory constraint (/app), available commands (pwd, ls, cat), available flags (-l, --help, -a), shell operator restrictions, and how to enable operators. It doesn't mention security implications, permission requirements, or output format details.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
Four sentences with zero waste - each provides essential information: purpose, available commands/flags, restrictions, and how to lift restrictions. The structure is front-loaded with the core purpose first, followed by operational details.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
For a single-parameter command execution tool with no annotations and no output schema, the description provides substantial context: execution environment, command/flag constraints, and operator restrictions. It doesn't describe return values or error behavior, but given the tool's relative simplicity, this is reasonably complete.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema description coverage is 100% with the parameter 'command' well-documented in the schema. The description adds context about what constitutes valid commands (specific examples and restrictions), but doesn't provide additional parameter-specific semantics beyond what the schema already covers. Baseline 3 is appropriate when schema does heavy lifting.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description explicitly states 'Allows command (CLI) execution in the directory: /app' - a specific verb ('execute') with clear resource ('command/CLI') and location constraint ('/app'). It distinguishes from the only sibling tool 'show_security_rules' which appears unrelated to command execution.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description provides clear context about what commands and flags are available, and when shell operators are/aren't supported. However, it doesn't explicitly state when to use this tool versus alternatives (though the sibling tool appears unrelated) or provide exclusion guidance beyond the shell operator limitation.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
show_security_rulesB
Show what commands and operations are allowed in this environment.
| Name | Required | Description | Default |
|---|---|---|---|
No parameters | |||
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations are provided, so the description carries the full burden of behavioral disclosure. It implies a read-only operation ('show'), but doesn't specify if it requires authentication, returns structured data, has rate limits, or details output format. For a tool with zero annotation coverage, this is a significant gap in behavioral context.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is a single, efficient sentence that directly states the tool's purpose without any fluff. It's front-loaded and wastes no words, making it easy for an agent to parse quickly.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Given the complexity of security rules and lack of annotations or output schema, the description is incomplete. It doesn't explain what the output looks like (e.g., list, structured data), how to interpret 'allowed,' or any prerequisites. This leaves the agent with insufficient context for effective use.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The tool has 0 parameters with 100% schema description coverage, so the schema fully documents the lack of inputs. The description doesn't add parameter details, which is appropriate here, but it could hint at implicit context like environment scope. Baseline is 4 for zero parameters, as no compensation is needed.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the tool's purpose: 'Show what commands and operations are allowed in this environment.' It specifies the verb 'show' and the resource 'commands and operations' with their context 'in this environment.' However, it doesn't explicitly differentiate from its sibling 'run_command,' which likely executes commands rather than showing allowed ones.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description provides no guidance on when to use this tool versus alternatives. It doesn't mention the sibling tool 'run_command' or any context for usage, such as checking permissions before execution or troubleshooting. This leaves the agent without explicit direction on tool selection.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
2 tool updates
v1.0.0- First observed
run_command - First observed
show_security_rules
TDQS
Scored across 2 tools
The two tools have completely distinct purposes: run_command executes CLI commands with specific constraints, while show_security_rules displays allowed operations and permissions. There is no overlap or ambiguity between these functions.
Both tools follow a clear verb_noun pattern (run_command, show_security_rules), which is consistent and readable. The minor deviation is that 'run' and 'show' are different verbs, but this is appropriate given their distinct actions.
With only 2 tools, the server feels thin for a CLI server that presumably handles command execution and environment management. A typical CLI server would benefit from more tools (e.g., for file operations, process management, or configuration), making this count insufficient for the apparent scope.
The tool surface is severely incomplete for a CLI server. It lacks basic operations like file creation, deletion, editing, process monitoring, or environment configuration. The run_command tool is limited to a few commands, and there are no tools for managing the CLI environment beyond showing security rules, creating significant gaps for agent workflows.
Maintenance
Related MCP Connectors
Scoped agent execution. Server-side credentials, policy, budgets and verifiable receipts.
Security gateway for AI agents: policy, approval, and audited execution, no secrets shared.
Operate Linux, macOS and Windows from your LLM. Every action runs through an auditable allowlist.
Remote MCP for Android CLI agent build gate, structured receipts, audit logs, and reviewer-ready evi
Related MCP Servers
- FlicenseBqualityDmaintenanceEnables safe execution of system shell commands with real-time streaming output and rich metadata capture. Provides configurable command execution with timeout controls, environment management, and extensible plugin architecture for monitoring command lifecycles.4-
- AlicenseAqualityBmaintenanceEnables secure command-line interactions on Windows systems with support for PowerShell, CMD, Git Bash, and WSL shells, providing controlled file access, command execution, and configurable security restrictions.643 npm4MIT
- AlicenseNot gradedqualityCmaintenanceProvides a secure environment for executing shell commands with restricted directory access and timeout enforcement. It includes tools for running commands, managing execution history, and isolating environment variables.24 npmMIT
- FlicenseNot gradedqualityDmaintenanceA security-focused tool that implements least-privilege credential injection for Claude Code by intercepting Bash and MCP tool calls to swap in minimum-privilege tokens. It enables secure execution of CLI commands and MCP operations by matching tool arguments against declarative YAML policies to prevent unauthorized access.-