local-mcp-manager 0.0.0-stage → 0.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +49 -0
- package/LICENSE +21 -0
- package/README.md +120 -2
- package/THIRD_PARTY_NOTICES.md +18 -0
- package/cordis.patch.yml +6 -0
- package/lib/controller.js +211 -0
- package/lib/credentials.js +22 -0
- package/lib/index.js +63 -0
- package/lib/runtime.js +648 -0
- package/lib/store.js +113 -0
- package/lib/ui.js +183 -0
- package/package.json +46 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# 更新记录
|
|
2
|
+
|
|
3
|
+
## 0.5.4 — npm 与市场分发
|
|
4
|
+
|
|
5
|
+
- 为插件市场准备可公开发布的 npm 包,保留 `local-mcp-manager` 包名和既有配置路径。
|
|
6
|
+
- 标明公共 npm 注册表及精确版本,保留 MIT 许可证和原生适配清单。
|
|
7
|
+
- 面板位置对齐市场的原生清单快照:保留全部功能、对话插件和聊天面板入口,移除市场快照尚未接受的 `plugin` 位置值。
|
|
8
|
+
- 运行代码与 0.5.3 一致;市场条目仍声明仅适配 dsh-go,不保证其他平台可用。
|
|
9
|
+
|
|
10
|
+
## 0.5.3 — 2026-11-19
|
|
11
|
+
|
|
12
|
+
首次 GitHub 公开发布。定位为 dsh-go 原生 MCP 管理适配插件,不保证其他平台可用。
|
|
13
|
+
|
|
14
|
+
### 修复
|
|
15
|
+
|
|
16
|
+
- 原生界面不再重复发送组合节点。较大参数页超过 16 KiB patch 预算时改走原生数据刷新,避免动作被桥接层丢弃。
|
|
17
|
+
- 未提交的搜索草稿在翻页、重开工具和重新订阅时保留,表单绑定与草稿一致。
|
|
18
|
+
- 只读设置页后台更新后使用最新配置修订;编辑页和删除确认页保留原修订以阻止过期保存。
|
|
19
|
+
- 删除服务器和凭据项的确认操作携带并校验明确目标与修订,过期确认不会误删另一目标。
|
|
20
|
+
- 凭据引用名校验与宿主 POSIX 标识符规则一致。
|
|
21
|
+
|
|
22
|
+
### 发布准备
|
|
23
|
+
|
|
24
|
+
- 声明直接使用的 `@deepseek-ai/dsh-subprocess` 宿主依赖,移除固定 `/opt/dsh` 缺包回退。
|
|
25
|
+
- 测试工具包按 `DSH_HOME` / `DSH_GO_PLUGIN_KIT` 定位,分离核心与原生测试。
|
|
26
|
+
- 使用 MCP client 2.3.0,锁定兼容的 Zod 4.6.6 与 Undici 8.12.2 修复版本;最小 Node 版本注明为 22.19.0。
|
|
27
|
+
- 增加许可证、兼容边界、安装/更新说明和依赖锁文件。
|
|
28
|
+
- 干净安装的 70 项回归测试通过;发布前 npm audit 报告 0 项已知漏洞。原生检查按 App 1.1.0 校验。
|
|
29
|
+
|
|
30
|
+
## 0.5.2 — 2026-11-19
|
|
31
|
+
|
|
32
|
+
- 自动连接等待工具和凭据服务就绪,避免启动过早导致凭据缺失而不再自动重试。
|
|
33
|
+
- 每个注入实例独立持有并释放自己的运行时。
|
|
34
|
+
- 64 项回归测试通过;用户确认重启后 Exa 和 GitHub 自动连接。
|
|
35
|
+
|
|
36
|
+
## 0.5.1
|
|
37
|
+
|
|
38
|
+
- 连接方式切换保留未保存的连接草稿。
|
|
39
|
+
- 工具筛选保留未提交搜索词。
|
|
40
|
+
- 修复服务器移除后的返回导航。
|
|
41
|
+
- 并发工具调用独立区分 401、403、429、超时和普通失败,不回显服务端错误正文、不重放工具。
|
|
42
|
+
|
|
43
|
+
## 0.5.0
|
|
44
|
+
|
|
45
|
+
- 紧凑服务器列表、工具优先导航、分页搜索和摘要设置入口。
|
|
46
|
+
- 分步添加 HTTP、SSE、stdio 服务,最终保存前不写配置或启动程序。
|
|
47
|
+
- 移除空布局导致的通用“无数据”占位。
|
|
48
|
+
|
|
49
|
+
早期版本为本机开发迭代,未作为本仓库公开版本发布。
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Aouky7
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,121 @@
|
|
|
1
|
-
#
|
|
1
|
+
# dsh-go MCP 管理器
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
面向 **dsh-go 原生界面**的 MCP 管理适配插件。添加自己的 MCP 服务,在手机里管理连接、工具和调用策略。
|
|
4
|
+
|
|
5
|
+
**支持范围仅限 dsh-go;不保证其他客户端、桌面端、网页版或操作系统可用。** 本项目是社区插件,不是 dsh-go 官方组件,也不是独立运行的通用 MCP 客户端。
|
|
6
|
+
|
|
7
|
+
当前版本:**0.5.4** · MIT License
|
|
8
|
+
|
|
9
|
+
## 功能
|
|
10
|
+
|
|
11
|
+
- 连接 Streamable HTTP、旧版 SSE,以及当前主机上的本地 stdio 服务。
|
|
12
|
+
- 添加、编辑、启停、移除服务器;等待工具与凭据服务就绪后自动连接。
|
|
13
|
+
- 自动发现工具,按名称或描述搜索、筛选、分页;支持逐工具启用和审批策略。
|
|
14
|
+
- 原生表单配置请求头或环境变量;新填写的值保存在 DSH 凭据库,服务器配置只保存引用。
|
|
15
|
+
- 测试连接并刷新工具目录;健康连接不因测试而中断在途调用。
|
|
16
|
+
- 活动页查看最近 20 次调用的耗时、结果类别,不记录参数、返回正文或凭据;重启后清空。
|
|
17
|
+
- 查看资源和提示词目录。
|
|
18
|
+
|
|
19
|
+
不内置服务商专用接口。普通 REST API 地址需要先由服务方提供 MCP 接口,才能添加。
|
|
20
|
+
|
|
21
|
+
## 兼容环境
|
|
22
|
+
|
|
23
|
+
已验证环境为 dsh-go **1.1.0**、DSH **0.2.2-rc.1**、Node.js **24.22.1**,Android 本机引擎。
|
|
24
|
+
|
|
25
|
+
- 原生清单最低 App 版本为 1.1.0。
|
|
26
|
+
- 包要求 Node.js >=22.19.0;宿主依赖按当前已验证的 DSH 版本固定。
|
|
27
|
+
- 需要宿主提供 `dshGo`、`tools` 和 `credentials` 服务。
|
|
28
|
+
- 不承诺未来 DSH/App 版本自动兼容。报告问题时请提供实际版本。
|
|
29
|
+
|
|
30
|
+
## 插件市场
|
|
31
|
+
|
|
32
|
+
市场提交使用 npm 精确版本 `local-mcp-manager@0.5.4`。条目通过市场检查并合并后,可在 dsh-go 插件市场搜索「MCP 管理器」安装。首次上架状态以市场仓库 PR 与实际目录为准;这不是官方插件,也不保证其他平台可用。
|
|
33
|
+
|
|
34
|
+
## 安装
|
|
35
|
+
|
|
36
|
+
在 **dsh-go 当前连接的主机终端**执行。以下命令安装到默认原生插件目录;已存在同名目录时请先检查自己的安装,不要覆盖用户配置。
|
|
37
|
+
|
|
38
|
+
```sh
|
|
39
|
+
DSH_DIR="${DSH_HOME:-$HOME/.dsh}"
|
|
40
|
+
PLUGIN_DIR="$DSH_DIR/dsh-go/plugins/local-mcp-manager"
|
|
41
|
+
|
|
42
|
+
git clone --branch v0.5.4 --depth 1 \
|
|
43
|
+
https://github.com/Aouky7/dsh-go-mcp-manager.git "$PLUGIN_DIR"
|
|
44
|
+
cd "$PLUGIN_DIR"
|
|
45
|
+
npm ci --ignore-scripts
|
|
46
|
+
dsh plugin --profile web add "$PLUGIN_DIR"
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
入口:**输入框加号 → MCP**,或 **全部功能 / 对话详情的插件页 → MCP 管理器**。
|
|
50
|
+
|
|
51
|
+
这是指向安装目录的链接;使用期间不要删除或移动该目录。
|
|
52
|
+
|
|
53
|
+
### 更新已有安装
|
|
54
|
+
|
|
55
|
+
通过 Git 安装的用户可拉取指定版本,再在 App 的「引擎」页重启引擎:
|
|
56
|
+
|
|
57
|
+
```sh
|
|
58
|
+
DSH_DIR="${DSH_HOME:-$HOME/.dsh}"
|
|
59
|
+
cd "$DSH_DIR/dsh-go/plugins/local-mcp-manager"
|
|
60
|
+
git fetch --tags origin
|
|
61
|
+
git checkout v0.5.4
|
|
62
|
+
npm ci --ignore-scripts
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
非 Git 安装请先备份原插件目录,再按发布内容更新代码。**无需删除服务器配置或重新填写密钥。**
|
|
66
|
+
|
|
67
|
+
## 使用
|
|
68
|
+
|
|
69
|
+
1. 添加服务器,选择 HTTP、SSE 或本地 stdio。
|
|
70
|
+
2. 填写名称与 MCP 地址,或本地程序、参数及工作目录。参数每行一个,不额外加引号。
|
|
71
|
+
3. 到服务器的「设置 → 请求头 / 环境变量」配置鉴权或环境值。
|
|
72
|
+
4. 工具页的「测试连接」仅握手、读取目录,不执行工具。
|
|
73
|
+
5. 工具详情可以分别调整启用和审批;关闭插件额外审批仍遵守宿主权限策略。
|
|
74
|
+
|
|
75
|
+
请求头:`x-api-key` 通常填 Key 本身;`Authorization` 按提供方要求填写完整值。编辑时留空保留原值,输入新值才替换。**App 1.1.0 输入阶段文字可见,保存后不回显。**
|
|
76
|
+
|
|
77
|
+
0.5.2 的启动连接修复已由用户重启手机 App 后确认:已启用的 Exa 和 GitHub 服务自动恢复连接。0.5.3 延续该修复。
|
|
78
|
+
|
|
79
|
+
## 数据与行为边界
|
|
80
|
+
|
|
81
|
+
- 服务器文件:`$DSH_HOME/dsh-go/plugin-data/local-mcp-manager/servers.json`。
|
|
82
|
+
- 新保存的请求头/环境变量值交给宿主凭据库管理;本项目不宣称对凭据库做了独立加密。
|
|
83
|
+
- 本地 stdio 会在当前主机执行指定程序,请只添加可信程序。插件不是程序沙箱。
|
|
84
|
+
- 显式「重新连接」会中止旧连接上的在途调用;失败的工具调用不会自动重放。
|
|
85
|
+
- 不提供 OAuth 登录流程。资源与提示词目前只展示目录,不提供内容读取或执行入口。
|
|
86
|
+
- 最多 32 个服务器;每服务请求头与环境变量各最多 16 项;原生单次提交预算为 4 KiB。
|
|
87
|
+
- 工具参数定义最多预览 7000 个字符;较大页面通过原生数据刷新加载。
|
|
88
|
+
- 超大表单、服务端协议差异、网络和服务方限流仍可能导致失败;本项目不保证任意 MCP 服务兼容。
|
|
89
|
+
|
|
90
|
+
遇到凭据不可用时,先确认宿主凭据服务正常,再尝试该服务的「重新连接」。401/403 需要检查鉴权和权限,429 需要检查额度或稍后重试。
|
|
91
|
+
|
|
92
|
+
## 验证与开发
|
|
93
|
+
|
|
94
|
+
```sh
|
|
95
|
+
npm ci --ignore-scripts
|
|
96
|
+
npm run test:core
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
完整原生测试还需要 dsh-go 自带的 `dsh-go-plugin` 开发工具包。默认从 `${DSH_HOME:-$HOME/.dsh}/skills/dsh-go-plugin/kit` 查找,可用 `DSH_GO_PLUGIN_KIT` 指向其他 kit 目录。
|
|
100
|
+
|
|
101
|
+
```sh
|
|
102
|
+
npm test
|
|
103
|
+
|
|
104
|
+
DSH_DIR="${DSH_HOME:-$HOME/.dsh}"
|
|
105
|
+
node "$DSH_DIR/skills/dsh-go-plugin/kit/bin/check.mjs" \
|
|
106
|
+
. --load --app 1.1.0
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
0.5.3 发布前在隔离的干净安装中通过 **70 项测试**,覆盖真实本地 HTTP MCP 握手/调用、凭据、工具权限、启动时序、分页搜索、原生桥接效果预算、设置版本和删除目标校验。完整自动检查不能替代所有 Android 设备的点击、键盘、滚动与视觉验收。
|
|
110
|
+
|
|
111
|
+
依赖锁定在 `package-lock.json`。升级兼容的 MCP SDK、Zod 和 Undici 修复版本后,发布前 `npm audit` 报告为 0 项已知漏洞;这不代表不存在未知漏洞,也不代表已审计整个宿主引擎。
|
|
112
|
+
|
|
113
|
+
## 反馈
|
|
114
|
+
|
|
115
|
+
请通过 [Issues](https://github.com/Aouky7/dsh-go-mcp-manager/issues) 提供 App/DSH/Node 版本、连接方式、复现步骤和脱敏错误提示。不要上传 Key、Token、完整凭据库或包含私人参数的配置。
|
|
116
|
+
|
|
117
|
+
功能与修复记录见 [CHANGELOG.md](CHANGELOG.md)。第三方依赖说明见 [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md)。
|
|
118
|
+
|
|
119
|
+
## License
|
|
120
|
+
|
|
121
|
+
[MIT](LICENSE),Copyright (c) 2026 Aouky7。依赖遵守各自许可证。
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Third-party dependencies
|
|
2
|
+
|
|
3
|
+
This repository distributes the plugin source. It does not vendor the dsh-go app, the DSH engine, or dependency source trees. Package installation obtains dependencies separately; their license and copyright notices remain authoritative.
|
|
4
|
+
|
|
5
|
+
Direct runtime dependencies and host peers:
|
|
6
|
+
|
|
7
|
+
- `@modelcontextprotocol/client` — 2.3.0 — MIT — official MCP TypeScript client SDK.
|
|
8
|
+
- `@deepseek-ai/cordis` — 4.1.x — MIT — host plugin lifecycle.
|
|
9
|
+
- `@deepseek-ai/schemastery` — 3.19.x — MIT — host configuration schema.
|
|
10
|
+
- `@deepseek-ai/dsh-mcp-client` — 0.2.2-rc.1 — MIT — MCP tool-definition integration.
|
|
11
|
+
- `@deepseek-ai/dsh-credentials` — 0.2.2-rc.1 — MIT — host credential references and storage integration.
|
|
12
|
+
- `@deepseek-ai/dsh-subprocess` — 0.2.2-rc.1 — MIT — host subprocess environment filtering.
|
|
13
|
+
|
|
14
|
+
All transitive package versions are listed in `package-lock.json`. This project uses standard MCP and DSH APIs; it does not claim authorship of the protocol, SDKs, host, or the general concept of an MCP manager.
|
|
15
|
+
|
|
16
|
+
Native validation tests require the separately provided dsh-go-plugin development kit. The kit is not bundled in this repository. No substitute validator is used when the kit is absent; `test:native` reports the missing requirement, while `test:core` can run independently.
|
|
17
|
+
|
|
18
|
+
`package.json` overrides select compatible fixes for Zod and Undici, and align the nested MCP client SDK version. These apply to this package's dependency installation, not an audit or modification of every dependency in a running DSH host.
|
package/cordis.patch.yml
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import {randomUUID} from 'node:crypto'
|
|
2
|
+
import {normalizeServer,formPayload,record,bool,integer,pairs} from './store.js'
|
|
3
|
+
import {render,connectionView,composeView,draftServer,buildView} from './ui.js'
|
|
4
|
+
import {referenced} from './credentials.js'
|
|
5
|
+
|
|
6
|
+
export function createController(store,runtime,options={}){
|
|
7
|
+
const screens=new Map(),listeners=new Map(),projections=new Map(),toolPositions=new Map(),listPositions=new Map(),vault=options.vault
|
|
8
|
+
let notifyTimer=null,disposed=false
|
|
9
|
+
const key=scope=>scope.sessionId??'settings'
|
|
10
|
+
const screenOf=scope=>screens.get(key(scope))??{page:'list'}
|
|
11
|
+
const toolKey=(scope,id)=>`${key(scope)}:${id}`
|
|
12
|
+
const find=id=>{const s=store.snapshot().servers.find(x=>x.id===id);if(!s)throw Error('服务器不存在,请返回列表');return s}
|
|
13
|
+
const projectOptions=screen=>{
|
|
14
|
+
if(!screen.serverId)return {detail:'summary'}
|
|
15
|
+
if(['tool','schema'].includes(screen.page))return {serverId:screen.serverId,detail:'tool',toolName:screen.toolName}
|
|
16
|
+
if(screen.page==='catalog')return {serverId:screen.serverId,detail:'catalog'}
|
|
17
|
+
if(screen.page==='records')return {serverId:screen.serverId,detail:'overview'}
|
|
18
|
+
if(['server','overview'].includes(screen.page))return {serverId:screen.serverId,detail:'tools'}
|
|
19
|
+
return {serverId:screen.serverId,detail:'summary'}
|
|
20
|
+
}
|
|
21
|
+
const runtimeView=screen=>runtime.project?runtime.project(projectOptions(screen)):runtime.snapshot()
|
|
22
|
+
const data=scope=>{const view=render(store.snapshot(),runtimeView(screenOf(scope)),screenOf(scope));projections.set(key(scope),view);return view}
|
|
23
|
+
const args=event=>{const raw=event?.value??{},v=record(raw)?raw:{value:raw};return {...(record(v.args)?v.args:{}),...v}}
|
|
24
|
+
const revision=(v,scope)=>{const n=v.revision??screenOf(scope).revision;if(!Number.isSafeInteger(n)||n!==store.snapshot().revision)throw Error('配置已更新,请重新打开后重试');return n}
|
|
25
|
+
// Keep composition helpers local; the native client only binds these fields.
|
|
26
|
+
const wire=view=>({content:view.content,navigation:view.navigation,form:view.form?{...view.form,pairValue:''}:null,filters:view.filters??null})
|
|
27
|
+
const updateView=view=>{const patch=wire(view);return Buffer.byteLength(JSON.stringify(patch))<=16384?{patch}:{refresh:true}}
|
|
28
|
+
const navigate=(scope,next)=>{
|
|
29
|
+
const prior=screenOf(scope)
|
|
30
|
+
if(prior.page==='server')toolPositions.set(toolKey(scope,prior.serverId),{query:prior.query??'',draftQuery:prior.draftQuery??prior.query??'',filter:prior.filter??'all',pageIndex:prior.pageIndex??0})
|
|
31
|
+
if(prior.page==='list')listPositions.set(key(scope),prior.pageIndex??0)
|
|
32
|
+
screens.set(key(scope),next)
|
|
33
|
+
const view=data(scope)
|
|
34
|
+
return updateView(view)
|
|
35
|
+
}
|
|
36
|
+
const openTools=(scope,id)=>navigate(scope,{page:'server',serverId:find(id).id,...(toolPositions.get(toolKey(scope,id))??{}),revision:store.snapshot().revision})
|
|
37
|
+
const settings=(scope,id)=>navigate(scope,{page:'settings',serverId:find(id).id,revision:store.snapshot().revision})
|
|
38
|
+
const credentials=(scope,id)=>navigate(scope,{page:'credentials',serverId:find(id).id,revision:store.snapshot().revision})
|
|
39
|
+
const basic=(scope,id)=>navigate(scope,{page:'edit',serverId:find(id).id,revision:store.snapshot().revision})
|
|
40
|
+
const notify=()=>{if(disposed||notifyTimer||!listeners.size)return;notifyTimer=setTimeout(flush,48);notifyTimer.unref?.()}
|
|
41
|
+
const flush=()=>{
|
|
42
|
+
if(notifyTimer)clearTimeout(notifyTimer);notifyTimer=null
|
|
43
|
+
if(disposed)return
|
|
44
|
+
const state=store.snapshot()
|
|
45
|
+
for(const [k,subscribers]of listeners){
|
|
46
|
+
const screen=screens.get(k)??{page:'list'},previous=projections.get(k)
|
|
47
|
+
// Editors keep both their content and revision until the user saves or leaves.
|
|
48
|
+
if(['edit','policy','pair','tool','schema','transport','delete','deletePair'].includes(screen.page))continue
|
|
49
|
+
screen.revision=state.revision
|
|
50
|
+
screens.set(k,screen)
|
|
51
|
+
let view=render(state,runtimeView(screen),screen)
|
|
52
|
+
if(['server','overview'].includes(screen.page)&&previous)view=composeView({...view,controls:previous.controls,form:previous.form,filters:previous.filters})
|
|
53
|
+
if(JSON.stringify(view)===JSON.stringify(previous))continue
|
|
54
|
+
projections.set(k,view)
|
|
55
|
+
for(const emit of subscribers)emit(wire(view))
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const reconcile=()=>{Promise.resolve(runtime.reconcile()).then(notify,notify);notify()}
|
|
59
|
+
const dropUnused=async refs=>{for(const ref of new Set(refs.filter(Boolean)))if(!referenced(store.snapshot(),ref))await vault?.drop(ref)}
|
|
60
|
+
const guarded=fn=>async(scope,event={})=>{try{return await fn(scope,event)}catch(error){return {toast:error instanceof SyntaxError?'填写格式不正确,请检查':String(error.message).length<=40?error.message:'操作未完成,请重新打开后重试'}}}
|
|
61
|
+
const checkServer=(scope,id,force=false)=>{
|
|
62
|
+
const s=find(id);if(!s.enabled)return {toast:'请先启用此服务器'}
|
|
63
|
+
Promise.resolve(force?runtime.connect(id):runtime.refresh(id)).then(notify,notify)
|
|
64
|
+
const screen=screenOf(scope),before=projections.get(key(scope))
|
|
65
|
+
if(before&&['settings','server','overview'].includes(screen.page)){
|
|
66
|
+
const view=composeView({...before,connection:connectionView(s,runtimeView(screen)[id])})
|
|
67
|
+
projections.set(key(scope),view)
|
|
68
|
+
return {toast:force?'正在重新连接':'正在测试连接并刷新工具',...updateView(view)}
|
|
69
|
+
}
|
|
70
|
+
return {toast:'正在重新连接'}
|
|
71
|
+
}
|
|
72
|
+
const connectionFields=['name','url','command','cwd','argsLines']
|
|
73
|
+
const connectionDraft=(screen,input={})=>{
|
|
74
|
+
const saved=screen.serverId?find(screen.serverId):draftServer(),base={...saved,...screen.draft}
|
|
75
|
+
const draft={name:base.name,transport:base.transport,url:base.url,command:base.command,cwd:base.cwd,argsLines:base.argsLines??(base.args??[]).join('\n')}
|
|
76
|
+
for(const field of connectionFields)if(typeof input[field]==='string')draft[field]=input[field]
|
|
77
|
+
return draft
|
|
78
|
+
}
|
|
79
|
+
const actions={
|
|
80
|
+
editDraft:(scope,event)=>{
|
|
81
|
+
const screen=screenOf(scope),v=args(event)
|
|
82
|
+
if(screen.page!=='edit'||!connectionFields.includes(v.field))throw Error('请重新打开连接编辑页')
|
|
83
|
+
const value=v.value??formPayload(v)[v.field]
|
|
84
|
+
if(typeof value!=='string'||value.length>2000)throw Error('字段格式或长度不正确')
|
|
85
|
+
screens.set(key(scope),{...screen,draft:connectionDraft(screen,{[v.field]:value})})
|
|
86
|
+
return {}
|
|
87
|
+
},
|
|
88
|
+
searchDraft:(scope,event)=>{
|
|
89
|
+
const screen=screenOf(scope),v=args(event),query=v.value??formPayload(v).query
|
|
90
|
+
if(screen.page!=='server'||typeof query!=='string'||query.length>120)return {}
|
|
91
|
+
screens.set(key(scope),{...screen,draftQuery:query})
|
|
92
|
+
return {}
|
|
93
|
+
},
|
|
94
|
+
resumeConnection:scope=>{const screen=screenOf(scope);if(screen.page!=='transport'||!screen.returnToEditor)throw Error('请重新打开连接编辑页');return navigate(scope,{...screen,page:'edit'})},
|
|
95
|
+
back:scope=>navigate(scope,{page:'list',pageIndex:listPositions.get(key(scope))??0}),
|
|
96
|
+
refresh:()=>{reconcile();return {toast:'正在刷新连接状态'}},
|
|
97
|
+
addServer:scope=>navigate(scope,{page:'transport',draft:draftServer(),revision:store.snapshot().revision}),
|
|
98
|
+
changeTransport:(scope,event)=>{const current=screenOf(scope),v=args(event);if(current.page!=='edit')throw Error('请先打开连接设置');if(v.serverId&&v.serverId!==current.serverId)throw Error('编辑目标已变化');return navigate(scope,{...current,page:'transport',returnToEditor:true,draft:connectionDraft(current,formPayload(v))})},
|
|
99
|
+
chooseTransport:(scope,event)=>{const current=screenOf(scope),transport=args(event).transport;if(current.page!=='transport'||!['streamable-http','sse','stdio'].includes(transport))throw Error('请先选择连接方式');return navigate(scope,{...current,page:'edit',draft:{...connectionDraft(current),transport}})},
|
|
100
|
+
editServer:(scope,event)=>basic(scope,args(event).serverId),
|
|
101
|
+
editPolicy:(scope,event)=>navigate(scope,{page:'policy',serverId:find(args(event).serverId).id,revision:store.snapshot().revision}),
|
|
102
|
+
viewSettings:(scope,event)=>settings(scope,args(event).serverId),
|
|
103
|
+
viewCredentials:(scope,event)=>credentials(scope,args(event).serverId),
|
|
104
|
+
viewOverview:(scope,event)=>openTools(scope,args(event).serverId),
|
|
105
|
+
viewServer:(scope,event)=>openTools(scope,args(event).serverId),
|
|
106
|
+
viewRecords:(scope,event)=>navigate(scope,{...screenOf(scope),page:'records',serverId:find(args(event).serverId).id,pageIndex:0}),
|
|
107
|
+
pageRecords:(scope,event)=>{const v=args(event);return navigate(scope,{...screenOf(scope),page:'records',serverId:find(v.serverId).id,pageIndex:integer(v.pageIndex,0,1000,0)})},
|
|
108
|
+
viewCatalog:(scope,event)=>navigate(scope,{page:'catalog',serverId:find(args(event).serverId).id}),
|
|
109
|
+
pageServers:(scope,event)=>navigate(scope,{page:'list',pageIndex:integer(args(event).pageIndex,0,1000,0)}),
|
|
110
|
+
selectSection:(scope,event)=>{
|
|
111
|
+
const current=screenOf(scope),v=args(event),s=find(current.serverId)
|
|
112
|
+
if(v.serverId&&v.serverId!==s.id)throw Error('页面已变化,请重新打开')
|
|
113
|
+
const section=v.value??v.section??formPayload(v).section
|
|
114
|
+
if(section==='settings')return settings(scope,s.id)
|
|
115
|
+
if(section==='tools'||section==='overview')return openTools(scope,s.id)
|
|
116
|
+
if(section==='activity')return navigate(scope,{page:'records',serverId:s.id,pageIndex:0})
|
|
117
|
+
throw Error('请选择工具、活动或设置')
|
|
118
|
+
},
|
|
119
|
+
searchTools:(scope,event)=>{
|
|
120
|
+
const screen=screenOf(scope),v=args(event),input=formPayload(v)
|
|
121
|
+
if(!['server','overview'].includes(screen.page)||v.serverId&&v.serverId!==screen.serverId)throw Error('请重新打开工具列表')
|
|
122
|
+
const query=typeof input.query==='string'?input.query.trim().slice(0,120):''
|
|
123
|
+
const filter=['all','enabled','disabled'].includes(input.filter)?input.filter:screen.filter??'all'
|
|
124
|
+
return navigate(scope,{...screen,page:'server',query,draftQuery:query,filter,pageIndex:0})
|
|
125
|
+
},
|
|
126
|
+
filterTools:(scope,event)=>{
|
|
127
|
+
const screen=screenOf(scope),v=args(event),filter=v.value??v.filter
|
|
128
|
+
if(screen.page!=='server'||v.serverId&&v.serverId!==screen.serverId||!['all','enabled','disabled'].includes(filter))throw Error('请选择工具筛选范围')
|
|
129
|
+
const input=formPayload(v),draftQuery=typeof input.query==='string'?input.query:screen.draftQuery??screen.query??''
|
|
130
|
+
return navigate(scope,{...screen,query:draftQuery.trim().slice(0,120),draftQuery,pageIndex:0,filter})
|
|
131
|
+
},
|
|
132
|
+
clearSearch:(scope,event)=>navigate(scope,{page:'server',serverId:find(args(event).serverId).id,query:'',filter:'all',pageIndex:0}),
|
|
133
|
+
viewTool:(scope,event)=>{const v=args(event);find(v.serverId);return navigate(scope,{page:'tool',serverId:v.serverId,toolName:v.toolName,revision:store.snapshot().revision})},
|
|
134
|
+
viewSchema:(scope,event)=>{const v=args(event);find(v.serverId);return navigate(scope,{page:'schema',serverId:v.serverId,toolName:v.toolName})},
|
|
135
|
+
pageTools:(scope,event)=>{const v=args(event);find(v.serverId);return navigate(scope,{...screenOf(scope),page:'server',serverId:v.serverId,pageIndex:integer(v.pageIndex,0,1000,0)})},
|
|
136
|
+
requestDelete:(scope,event)=>navigate(scope,{page:'delete',serverId:find(args(event).serverId).id,revision:store.snapshot().revision}),
|
|
137
|
+
deleteServer:async(scope,event)=>{
|
|
138
|
+
const screen=screenOf(scope),v=args(event)
|
|
139
|
+
if(screen.page!=='delete')throw Error('请先选择要移除的服务器')
|
|
140
|
+
if(v.serverId!==screen.serverId||v.revision!==screen.revision)throw Error('确认目标已变化,请重新确认')
|
|
141
|
+
if(v.confirmed!==true)return settings(scope,screen.serverId)
|
|
142
|
+
const old=find(screen.serverId)
|
|
143
|
+
await store.update(revision(v,scope),next=>{next.servers=next.servers.filter(s=>s.id!==old.id)})
|
|
144
|
+
reconcile();await dropUnused([...old.headers,...old.env].map(x=>x.credentialRef))
|
|
145
|
+
return {...navigate(scope,{page:'list'}),toast:'服务器已移除'}
|
|
146
|
+
},
|
|
147
|
+
saveServer:async(scope,event)=>{
|
|
148
|
+
const screen=screenOf(scope),v=args(event)
|
|
149
|
+
if(!['edit','policy'].includes(screen.page))throw Error('请先打开连接或策略编辑页')
|
|
150
|
+
if(Buffer.byteLength(JSON.stringify(event.value??{}))>4096)throw Error('表单太长,请缩短地址或参数')
|
|
151
|
+
const input=formPayload(v),rev=revision(v,scope)
|
|
152
|
+
if(v.serverId!==undefined&&v.serverId!==(screen.serverId??''))throw Error('编辑目标已变化,请重新打开')
|
|
153
|
+
const old=screen.serverId?find(screen.serverId):undefined
|
|
154
|
+
const allowed=screen.page==='policy'?['timeoutMs','requireApproval']:['name','transport','url','command','cwd','argsLines']
|
|
155
|
+
const fields=Object.fromEntries(Object.entries(input).filter(([k])=>allowed.includes(k)))
|
|
156
|
+
const id=old?.id||'mcp_'+randomUUID().replaceAll('-','').slice(0,16)
|
|
157
|
+
const draft=screen.page==='edit'?connectionDraft(screen):{}
|
|
158
|
+
const merged={...(old??draftServer()),...draft,...fields,id,headers:old?.headers??[],env:old?.env??[]}
|
|
159
|
+
merged.args=typeof merged.argsLines==='string'?merged.argsLines.split('\n').filter(x=>x.length):old?.args??[]
|
|
160
|
+
delete merged.argsLines
|
|
161
|
+
const server=normalizeServer(merged,old)
|
|
162
|
+
await store.update(rev,next=>{if(old)next.servers[next.servers.findIndex(s=>s.id===id)]=server;else{if(next.servers.length>=32)throw Error('最多可添加 32 个服务器');next.servers.push(server)}})
|
|
163
|
+
reconcile();return {...settings(scope,id),toast:'已保存基础设置'}
|
|
164
|
+
},
|
|
165
|
+
toggleServer:async(scope,event)=>{const v=args(event),s=find(v.serverId);await store.update(revision(v,scope),next=>{const server=next.servers.find(x=>x.id===s.id);server.enabled=!server.enabled});reconcile();return settings(scope,s.id)},
|
|
166
|
+
saveTool:async(scope,event)=>{
|
|
167
|
+
const v=args(event),screen=screenOf(scope),input=formPayload(v)
|
|
168
|
+
if(screen.page!=='tool'||v.serverId&&v.serverId!==screen.serverId||v.toolName&&v.toolName!==screen.toolName)throw Error('工具目标已变化,请重新打开')
|
|
169
|
+
const s=find(screen.serverId)
|
|
170
|
+
if(!runtimeView(screen)[s.id]?.tools?.some(t=>t.name===screen.toolName))throw Error('工具列表已更新,请刷新')
|
|
171
|
+
await store.update(revision(v,scope),next=>{next.servers.find(x=>x.id===s.id).tools[screen.toolName]={enabled:bool(input.enabled,true),requireApproval:bool(input.requireApproval,true)}})
|
|
172
|
+
reconcile();return {...openTools(scope,s.id),toast:'工具设置已保存'}
|
|
173
|
+
},
|
|
174
|
+
connect:(scope,event)=>checkServer(scope,args(event).serverId,true),
|
|
175
|
+
testConnection:(scope,event)=>checkServer(scope,args(event).serverId),
|
|
176
|
+
addPair:(scope,event)=>{const v=args(event),s=find(v.serverId),kind=v.kind==='env'?'env':'headers';if(s[kind].length>=16)throw Error('最多可添加 16 项');return navigate(scope,{page:'pair',serverId:s.id,kind,index:-1,revision:store.snapshot().revision})},
|
|
177
|
+
editPair:(scope,event)=>{const v=args(event),s=find(v.serverId),kind=v.kind==='env'?'env':'headers',index=integer(v.index,0,15,0);if(!s[kind][index])throw Error('配置项已删除,请重新打开');return navigate(scope,{page:'pair',serverId:s.id,kind,index,revision:store.snapshot().revision})},
|
|
178
|
+
savePair:async(scope,event)=>{
|
|
179
|
+
const screen=screenOf(scope),v=args(event),input=formPayload(v)
|
|
180
|
+
if(screen.page!=='pair')throw Error('请重新打开请求头编辑页')
|
|
181
|
+
const rev=revision(v,scope),s=find(screen.serverId),kind=screen.kind,index=screen.index
|
|
182
|
+
if(v.serverId!==undefined&&v.serverId!==s.id||v.kind!==undefined&&v.kind!==kind||v.index!==undefined&&v.index!==index)throw Error('编辑目标已变化,请重新打开')
|
|
183
|
+
const old=s[kind][index],name=typeof input.pairName==='string'?input.pairName.trim():''
|
|
184
|
+
const value=input.pairValue??''
|
|
185
|
+
if(typeof value!=='string'||value.length>2000||/[\r\n\0]/.test(value))throw Error('值不能超过 2000 字符或包含换行')
|
|
186
|
+
if(value!==value.trim())throw Error('值前后有空白,请去除后再保存')
|
|
187
|
+
const clear=bool(input.clearValue,false)
|
|
188
|
+
if(clear&&value)throw Error('清空值和填写新值不能同时选择')
|
|
189
|
+
if(!old&&!value)throw Error('请填写值;无需鉴权则不必添加请求头')
|
|
190
|
+
const candidate=clear?{name,value:''}:value?{name,credentialRef:'MCP_PENDING'}:{...old,name}
|
|
191
|
+
const list=s[kind].slice();if(index===-1)list.push(candidate);else list[index]=candidate
|
|
192
|
+
pairs(list,kind)
|
|
193
|
+
let created
|
|
194
|
+
try{await store.update(rev,async next=>{if(value){if(!vault)throw Error('当前主机不支持保存凭据');created=await vault.put(value);candidate.credentialRef=created}const server=next.servers.find(x=>x.id===s.id);if(index===-1)server[kind].push(candidate);else server[kind][index]=candidate})}
|
|
195
|
+
catch(error){if(created)await vault.drop(created);throw error}
|
|
196
|
+
reconcile();await dropUnused([old?.credentialRef])
|
|
197
|
+
return {...credentials(scope,s.id),toast:'已保存并更新连接'}
|
|
198
|
+
},
|
|
199
|
+
requestDeletePair:(scope,event)=>{const v=args(event),s=find(v.serverId),kind=v.kind==='env'?'env':'headers',index=integer(v.index,0,15,0);if(!s[kind][index])throw Error('配置项已删除');return navigate(scope,{page:'deletePair',serverId:s.id,kind,index,revision:store.snapshot().revision})},
|
|
200
|
+
deletePair:async(scope,event)=>{
|
|
201
|
+
const screen=screenOf(scope),v=args(event)
|
|
202
|
+
if(screen.page!=='deletePair')throw Error('请先选择要删除的请求头')
|
|
203
|
+
if(v.serverId!==screen.serverId||v.kind!==screen.kind||v.index!==screen.index||v.revision!==screen.revision)throw Error('确认目标已变化,请重新确认')
|
|
204
|
+
if(v.confirmed!==true)return credentials(scope,screen.serverId)
|
|
205
|
+
const old=find(screen.serverId)[screen.kind][screen.index]
|
|
206
|
+
await store.update(revision(v,scope),next=>{next.servers.find(s=>s.id===screen.serverId)[screen.kind].splice(screen.index,1)})
|
|
207
|
+
reconcile();await dropUnused([old?.credentialRef]);return {...credentials(scope,screen.serverId),toast:'已删除并更新连接'}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return {notify,data,screens,actions:Object.fromEntries(Object.entries(actions).map(([id,fn])=>[id,guarded(fn)])),panel:{view:buildView,data:(scope,emit)=>{const k=key(scope),set=listeners.get(k)??new Set();set.add(emit);listeners.set(k,set);emit(wire(data(scope)));return ()=>{set.delete(emit);if(!set.size){listeners.delete(k);projections.delete(k)}}}},dispose:()=>{disposed=true;if(notifyTimer)clearTimeout(notifyTimer);listeners.clear();screens.clear();projections.clear();toolPositions.clear();listPositions.clear()}}
|
|
211
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto'
|
|
2
|
+
import { credentialRef } from '@deepseek-ai/dsh-credentials'
|
|
3
|
+
const OWNED=/^MCP_MANAGER_[A-F0-9]{32}$/
|
|
4
|
+
export function createVault(getService) {
|
|
5
|
+
return {
|
|
6
|
+
async put(value) {
|
|
7
|
+
if(typeof value!=='string'||!value||value.length>2000||/[\r\n\0]/.test(value))throw Error('请求头值无效:不能为空或包含换行')
|
|
8
|
+
const service=getService()
|
|
9
|
+
if(typeof service?.set!=='function')throw Error('当前主机不支持保存凭据')
|
|
10
|
+
const ref='MCP_MANAGER_'+randomUUID().replaceAll('-','').toUpperCase()
|
|
11
|
+
try {await service.set(credentialRef(ref),value)}catch{throw Error('凭据保存失败,请重试;原值未修改')}
|
|
12
|
+
return ref
|
|
13
|
+
},
|
|
14
|
+
async drop(ref) {
|
|
15
|
+
if(!OWNED.test(ref??''))return
|
|
16
|
+
const service=getService()
|
|
17
|
+
if(typeof service?.unset!=='function')return
|
|
18
|
+
try {await service.unset(credentialRef(ref))}catch{/* Retain unreferenced secret rather than misreport committed edits. */}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export function referenced(state,ref) {return state.servers.some(s=>[...s.headers,...s.env].some(row=>row.credentialRef===ref))}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import z from '@deepseek-ai/schemastery'
|
|
2
|
+
import { credentialRef } from '@deepseek-ai/dsh-credentials'
|
|
3
|
+
import { join } from 'node:path'
|
|
4
|
+
import { homedir } from 'node:os'
|
|
5
|
+
import { StateStore } from './store.js'
|
|
6
|
+
import { createRuntime } from './runtime.js'
|
|
7
|
+
import { createController } from './controller.js'
|
|
8
|
+
import { createVault } from './credentials.js'
|
|
9
|
+
|
|
10
|
+
export const name='local-mcp-manager'
|
|
11
|
+
export const Config=z.object({
|
|
12
|
+
autoConnect:z.boolean().default(true).description('允许 MCP 连接(总开关)。服务器、请求头和工具请在本插件原生面板管理。'),
|
|
13
|
+
credentials:z.array(z.object({
|
|
14
|
+
ref:z.string().required(),
|
|
15
|
+
value:z.string().role('secret')
|
|
16
|
+
})).default([]).hidden()
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
export async function apply(ctx,config={}) {
|
|
20
|
+
const root=process.env.DSH_HOME||join(homedir(),'.dsh')
|
|
21
|
+
const store=new StateStore(join(root,'dsh-go','plugin-data',name,'servers.json'))
|
|
22
|
+
await store.load()
|
|
23
|
+
let active,controller,closed=false,credentialContext=ctx
|
|
24
|
+
const runtime={snapshot:()=>active?.snapshot()??{},project:options=>active?.project(options)??{},reconcile:()=>active?.reconcile(),connect:id=>active?.connect(id),refresh:id=>active?.refresh(id)}
|
|
25
|
+
const resolveSecret=async(ref,source=credentialContext)=>{
|
|
26
|
+
const entry=(config.credentials??[]).find(x=>x.ref===ref)
|
|
27
|
+
if(typeof entry?.value==='string'&&entry.value)return entry.value
|
|
28
|
+
const service=source.get('credentials')
|
|
29
|
+
return service?(await service.resolve(credentialRef(ref)))?.value:undefined
|
|
30
|
+
}
|
|
31
|
+
controller=createController(store,runtime,{vault:createVault(()=>credentialContext.get('credentials'))})
|
|
32
|
+
// A credentials provider may initialize after tools. Do not attempt authenticated
|
|
33
|
+
// MCP connections until both services exist; otherwise one early miss is marked
|
|
34
|
+
// blocked and will not be retried by the ordinary list refresh.
|
|
35
|
+
ctx.inject(['tools','credentials'],child=>{
|
|
36
|
+
if(closed)return
|
|
37
|
+
if(typeof child.tools.guard!=='function') {
|
|
38
|
+
ctx.logger?.warn?.('MCP connections disabled: host tool guard API unavailable')
|
|
39
|
+
return
|
|
40
|
+
}
|
|
41
|
+
credentialContext=child
|
|
42
|
+
const instance=createRuntime(child,{
|
|
43
|
+
getState:()=>{const state=store.snapshot();if(config.autoConnect===false)state.servers=state.servers.map(s=>({...s,enabled:false}));return state},
|
|
44
|
+
resolveSecret:ref=>resolveSecret(ref,child),onInvalidate:()=>controller.notify()
|
|
45
|
+
})
|
|
46
|
+
active=instance
|
|
47
|
+
instance.reconcile().catch(()=>child.logger?.warn?.('MCP startup reconciliation failed'))
|
|
48
|
+
child.on('dispose',async()=>{
|
|
49
|
+
if(active===instance)active=undefined
|
|
50
|
+
if(credentialContext===child)credentialContext=ctx
|
|
51
|
+
await instance.dispose()
|
|
52
|
+
})
|
|
53
|
+
})
|
|
54
|
+
ctx.inject(['dshGo'],child=>{
|
|
55
|
+
child.dshGo.panel('mcp-manager',{...controller.panel,actions:controller.actions})
|
|
56
|
+
})
|
|
57
|
+
ctx.on('dispose',async()=>{
|
|
58
|
+
if(closed)return
|
|
59
|
+
closed=true;controller.dispose()
|
|
60
|
+
const instance=active;active=undefined
|
|
61
|
+
await instance?.dispose()
|
|
62
|
+
})
|
|
63
|
+
}
|