关于 mcp-server-commands
mcp-server-commands 是一个用于执行任意命令的 MCP 服务。它面向需要在本地或远程运行 shell 命令的 MCP 客户端,支持 stdio、SSE 与 Streamable HTTP 连接方式。README 对安全限制的说明较少。
主要功能
- 01执行任意命令行命令
- 02支持 --cwd 参数指定工作目录
- 03支持 stdio、SSE 与 Streamable HTTP 传输
- 04可通过 npx 直接安装运行
适用场景
- 01让 MCP 客户端在项目目录中运行构建或测试命令
- 02通过远程端点在服务器上执行命令
MCP 相关
该服务以 MCP 服务形式向客户端提供命令执行能力。客户端可通过 stdio 或 /sse、/mcp 远程端点连接。
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
工具
2收录的工具列表 · 更新于 2 周前
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| cwd | string | 否 | 当前工作目录,大多数情况下留空 |
| command | string | 是 | 带参数的命令 |
详细介绍
Commands MCP 服务
一个可执行任意命令的模型上下文协议(MCP)服务。
要求
- Node.js 18 或更高版本
- VS Code、Cursor、Windsurf、Claude Desktop 或任何其他 MCP 客户端
入门
本地(Stdio)
首先,使用你的客户端安装 Commands MCP 服务。典型配置如下:
{
"mcpServers": {
"commands": {
"command": "npx",
"args": [
"-y",
"@agent-infra/mcp-server-commands@latest",
"--cwd",
"/tmp"
]
}
}
}
在 VS Code 中安装
你也可以使用 VS Code CLI 安装 Commands MCP 服务:
# For VS Code
code --add-mcp '{"name":"commands","command":"npx","args":["@agent-infra/mcp-server-commands@latest"]}'
安装后,即可在 VS Code 中将 Commands MCP 服务与 GitHub Copilot Agent 配合使用。
在 Cursor 中安装
前往 Cursor Settings -> MCP -> Add new MCP Server。名称可自行设置,类型选择 command,命令填写 npx @agent-infra/mcp-server-commands。你也可以点击 Edit 验证配置或添加类似参数的命令。
{
"mcpServers": {
"commands": {
"command": "npx",
"args": [
"-y",
"@agent-infra/mcp-server-commands@latest"
]
}
}
}
在 Windsurf 中安装
请参阅 Windsurf MCP 文档。使用以下配置:
{
"mcpServers": {
"commands": {
"command": "npx",
"args": [
"-y",
"@agent-infra/mcp-server-commands@latest"
]
}
}
}
在 Claude Desktop 中安装
请参阅 MCP 安装指南,并使用以下配置:
{
"mcpServers": {
"commands": {
"command": "npx",
"args": [
"-y",
"@agent-infra/mcp-server-commands@latest"
]
}
}
}
远程(SSE / Streamable HTTP)
同时,使用 --port $your_port 参数启动浏览器 MCP,即可将其转换为 SSE 和 Streamable HTTP 服务。
# normal run remote mcp server
npx @agent-infra/mcp-server-commands --port 8089
你可以使用以下两个 MCP 服务远程端点之一:
- Streamable HTTP(推荐):
http://127.0.0.1:8089/mcp - SSE:
http://127.0.0.1:8089/sse
然后,在 MCP 客户端配置中,将 url 设置为 SSE 端点:
{
"mcpServers": {
"commands": {
"url": "http://127.0.0.1:8089/sse"
}
}
}
将 url 设置为 Streamable HTTP:
{
"mcpServers": {
"commands": {
"type": "streamable-http", // If there is MCP Client support
"url": "http://127.0.0.1:8089/mcp"
}
}
}
内存中调用
如果你的 MCP 客户端基于 JavaScript / TypeScript 开发,可以直接使用进程内调用,避免要求用户安装命令行界面才能使用 Commands MCP。
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { InMemoryTransport } from '@modelcontextprotocol/sdk/inMemory.js';
// type: module project usage
import { createServer } from '@agent-infra/mcp-server-commands';
// commonjs project usage
// const { createServer } = await import('@agent-infra/mcp-server-commands')
const client = new Client(
{
name: 'test commands client',
version: '1.0',
},
{
capabilities: {},
},
);
const server = createServer();
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
await Promise.all([
client.connect(clientTransport),
server.connect(serverTransport),
]);
// list tools
const result = await client.listTools();
console.log(result);
// call tool
const toolResult = await client.callTool({
name: 'run_script',
arguments: {
interpreter: 'node',
script: 'console.log(1+1);',
},
});
console.log(toolResult);
开发
npm run dev
评论
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。