mcp-for-shell 源码版安装与接入说明

使用文档

这份文档只说明两件事:

  1. 如何安装
  2. 如何接入 OpenCode

1. 安装

把整个源码目录复制到目标机器后,进入项目目录:

1
cd mcp-for-shell-source

安装依赖:

1
npm install

构建项目:

1
npm run build

构建完成后,运行入口是:

1
dist/index.js

如果只是本地调试,也可以直接运行开发模式:

1
npm run dev

2. 接入 OpenCode

OpenCode 建议通过本地 stdio MCP 模式接入。

编辑配置文件:

1
~/.config/opencode/opencode.json

加入如下配置:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
{
"mcp": {
"mcp-for-shell": {
"type": "local",
"command": [
"node",
"/absolute/path/to/mcp-for-shell-source/dist/index.js"
],
"environment": {
"MCP_TRANSPORT": "stdio",
"MCP_SERVER_CONFIG": "/absolute/path/to/mcp-for-shell-source/config/servers.json"
},
"enabled": true
}
}
}

你需要把上面的两个绝对路径替换成你自己机器上的实际路径。

配置说明

  • type: local:表示本地 MCP 服务
  • command:指向构建后的 dist/index.js
  • MCP_TRANSPORT=stdio:让服务以本地 MCP 模式运行
  • MCP_SERVER_CONFIG:指定服务器配置文件位置

配置完成后

重启 OpenCode。

重启成功后,这个 MCP 会提供以下工具:

  • listServers
  • getServer
  • runCommand
  • testConnection
  • getFileTransferStatus
  • uploadFile
  • downloadFile

3. 配置文件示例

首次使用前,可以先准备一个最小配置文件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
{
"environments": [
{
"name": "default",
"servers": [
{
"name": "demo-1",
"host": "192.168.1.10",
"port": 22,
"username": "root",
"authType": "password",
"password": "REPLACE_ME",
"tags": ["prod"]
}
]
}
]
}

也可以不手动写,直接启动 HTTP 模式后用 /admin 页面生成。

4. 如果要用 Web 页面生成配置

执行:

1
node dist/index.js

然后访问:

1
http://127.0.0.1:3000/admin

页面支持:

  • 读取已有本地 servers.json
  • 选择新的本地保存路径
  • 交互式维护服务器列表
  • 保存到本地文件