mcpField
M
MCP CLI

MCP CLI

本地服务
github.com/gelisam开发工具740 周前更新

关于 MCP CLI

MCP CLI 是一个 MCP 服务,将配置中列出的 Shell 命令作为工具提供给 AI 助手。它适合希望明确限定可执行命令,并减少逐条授权操作的 VS Code 用户。

主要功能

  1. 01按配置公开 Shell 命令
  2. 02维护允许执行的命令列表
  3. 03设置工具名称与说明
  4. 04配置工作目录和环境变量

适用场景

  1. 01让 Agent 执行构建命令
  2. 02运行项目测试
  3. 03调用特定数据库连接命令

MCP 相关

它将配置的 Shell 命令作为工具暴露给 MCP 客户端;每个命令可先列入允许列表,再授权工具使用。

配置

本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。

暂未收录安装方式

我们还没有获取到这个服务的安装包或远程地址,请按项目 README 中的说明安装。

代码仓库

工具

还没有获取到工具列表

本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。

详细介绍

MCP CLI

一个 Model Context Protocol(MCP)服务,可将 shell 命令作为工具提供给 GitHub Copilot 等 AI 助手。

截图

为什么?

GitHub Copilot 已经能够运行任意 shell 命令,但使用 mcp-cli,你可以明确说明它需要运行哪些 shell 命令,例如构建代码、运行测试,或连接到数据库所需的特定命令。

此外,出于安全考虑,GitHub Copilot 会在运行每条 shell 命令前征求你的许可。使用 mcp-cli,你可以维护一个允许执行的 shell 命令列表,这样每个工具只需授权一次。

安装

git clone <repository-url>
cd mcp-cli
cabal install

首先,创建一个包含允许执行命令的 JSON 配置文件。例如,创建 mcp-cli.json:

{
  "commands": [
    "ls -l",
    "date",
    "pwd"
  ]
}

然后,在 Agent 模式下,点击 Tools 按钮,再依次点击 "Add More Tools..."、"Add MCP Server..." 和 "Command (stdio)..."。接着输入 mcp-cli ${workspaceFolder}/mcp-cli.json,将随机生成的名称替换为 mcp-cli,然后选择 "Workspace Settings"。现在,你可以在提示词中提及 mcp-cli,指示 Agent 使用该工具。

此时,你应该会有一个 .vscode/mcp.json 文件,内容如下:

{
  "servers": {
    "mcp-cli": {
      "type": "stdio",
      "command": "mcp-cli",
      "args": [
        "${workspaceFolder}/mcp-cli.json"
      ]
    }
  }
}

用法

现在,你可以修改 JSON 配置文件中的允许执行命令列表。

以下是一个示例会话。

HUMAN
Please use the `mcp-cli` tool to repeatedly call `date` for 10 seconds, and
report the time at which the experiment started and ended. After each call,
carefully consider whether the 10 seconds has elapsed before deciding whether
to call `date` again.

AGENT
I'll help you use the mcp-cli tool to repeatedly call date for 10 seconds. Let
me start by making the first call to record the start time, then continue
calling until 10 seconds have elapsed.

VS CODE
> Run execute_command_2
[Continue] [Cancel]

HUMAN
(clicks the arrow next to "Continue", then "Allow in this session")

AGENT
> Ran execute_command_2

The experiment started at Fri May 30 08:51:55 AM EDT 2025. Now I'll continue
calling the date command repeatedly until 10 seconds have elapsed.

> Ran execute_command_2

The second call shows Fri May 30 08:51:58 AM EDT 2025 - that's 3 seconds after
the start. I need to continue calling date until 10 seconds have elapsed from
the start time (08:51:55). Let me continue:

> Ran execute_command_2

The third call shows Fri May 30 08:52:01 AM EDT 2025 - that's 6 seconds after
the start. I need to continue until 10 seconds have elapsed (until 08:52:05).
Let me continue:

> Ran execute_command_2

The fourth call shows Fri May 30 08:52:04 AM EDT 2025 - that's 9 seconds after
the start. I need one more call to reach or exceed the 10-second mark:

> Ran execute_command_2

Perfect! The experiment is now complete. Here are the results:

Experiment Summary:

Start time: Fri May 30 08:51:55 AM EDT 2025
End time: Fri May 30 08:52:07 AM EDT 2025
Total duration: 12 seconds
I made 5 calls to the date command through the mcp-cli tool:

08:51:55 (start)
08:51:58 (3 seconds elapsed)
08:52:01 (6 seconds elapsed)
08:52:04 (9 seconds elapsed)
08:52:07 (12 seconds elapsed - experiment complete)

The experiment ran for 12 seconds total, which exceeded the target of 10
seconds. After the 4th call at 08:52:04 (9 seconds elapsed), I made one final
call to ensure we had crossed the 10-second threshold, which occurred at
08:52:07, confirming that 10+ seconds had elapsed from the start time.
高级配置

使用这种扩展格式,你还可以指定

  • AI 助手看到的名称。默认为 execute_command_1。
  • 向 AI 助手说明工具用途的描述。默认为 Execute the shell command: pwd。
  • 命令运行时所在的工作目录,相对于 mcp-cli.json 文件的位置。若存在工具专属路径,则该路径相对于顶层路径。默认为 VS Code 启动时所在的文件夹。
  • AI 助手必须提供的参数,这些参数会成为命令中的环境变量。
  • 要设置的环境变量。工具专属环境变量会覆盖顶层环境变量。
{
  "commands": [
    "ls -l",
    {
      "name": "list-source-files",
      "workingDirectory": "src",
      "command": "ls -l"
    },
    {
      "name": "list-files-in",
      "command": "ls -l \"$FOLDER\"",
      "arguments": [
        "FOLDER"
      ]
    },
    "git status",
    {
      "name": "recent_changes",
      "description": "summarize the last few commits",
      "command": "git log --oneline | head -n \"$N\"",
      "arguments": [
        {
          "name": "N",
          "description": "the number of commits to list"
        }
      ],
      "envVars": [
        "GIT_EDITOR": "code"
      ]
    }
  ],
  "envVars": [
    "NO_COLOR": "true",
    "PAGER": null
  ]
}

评论

支持 Markdown

第一次接触 MCP?

从协议是什么,到在客户端里装上第一个服务,这几条回答覆盖了大多数入门问题。

一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。