使用说明
MCP-CLI
一个模型上下文协议(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"
]
}
然后在代理模式下,单击“工具”按钮,然后单击“添加更多工具…”、“添加MCP服务器…”,再单击“命令(stdio)…”。然后键入 mcp-cli ${workspaceFolder}/mcp-cli.json,然后将随机生成的名称替换为 mcp-cli,然后选择“工作区设置”。你现在可以提及 mcp-cli 作为指示代理使用该工具的提示的一部分。
你现在应该有一个 .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
]
}
