@fengguanghuai/dsh-capability-hub 1.0.0 → 1.0.2
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/LICENSE +21 -0
- package/README.md +121 -11
- package/README.zh-CN.md +92 -0
- package/client.js +352 -20
- package/index.js +109 -6
- package/package.json +13 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 fengguanghuai
|
|
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,23 +1,133 @@
|
|
|
1
1
|
# @fengguanghuai/dsh-capability-hub
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/@fengguanghuai/dsh-capability-hub)
|
|
4
|
+
[](./LICENSE)
|
|
5
|
+
[](https://github.com/topics/dsh-plugin)
|
|
6
|
+
|
|
7
|
+
**English** | [简体中文](./README.zh-CN.md)
|
|
8
|
+
|
|
9
|
+
A unified capability hub for **DeepSeek Harness (DSH)** that lets you organize **Skills** and **MCP servers** into switchable suites, control per-session capability injection from the chat composer, and manage local skills end-to-end without cluttering your context window.
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Preview
|
|
14
|
+
|
|
15
|
+
| Suites & Budget Overview | Skills Drawer & Per-Session Composer |
|
|
16
|
+
| --- | --- |
|
|
17
|
+
|  |  |
|
|
18
|
+
|
|
19
|
+
## Key Features
|
|
20
|
+
|
|
21
|
+
- **Switchable Capability Suites**: Group related MCP servers and Skills into scenario suites (e.g., Office docs, architecture/artifacts, media workflows) and toggle them with one click.
|
|
22
|
+
- **Per-Session Injection (Composer Popover)**: Pick which suites are active for the **current session** directly from the chat composer without affecting global defaults or other sessions. Subagents inherit their parent session's active suites automatically.
|
|
23
|
+
- **Non-Destructive Skill Policy**: Override Skill invocation between `auto`, `manual` (`/skill`-only), and `muted` in memory—never dirtying `SKILL.md` files on disk.
|
|
24
|
+
- **Full Skill Lifecycle**:
|
|
25
|
+
- **Create / Paste**: Write or paste a `SKILL.md` (with automatic frontmatter parsing) into user (`~/.agents/skills`, `~/.dsh/skills`) or project (`.agents/skills`, `.dsh/skills`) directories.
|
|
26
|
+
- **Import**: Install from a repository (`npx -y skills add`), import from a local directory, or upload a `.zip` archive (with path-traversal protection).
|
|
27
|
+
- **Edit & Safe Uninstall**: Edit writable `SKILL.md` files in place, or remove them by archiving to `~/.agents/skills-disabled/` or permanently deleting them (while cleaning up suite references). Built-in/bundled skills remain read-only.
|
|
28
|
+
- **Granular MCP Control**: Toggle individual `mcp__<server>__<tool>` tools, reconnect servers, or add custom `stdio` / `streamable-http` MCP servers.
|
|
29
|
+
- **Agent Tool (`capability_hub`)**: Exposes status inspection, suite/skill/MCP toggling, and skill management directly to the agent.
|
|
4
30
|
|
|
5
31
|
## Installation
|
|
6
32
|
|
|
7
|
-
|
|
33
|
+
### Via CLI (Recommended)
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
# Install from npm into the web profile
|
|
37
|
+
dsh plugin --profile web add @fengguanghuai/dsh-capability-hub
|
|
38
|
+
|
|
39
|
+
# Or without a global dsh install
|
|
40
|
+
npx @deepseek-ai/dsh plugin --profile web add @fengguanghuai/dsh-capability-hub
|
|
41
|
+
|
|
42
|
+
# Or install directly from GitHub
|
|
43
|
+
dsh plugin --profile web add github:fengguanghuai/dsh-capability-hub
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
> Restart `dsh web` (or reopen the desktop app) after installing if the sidebar entry does not appear immediately.
|
|
47
|
+
|
|
48
|
+
### Via DeepSeek Harness UI
|
|
49
|
+
|
|
50
|
+
Open **Plugins → Add plugin** and enter either:
|
|
8
51
|
|
|
9
|
-
|
|
10
|
-
github:fengguanghuai/dsh-capability-hub
|
|
52
|
+
- `@fengguanghuai/dsh-capability-hub`
|
|
53
|
+
- `github:fengguanghuai/dsh-capability-hub`
|
|
54
|
+
|
|
55
|
+
### Update & Uninstall
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
# Update to the latest version
|
|
59
|
+
dsh plugin --profile web update @fengguanghuai/dsh-capability-hub
|
|
60
|
+
|
|
61
|
+
# Remove the plugin
|
|
62
|
+
dsh plugin --profile web remove @fengguanghuai/dsh-capability-hub
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
> Disabling or removing this bundle immediately restores default tool and skill visibility.
|
|
66
|
+
|
|
67
|
+
## Quick Start
|
|
68
|
+
|
|
69
|
+
1. Open **Capability Hub** from the top-left sidebar.
|
|
70
|
+
2. Switch between the **Suites**, **Skills**, and **MCPs** tabs—the top-right action button adapts automatically (`+ New Suite` / `+ Add Skill` / `+ Connect MCP`).
|
|
71
|
+
3. Create a suite by selecting related MCP servers and Skills.
|
|
72
|
+
4. In any chat session, click the **Suites** pill in the chat composer to override active suites for that session only (subagents inherit the selection automatically).
|
|
73
|
+
|
|
74
|
+
## Architecture
|
|
75
|
+
|
|
76
|
+
```mermaid
|
|
77
|
+
flowchart TB
|
|
78
|
+
subgraph UI["Web UI (client.js)"]
|
|
79
|
+
Sidebar["Sidebar Entry (Capability Hub)"]
|
|
80
|
+
Hub["Main Panel (Suites · Skills · MCPs)"]
|
|
81
|
+
Drawer["Right Drawer (Inspect · Create · Import · Edit)"]
|
|
82
|
+
Composer["Chat Composer Pill (Per-Session Suites)"]
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
subgraph Core["Cordis Plugin Runtime (index.js)"]
|
|
86
|
+
API["HTTP API (/api/capability-hub) and Agent Tool (capability_hub)"]
|
|
87
|
+
State["State Store (~/.dsh/capability-hub/state.json)"]
|
|
88
|
+
SkillPolicy["Skill Policy Provider (in-memory auto / manual / muted)"]
|
|
89
|
+
ToolFilter["Session Tool Filter (per-session and subagent inheritance)"]
|
|
90
|
+
SkillFS["Skill Lifecycle Manager (save · import repo/local/zip · archive/delete)"]
|
|
91
|
+
McpMgr["Custom MCP Manager (stdio · streamable-http)"]
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
subgraph Disk["Runtime and Local Storage"]
|
|
95
|
+
AgentCtx["Live DSH Sessions and Subagents"]
|
|
96
|
+
SkillDirs["Skill Directories (~/.agents/skills, .agents/skills)"]
|
|
97
|
+
ArchiveDir["Archive (~/.agents/skills-disabled/)"]
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
Sidebar --> Hub
|
|
101
|
+
Hub --> Drawer
|
|
102
|
+
Hub --> API
|
|
103
|
+
Composer --> API
|
|
104
|
+
API --> State
|
|
105
|
+
State --> SkillPolicy
|
|
106
|
+
State --> ToolFilter
|
|
107
|
+
API --> SkillFS
|
|
108
|
+
API --> McpMgr
|
|
109
|
+
SkillPolicy --> AgentCtx
|
|
110
|
+
ToolFilter --> AgentCtx
|
|
111
|
+
SkillFS --> SkillDirs
|
|
112
|
+
SkillFS --> ArchiveDir
|
|
11
113
|
```
|
|
12
114
|
|
|
13
|
-
|
|
115
|
+
## Data, Permissions & Safety
|
|
116
|
+
|
|
117
|
+
- **Local State**: Persists suite definitions, skill policy overrides, and custom MCP metadata in `~/.dsh/capability-hub/state.json`.
|
|
118
|
+
- **Skill Files**: Reads/writes user-managed skills under `~/.agents/skills`, `~/.dsh/skills`, `.agents/skills`, and `.dsh/skills`. Archiving moves skills to `~/.agents/skills-disabled/`. Built-in skills remain read-only, and skill policy overrides (`auto` / `manual` / `muted`) stay in memory without modifying `SKILL.md`.
|
|
119
|
+
- **External Commands**: Importing a skill from a Git repository invokes `npx -y skills add`.
|
|
120
|
+
- **Exposed Surfaces**: Registers the local HTTP endpoint `/api/capability-hub` and the `capability_hub` agent tool.
|
|
121
|
+
- **Privacy**: Runs entirely locally with no telemetry or external data collection.
|
|
122
|
+
|
|
123
|
+
## Development & Testing
|
|
14
124
|
|
|
15
|
-
```
|
|
16
|
-
|
|
125
|
+
```bash
|
|
126
|
+
node --check index.js
|
|
127
|
+
node --check client.js
|
|
128
|
+
node test.mjs
|
|
17
129
|
```
|
|
18
130
|
|
|
19
|
-
##
|
|
131
|
+
## License
|
|
20
132
|
|
|
21
|
-
|
|
22
|
-
- **Switchable capability bundles**: Group related MCP servers and Skills into project/scenario suites and toggle them together without dirtying repository `SKILL.md` files.
|
|
23
|
-
- **Granular Skill & MCP control**: Inspect `SKILL.md` instructions, switch skills between automatic, `/skill`-only, and muted states, toggle individual `mcp__<server>__<tool>` tools across live and new sessions, and connect custom `stdio` / `streamable-http` MCP servers.
|
|
133
|
+
[MIT](./LICENSE)
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# @fengguanghuai/dsh-capability-hub(能力中心)
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@fengguanghuai/dsh-capability-hub)
|
|
4
|
+
[](./LICENSE)
|
|
5
|
+
[](https://github.com/topics/dsh-plugin)
|
|
6
|
+
|
|
7
|
+
[English](./README.md) | **简体中文**
|
|
8
|
+
|
|
9
|
+
**能力中心(Capability Hub)** 是面向 **DeepSeek Harness (DSH)** 的统一能力编排插件。它可以将 **Skills** 与 **MCP 服务** 打包为可一键切换的场景套件,支持在聊天输入框中按会话动态注入能力,并提供本地 Skill 的全生命周期管理,避免工具与上下文膨胀。
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## 界面预览
|
|
14
|
+
|
|
15
|
+
| 套件与上下文预算总览 | Skill 抽屉与会话级套件选择 |
|
|
16
|
+
| --- | --- |
|
|
17
|
+
|  |  |
|
|
18
|
+
|
|
19
|
+
## 核心特性
|
|
20
|
+
|
|
21
|
+
- **场景套件一键切换**:将关联的 MCP 服务与 Skill 打包为场景套件(如文档处理、架构绘图、媒体工作流等),一键启用或停用。
|
|
22
|
+
- **会话级按需注入(聊天框快捷入口)**:在聊天框底部的「套件」入口中,单独指定**当前会话**启用的套件,不影响全局默认配置或其他会话;子 Agent 会自动继承父会话的套件策略。
|
|
23
|
+
- **无侵入 Skill 策略控制**:在内存中动态切换 `自动触发 (auto)`、`仅手动 /skill (manual)` 与 `静默隐藏 (muted)`,绝不修改磁盘上的原始 `SKILL.md`。
|
|
24
|
+
- **Skill 全生命周期管理**:
|
|
25
|
+
- **新建 / 粘贴**:支持在线编写或粘贴 `SKILL.md`(自动解析 frontmatter),写入用户目录(`~/.agents/skills`、`~/.dsh/skills`)或项目目录(`.agents/skills`、`.dsh/skills`)。
|
|
26
|
+
- **多源导入**:支持从仓库导入(`npx -y skills add`)、本地目录导入以及 `.zip` 压缩包上传(内置路径穿越防护)。
|
|
27
|
+
- **编辑与安全卸载**:支持在线编辑可写 Skill;移除时可选择「移入归档(`~/.agents/skills-disabled/`)」或「彻底删除」(自动清理套件引用)。内置 Skill 保持只读。
|
|
28
|
+
- **MCP 精细化控制**:支持工具级开关(`mcp__<server>__<tool>`)、服务重连及新增自定义 `stdio` / `streamable-http` MCP 连接。
|
|
29
|
+
- **Agent 工具(`capability_hub`)**:向智能体开放状态查看、套件/Skill/MCP 启停以及 Skill 管理能力。
|
|
30
|
+
|
|
31
|
+
## 安装方式
|
|
32
|
+
|
|
33
|
+
### 通过 CLI 安装(推荐)
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
# 从 npm 安装到 web profile
|
|
37
|
+
dsh plugin --profile web add @fengguanghuai/dsh-capability-hub
|
|
38
|
+
|
|
39
|
+
# 如未全局安装 dsh,可使用 npx
|
|
40
|
+
npx @deepseek-ai/dsh plugin --profile web add @fengguanghuai/dsh-capability-hub
|
|
41
|
+
|
|
42
|
+
# 或直接从 GitHub 安装
|
|
43
|
+
dsh plugin --profile web add github:fengguanghuai/dsh-capability-hub
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
> 安装完成后,如左侧栏未立即出现入口,请重启 `dsh web`(或重启桌面端应用)。
|
|
47
|
+
|
|
48
|
+
### 通过 DeepSeek Harness 界面安装
|
|
49
|
+
|
|
50
|
+
打开 **Plugins → Add plugin**(插件 → 添加插件),输入以下任意地址:
|
|
51
|
+
|
|
52
|
+
- `@fengguanghuai/dsh-capability-hub`
|
|
53
|
+
- `github:fengguanghuai/dsh-capability-hub`
|
|
54
|
+
|
|
55
|
+
### 更新与卸载
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
# 更新到最新版本
|
|
59
|
+
dsh plugin --profile web update @fengguanghuai/dsh-capability-hub
|
|
60
|
+
|
|
61
|
+
# 卸载插件
|
|
62
|
+
dsh plugin --profile web remove @fengguanghuai/dsh-capability-hub
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
> 禁用或卸载本插件后,会自动恢复全部默认的工具与 Skill 可见性策略。
|
|
66
|
+
|
|
67
|
+
## 快速上手
|
|
68
|
+
|
|
69
|
+
1. 点击左上角侧边栏的 **能力中心(Capability Hub)** 打开主面板。
|
|
70
|
+
2. 顶部可在 **套件 / Skills / MCP** 之间切换,右上角操作按钮会随当前 Tab 自动联动(`+ 新建套件` / `+ 添加 Skill` / `+ 连接 MCP`)。
|
|
71
|
+
3. 创建一个场景套件并勾选关联的 MCP 服务与 Skill。
|
|
72
|
+
4. 在任意对话中,点击聊天输入框底部的「套件」胶囊入口,即可为当前会话单独调整启用的套件。
|
|
73
|
+
|
|
74
|
+
## 数据存储、权限与安全说明
|
|
75
|
+
|
|
76
|
+
- **本地状态文件**:套件配置、Skill 策略覆写与自定义 MCP 元数据保存在 `~/.dsh/capability-hub/state.json`。
|
|
77
|
+
- **Skill 目录读写**:仅读写 `~/.agents/skills`、`~/.dsh/skills`、`.agents/skills`、`.dsh/skills`,归档目录为 `~/.agents/skills-disabled/`;内置 Skill 只读;策略切换在内存中生效,不改动原 `SKILL.md`。
|
|
78
|
+
- **外部命令**:仅在使用「从仓库导入 Skill」功能时执行 `npx -y skills add`。
|
|
79
|
+
- **扩展接口**:注册本地 HTTP 接口 `/api/capability-hub` 与 Agent 工具 `capability_hub`。
|
|
80
|
+
- **隐私**:完全在本地运行,无遥测、无外部数据上报。
|
|
81
|
+
|
|
82
|
+
## 开发与测试
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
node --check index.js
|
|
86
|
+
node --check client.js
|
|
87
|
+
node test.mjs
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## 开源协议
|
|
91
|
+
|
|
92
|
+
[MIT](./LICENSE)
|
package/client.js
CHANGED
|
@@ -1111,12 +1111,22 @@ window.__ModuleLoader__.load({
|
|
|
1111
1111
|
const [bfSkillFilter, setBfSkillFilter] = useState('');
|
|
1112
1112
|
|
|
1113
1113
|
// Custom MCP form state
|
|
1114
|
+
const [cmEditing, setCmEditing] = useState(false);
|
|
1114
1115
|
const [cmName, setCmName] = useState('');
|
|
1115
1116
|
const [cmTransport, setCmTransport] = useState('streamable-http');
|
|
1116
1117
|
const [cmUrl, setCmUrl] = useState('');
|
|
1118
|
+
const [cmAuthType, setCmAuthType] = useState('none'); // 'none' | 'bearer' | 'api-key' | 'custom'
|
|
1119
|
+
const [cmBearerToken, setCmBearerToken] = useState('');
|
|
1120
|
+
const [cmApiKeyHeader, setCmApiKeyHeader] = useState('X-API-Key');
|
|
1121
|
+
const [cmApiKeyValue, setCmApiKeyValue] = useState('');
|
|
1122
|
+
const [cmHeadersText, setCmHeadersText] = useState('');
|
|
1123
|
+
const [cmKeepHeaders, setCmKeepHeaders] = useState({}); // { key: maskedValue }
|
|
1117
1124
|
const [cmCommand, setCmCommand] = useState('npx');
|
|
1118
1125
|
const [cmArgs, setCmArgs] = useState('');
|
|
1126
|
+
const [cmEnvText, setCmEnvText] = useState('');
|
|
1127
|
+
const [cmKeepEnv, setCmKeepEnv] = useState({}); // { key: maskedValue }
|
|
1119
1128
|
const [cmCwd, setCmCwd] = useState('');
|
|
1129
|
+
const [cmShowSecret, setCmShowSecret] = useState(false);
|
|
1120
1130
|
|
|
1121
1131
|
// Skill add / edit / import / delete state
|
|
1122
1132
|
const [skModeTab, setSkModeTab] = useState('create'); // 'create' | 'import'
|
|
@@ -1214,13 +1224,56 @@ window.__ModuleLoader__.load({
|
|
|
1214
1224
|
setDrawer({ kind: 'bundle-form' });
|
|
1215
1225
|
}, []);
|
|
1216
1226
|
|
|
1217
|
-
const openConnectMcp = useCallback(() => {
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1227
|
+
const openConnectMcp = useCallback((existing = null) => {
|
|
1228
|
+
setCmShowSecret(false);
|
|
1229
|
+
if (existing && typeof existing === 'object' && typeof existing.name === 'string' && existing.name) {
|
|
1230
|
+
setCmEditing(true);
|
|
1231
|
+
setCmName(existing.name || '');
|
|
1232
|
+
const tr = existing.transport === 'stdio' ? 'stdio' : 'streamable-http';
|
|
1233
|
+
setCmTransport(tr);
|
|
1234
|
+
setCmUrl(existing.url || '');
|
|
1235
|
+
setCmCommand(existing.command || 'npx');
|
|
1236
|
+
setCmArgs(Array.isArray(existing.args) ? existing.args.join(' ') : '');
|
|
1237
|
+
setCmCwd(existing.cwd || '');
|
|
1238
|
+
const existingHeaders = existing.headers && typeof existing.headers === 'object' ? { ...existing.headers } : {};
|
|
1239
|
+
const existingEnv = existing.env && typeof existing.env === 'object' ? { ...existing.env } : {};
|
|
1240
|
+
setCmKeepHeaders(existingHeaders);
|
|
1241
|
+
setCmKeepEnv(existingEnv);
|
|
1242
|
+
setCmBearerToken('');
|
|
1243
|
+
setCmApiKeyValue('');
|
|
1244
|
+
setCmHeadersText('');
|
|
1245
|
+
setCmEnvText('');
|
|
1246
|
+
const hKeys = Object.keys(existingHeaders);
|
|
1247
|
+
if (hKeys.length === 0) {
|
|
1248
|
+
setCmAuthType('none');
|
|
1249
|
+
setCmApiKeyHeader('X-API-Key');
|
|
1250
|
+
} else if (hKeys.length === 1 && /^authorization$/i.test(hKeys[0]) && /^bearer\s+/i.test(existingHeaders[hKeys[0]] || '')) {
|
|
1251
|
+
setCmAuthType('bearer');
|
|
1252
|
+
setCmApiKeyHeader('X-API-Key');
|
|
1253
|
+
} else if (hKeys.length === 1) {
|
|
1254
|
+
setCmAuthType('api-key');
|
|
1255
|
+
setCmApiKeyHeader(hKeys[0]);
|
|
1256
|
+
} else {
|
|
1257
|
+
setCmAuthType('custom');
|
|
1258
|
+
setCmApiKeyHeader('X-API-Key');
|
|
1259
|
+
}
|
|
1260
|
+
} else {
|
|
1261
|
+
setCmEditing(false);
|
|
1262
|
+
setCmName('');
|
|
1263
|
+
setCmTransport('streamable-http');
|
|
1264
|
+
setCmUrl('');
|
|
1265
|
+
setCmAuthType('none');
|
|
1266
|
+
setCmBearerToken('');
|
|
1267
|
+
setCmApiKeyHeader('X-API-Key');
|
|
1268
|
+
setCmApiKeyValue('');
|
|
1269
|
+
setCmHeadersText('');
|
|
1270
|
+
setCmKeepHeaders({});
|
|
1271
|
+
setCmCommand('npx');
|
|
1272
|
+
setCmArgs('');
|
|
1273
|
+
setCmEnvText('');
|
|
1274
|
+
setCmKeepEnv({});
|
|
1275
|
+
setCmCwd('');
|
|
1276
|
+
}
|
|
1224
1277
|
setDrawer({ kind: 'connect-mcp' });
|
|
1225
1278
|
}, []);
|
|
1226
1279
|
|
|
@@ -1622,7 +1675,7 @@ window.__ModuleLoader__.load({
|
|
|
1622
1675
|
activeTab === 'skills'
|
|
1623
1676
|
? h('button', { type: 'button', className: 'ch-btn ch-btn-primary', onClick: () => openAddSkill(null) }, t('btn.addSkill'))
|
|
1624
1677
|
: activeTab === 'mcps'
|
|
1625
|
-
? h('button', { type: 'button', className: 'ch-btn ch-btn-primary', onClick: openConnectMcp }, t('btn.connectMcp'))
|
|
1678
|
+
? h('button', { type: 'button', className: 'ch-btn ch-btn-primary', onClick: () => openConnectMcp() }, t('btn.connectMcp'))
|
|
1626
1679
|
: h('button', { type: 'button', className: 'ch-btn ch-btn-primary', onClick: () => openBundleForm(null) }, t('btn.newBundle')),
|
|
1627
1680
|
),
|
|
1628
1681
|
),
|
|
@@ -2111,6 +2164,7 @@ window.__ModuleLoader__.load({
|
|
|
2111
2164
|
{ style: { display: 'flex', alignItems: 'center', gap: 8, flexWrap: 'wrap' } },
|
|
2112
2165
|
h('span', { className: m.enabled ? 'ch-pill ok' : 'ch-pill' }, m.enabled ? t('status.connected') : t('status.muted')),
|
|
2113
2166
|
h('span', { className: 'ch-pill ch-mono' }, m.transport),
|
|
2167
|
+
m.hasAuth ? h('span', { className: 'ch-pill ok' }, '已配置鉴权') : null,
|
|
2114
2168
|
h('span', { className: 'ch-pill' }, `${m.activeTools}/${m.totalTools} tools`),
|
|
2115
2169
|
),
|
|
2116
2170
|
h(
|
|
@@ -2119,6 +2173,17 @@ window.__ModuleLoader__.load({
|
|
|
2119
2173
|
m.canRestart
|
|
2120
2174
|
? h('button', { type: 'button', className: 'ch-btn ch-btn-sm', onClick: () => runMutation({ action: 'restart_mcp', serverName: m.name }) }, t('btn.restart'))
|
|
2121
2175
|
: null,
|
|
2176
|
+
m.isCustom
|
|
2177
|
+
? h(
|
|
2178
|
+
'button',
|
|
2179
|
+
{
|
|
2180
|
+
type: 'button',
|
|
2181
|
+
className: 'ch-btn ch-btn-sm',
|
|
2182
|
+
onClick: () => openConnectMcp(m),
|
|
2183
|
+
},
|
|
2184
|
+
'编辑配置',
|
|
2185
|
+
)
|
|
2186
|
+
: null,
|
|
2122
2187
|
m.isCustom
|
|
2123
2188
|
? h(
|
|
2124
2189
|
'button',
|
|
@@ -2419,6 +2484,83 @@ window.__ModuleLoader__.load({
|
|
|
2419
2484
|
}
|
|
2420
2485
|
|
|
2421
2486
|
if (drawer.kind === 'connect-mcp') {
|
|
2487
|
+
const credRe = /\$\{credential:[^}]+\}/;
|
|
2488
|
+
const maskPreview = (val) => {
|
|
2489
|
+
const str = String(val || '');
|
|
2490
|
+
if (!str) return '';
|
|
2491
|
+
if (credRe.test(str)) return str;
|
|
2492
|
+
const bm = /^(Bearer\s+)(.+)$/i.exec(str);
|
|
2493
|
+
if (bm) return `${bm[1]}${maskPreview(bm[2])}`;
|
|
2494
|
+
if (str.length <= 8) return '****';
|
|
2495
|
+
return `${str.slice(0, 4)}****${str.slice(-4)}`;
|
|
2496
|
+
};
|
|
2497
|
+
const parseKvLines = (text, sep) => {
|
|
2498
|
+
const map = {};
|
|
2499
|
+
for (const rawLine of String(text || '').split(/\r?\n/)) {
|
|
2500
|
+
const line = rawLine.trim();
|
|
2501
|
+
if (!line || line.startsWith('#')) continue;
|
|
2502
|
+
const idx = line.indexOf(sep);
|
|
2503
|
+
if (idx <= 0) continue;
|
|
2504
|
+
const k = line.slice(0, idx).trim();
|
|
2505
|
+
const v = line.slice(idx + 1).trim();
|
|
2506
|
+
if (k && v) map[k] = v;
|
|
2507
|
+
}
|
|
2508
|
+
return map;
|
|
2509
|
+
};
|
|
2510
|
+
const buildHttpHeaders = (forPreview) => {
|
|
2511
|
+
const out = {};
|
|
2512
|
+
if (cmAuthType === 'bearer') {
|
|
2513
|
+
const tok = cmBearerToken.trim();
|
|
2514
|
+
if (tok) {
|
|
2515
|
+
const rawVal = /^bearer\s+/i.test(tok) ? tok : `Bearer ${tok}`;
|
|
2516
|
+
out.Authorization = forPreview ? maskPreview(rawVal) : rawVal;
|
|
2517
|
+
} else {
|
|
2518
|
+
const existingAuthKey = Object.keys(cmKeepHeaders).find((k) => /^authorization$/i.test(k));
|
|
2519
|
+
if (existingAuthKey) {
|
|
2520
|
+
out[existingAuthKey] = forPreview ? cmKeepHeaders[existingAuthKey] : '__KEEP__';
|
|
2521
|
+
}
|
|
2522
|
+
}
|
|
2523
|
+
} else if (cmAuthType === 'api-key') {
|
|
2524
|
+
const hk = cmApiKeyHeader.trim() || 'X-API-Key';
|
|
2525
|
+
const hv = cmApiKeyValue.trim();
|
|
2526
|
+
if (hv) {
|
|
2527
|
+
out[hk] = forPreview ? maskPreview(hv) : hv;
|
|
2528
|
+
} else if (cmKeepHeaders[hk]) {
|
|
2529
|
+
out[hk] = forPreview ? cmKeepHeaders[hk] : '__KEEP__';
|
|
2530
|
+
}
|
|
2531
|
+
} else if (cmAuthType === 'custom') {
|
|
2532
|
+
for (const [k, masked] of Object.entries(cmKeepHeaders)) {
|
|
2533
|
+
out[k] = forPreview ? masked : '__KEEP__';
|
|
2534
|
+
}
|
|
2535
|
+
const parsed = parseKvLines(cmHeadersText, ':');
|
|
2536
|
+
for (const [k, v] of Object.entries(parsed)) {
|
|
2537
|
+
out[k] = forPreview ? maskPreview(v) : v;
|
|
2538
|
+
}
|
|
2539
|
+
}
|
|
2540
|
+
return out;
|
|
2541
|
+
};
|
|
2542
|
+
const buildStdioEnv = (forPreview) => {
|
|
2543
|
+
const out = {};
|
|
2544
|
+
for (const [k, masked] of Object.entries(cmKeepEnv)) {
|
|
2545
|
+
out[k] = forPreview ? masked : '__KEEP__';
|
|
2546
|
+
}
|
|
2547
|
+
const parsed = parseKvLines(cmEnvText, '=');
|
|
2548
|
+
for (const [k, v] of Object.entries(parsed)) {
|
|
2549
|
+
out[k] = forPreview ? maskPreview(v) : v;
|
|
2550
|
+
}
|
|
2551
|
+
return out;
|
|
2552
|
+
};
|
|
2553
|
+
|
|
2554
|
+
const previewHeaders = buildHttpHeaders(true);
|
|
2555
|
+
const previewEnv = buildStdioEnv(true);
|
|
2556
|
+
const hasCredTpl =
|
|
2557
|
+
credRe.test(cmUrl) ||
|
|
2558
|
+
credRe.test(cmCommand) ||
|
|
2559
|
+
credRe.test(cmArgs) ||
|
|
2560
|
+
credRe.test(cmCwd) ||
|
|
2561
|
+
Object.values(previewHeaders).some((v) => credRe.test(String(v))) ||
|
|
2562
|
+
Object.values(previewEnv).some((v) => credRe.test(String(v)));
|
|
2563
|
+
|
|
2422
2564
|
const previewJson = JSON.stringify(
|
|
2423
2565
|
{
|
|
2424
2566
|
mcpServers: {
|
|
@@ -2428,24 +2570,31 @@ window.__ModuleLoader__.load({
|
|
|
2428
2570
|
transport: 'stdio',
|
|
2429
2571
|
command: cmCommand.trim() || 'npx',
|
|
2430
2572
|
...(cmArgs.trim() ? { args: cmArgs.trim().split(/\s+/) } : {}),
|
|
2573
|
+
...(Object.keys(previewEnv).length ? { env: previewEnv } : {}),
|
|
2431
2574
|
...(cmCwd.trim() ? { cwd: cmCwd.trim() } : {}),
|
|
2575
|
+
...(hasCredTpl ? { expandTemplates: true } : {}),
|
|
2432
2576
|
}
|
|
2433
2577
|
: {
|
|
2434
2578
|
transport: 'streamable-http',
|
|
2435
2579
|
url: cmUrl.trim() || 'https://example.com/mcp',
|
|
2580
|
+
...(Object.keys(previewHeaders).length ? { headers: previewHeaders } : {}),
|
|
2581
|
+
...(hasCredTpl ? { expandTemplates: true } : {}),
|
|
2436
2582
|
},
|
|
2437
2583
|
},
|
|
2438
2584
|
},
|
|
2439
2585
|
null,
|
|
2440
2586
|
2,
|
|
2441
2587
|
);
|
|
2588
|
+
const existingBearerKey = Object.keys(cmKeepHeaders).find((k) => /^authorization$/i.test(k));
|
|
2589
|
+
const existingApiKeyVal = cmKeepHeaders[cmApiKeyHeader.trim() || 'X-API-Key'];
|
|
2590
|
+
|
|
2442
2591
|
return h(
|
|
2443
2592
|
React.Fragment,
|
|
2444
2593
|
null,
|
|
2445
2594
|
h(
|
|
2446
2595
|
'div',
|
|
2447
2596
|
{ className: 'ch-drawer-head' },
|
|
2448
|
-
h('div', { className: 'ch-drawer-title' }, '连接自定义 MCP 服务'),
|
|
2597
|
+
h('div', { className: 'ch-drawer-title' }, cmEditing ? `编辑自定义 MCP · ${cmName}` : '连接自定义 MCP 服务'),
|
|
2449
2598
|
h('button', { type: 'button', className: 'ch-btn ch-btn-sm', onClick: () => setDrawer(null) }, '✕'),
|
|
2450
2599
|
),
|
|
2451
2600
|
h(
|
|
@@ -2459,6 +2608,7 @@ window.__ModuleLoader__.load({
|
|
|
2459
2608
|
className: 'ch-input ch-field-input ch-mono',
|
|
2460
2609
|
placeholder: '例如: github_mcp 或 local_sqlite',
|
|
2461
2610
|
value: cmName,
|
|
2611
|
+
disabled: cmEditing,
|
|
2462
2612
|
onChange: (e) => setCmName(e.target.value),
|
|
2463
2613
|
}),
|
|
2464
2614
|
),
|
|
@@ -2491,15 +2641,153 @@ window.__ModuleLoader__.load({
|
|
|
2491
2641
|
),
|
|
2492
2642
|
cmTransport === 'streamable-http'
|
|
2493
2643
|
? h(
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
h(
|
|
2497
|
-
|
|
2498
|
-
className: 'ch-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2644
|
+
React.Fragment,
|
|
2645
|
+
null,
|
|
2646
|
+
h(
|
|
2647
|
+
'div',
|
|
2648
|
+
{ className: 'ch-field' },
|
|
2649
|
+
h('label', { className: 'ch-label' }, 'MCP Endpoint URL'),
|
|
2650
|
+
h('input', {
|
|
2651
|
+
className: 'ch-input ch-field-input ch-mono',
|
|
2652
|
+
placeholder: 'https://mcp.example.com/mcp',
|
|
2653
|
+
value: cmUrl,
|
|
2654
|
+
onChange: (e) => setCmUrl(e.target.value),
|
|
2655
|
+
}),
|
|
2656
|
+
),
|
|
2657
|
+
h(
|
|
2658
|
+
'div',
|
|
2659
|
+
{ className: 'ch-field' },
|
|
2660
|
+
h('span', { className: 'ch-label' }, '鉴权方式 (Authentication)'),
|
|
2661
|
+
h(
|
|
2662
|
+
'div',
|
|
2663
|
+
{ className: 'ch-seg', style: { gridTemplateColumns: 'repeat(4, 1fr)' } },
|
|
2664
|
+
[
|
|
2665
|
+
['none', '无鉴权'],
|
|
2666
|
+
['bearer', 'Bearer'],
|
|
2667
|
+
['api-key', 'API Key'],
|
|
2668
|
+
['custom', '自定义'],
|
|
2669
|
+
].map(([k, label]) =>
|
|
2670
|
+
h(
|
|
2671
|
+
'button',
|
|
2672
|
+
{
|
|
2673
|
+
key: k,
|
|
2674
|
+
type: 'button',
|
|
2675
|
+
className: cmAuthType === k ? 'ch-seg-btn active' : 'ch-seg-btn',
|
|
2676
|
+
onClick: () => setCmAuthType(k),
|
|
2677
|
+
},
|
|
2678
|
+
label,
|
|
2679
|
+
),
|
|
2680
|
+
),
|
|
2681
|
+
),
|
|
2682
|
+
),
|
|
2683
|
+
cmAuthType === 'bearer'
|
|
2684
|
+
? h(
|
|
2685
|
+
'div',
|
|
2686
|
+
{ className: 'ch-field' },
|
|
2687
|
+
h(
|
|
2688
|
+
'div',
|
|
2689
|
+
{ style: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 8 } },
|
|
2690
|
+
h('label', { className: 'ch-label' }, 'Bearer Token'),
|
|
2691
|
+
h(
|
|
2692
|
+
'button',
|
|
2693
|
+
{ type: 'button', className: 'ch-btn ch-btn-sm', onClick: () => setCmShowSecret((v) => !v) },
|
|
2694
|
+
cmShowSecret ? '隐藏' : '显示',
|
|
2695
|
+
),
|
|
2696
|
+
),
|
|
2697
|
+
h('input', {
|
|
2698
|
+
type: cmShowSecret ? 'text' : 'password',
|
|
2699
|
+
className: 'ch-input ch-field-input ch-mono',
|
|
2700
|
+
placeholder: existingBearerKey
|
|
2701
|
+
? `已保存 (${cmKeepHeaders[existingBearerKey]}),留空保持不变`
|
|
2702
|
+
: 'sk-... 或 ${credential:MCP_TOKEN}',
|
|
2703
|
+
value: cmBearerToken,
|
|
2704
|
+
onChange: (e) => setCmBearerToken(e.target.value),
|
|
2705
|
+
}),
|
|
2706
|
+
h('div', { className: 'ch-muted', style: { fontSize: 12 } }, '将自动以 Authorization: Bearer <token> 发送,支持 DSH 凭据模板 ${credential:REF}。'),
|
|
2707
|
+
)
|
|
2708
|
+
: null,
|
|
2709
|
+
cmAuthType === 'api-key'
|
|
2710
|
+
? h(
|
|
2711
|
+
React.Fragment,
|
|
2712
|
+
null,
|
|
2713
|
+
h(
|
|
2714
|
+
'div',
|
|
2715
|
+
{ className: 'ch-field' },
|
|
2716
|
+
h('label', { className: 'ch-label' }, 'Header 名称'),
|
|
2717
|
+
h('input', {
|
|
2718
|
+
className: 'ch-input ch-field-input ch-mono',
|
|
2719
|
+
placeholder: 'X-API-Key',
|
|
2720
|
+
value: cmApiKeyHeader,
|
|
2721
|
+
onChange: (e) => setCmApiKeyHeader(e.target.value),
|
|
2722
|
+
}),
|
|
2723
|
+
),
|
|
2724
|
+
h(
|
|
2725
|
+
'div',
|
|
2726
|
+
{ className: 'ch-field' },
|
|
2727
|
+
h(
|
|
2728
|
+
'div',
|
|
2729
|
+
{ style: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 8 } },
|
|
2730
|
+
h('label', { className: 'ch-label' }, 'API Key 值'),
|
|
2731
|
+
h(
|
|
2732
|
+
'button',
|
|
2733
|
+
{ type: 'button', className: 'ch-btn ch-btn-sm', onClick: () => setCmShowSecret((v) => !v) },
|
|
2734
|
+
cmShowSecret ? '隐藏' : '显示',
|
|
2735
|
+
),
|
|
2736
|
+
),
|
|
2737
|
+
h('input', {
|
|
2738
|
+
type: cmShowSecret ? 'text' : 'password',
|
|
2739
|
+
className: 'ch-input ch-field-input ch-mono',
|
|
2740
|
+
placeholder: existingApiKeyVal
|
|
2741
|
+
? `已保存 (${existingApiKeyVal}),留空保持不变`
|
|
2742
|
+
: '输入 Key 或 ${credential:API_KEY}',
|
|
2743
|
+
value: cmApiKeyValue,
|
|
2744
|
+
onChange: (e) => setCmApiKeyValue(e.target.value),
|
|
2745
|
+
}),
|
|
2746
|
+
),
|
|
2747
|
+
)
|
|
2748
|
+
: null,
|
|
2749
|
+
cmAuthType === 'custom'
|
|
2750
|
+
? h(
|
|
2751
|
+
'div',
|
|
2752
|
+
{ className: 'ch-field' },
|
|
2753
|
+
h('label', { className: 'ch-label' }, '自定义 Headers(每行一条 Key: Value)'),
|
|
2754
|
+
Object.keys(cmKeepHeaders).length > 0
|
|
2755
|
+
? h(
|
|
2756
|
+
'div',
|
|
2757
|
+
{ style: { display: 'flex', flexWrap: 'wrap', gap: 6, marginBottom: 6 } },
|
|
2758
|
+
Object.entries(cmKeepHeaders).map(([k, masked]) =>
|
|
2759
|
+
h(
|
|
2760
|
+
'span',
|
|
2761
|
+
{ key: k, className: 'ch-pill ch-mono', style: { display: 'inline-flex', alignItems: 'center', gap: 6 } },
|
|
2762
|
+
`${k}: ${masked}`,
|
|
2763
|
+
h(
|
|
2764
|
+
'button',
|
|
2765
|
+
{
|
|
2766
|
+
type: 'button',
|
|
2767
|
+
style: { border: 'none', background: 'transparent', cursor: 'pointer', padding: 0, color: 'inherit' },
|
|
2768
|
+
title: '移除此 Header',
|
|
2769
|
+
onClick: () =>
|
|
2770
|
+
setCmKeepHeaders((prev) => {
|
|
2771
|
+
const next = { ...prev };
|
|
2772
|
+
delete next[k];
|
|
2773
|
+
return next;
|
|
2774
|
+
}),
|
|
2775
|
+
},
|
|
2776
|
+
'✕',
|
|
2777
|
+
),
|
|
2778
|
+
),
|
|
2779
|
+
),
|
|
2780
|
+
)
|
|
2781
|
+
: null,
|
|
2782
|
+
h('textarea', {
|
|
2783
|
+
className: 'ch-input ch-field-input ch-mono',
|
|
2784
|
+
rows: 3,
|
|
2785
|
+
placeholder: 'Authorization: Bearer ${credential:MCP_TOKEN}\nX-Tenant-Id: prod',
|
|
2786
|
+
value: cmHeadersText,
|
|
2787
|
+
onChange: (e) => setCmHeadersText(e.target.value),
|
|
2788
|
+
}),
|
|
2789
|
+
)
|
|
2790
|
+
: null,
|
|
2503
2791
|
)
|
|
2504
2792
|
: h(
|
|
2505
2793
|
React.Fragment,
|
|
@@ -2526,6 +2814,46 @@ window.__ModuleLoader__.load({
|
|
|
2526
2814
|
onChange: (e) => setCmArgs(e.target.value),
|
|
2527
2815
|
}),
|
|
2528
2816
|
),
|
|
2817
|
+
h(
|
|
2818
|
+
'div',
|
|
2819
|
+
{ className: 'ch-field' },
|
|
2820
|
+
h('label', { className: 'ch-label' }, '环境变量 / 鉴权凭据 (Env,每行 KEY=VALUE,可选)'),
|
|
2821
|
+
Object.keys(cmKeepEnv).length > 0
|
|
2822
|
+
? h(
|
|
2823
|
+
'div',
|
|
2824
|
+
{ style: { display: 'flex', flexWrap: 'wrap', gap: 6, marginBottom: 6 } },
|
|
2825
|
+
Object.entries(cmKeepEnv).map(([k, masked]) =>
|
|
2826
|
+
h(
|
|
2827
|
+
'span',
|
|
2828
|
+
{ key: k, className: 'ch-pill ch-mono', style: { display: 'inline-flex', alignItems: 'center', gap: 6 } },
|
|
2829
|
+
`${k}=${masked}`,
|
|
2830
|
+
h(
|
|
2831
|
+
'button',
|
|
2832
|
+
{
|
|
2833
|
+
type: 'button',
|
|
2834
|
+
style: { border: 'none', background: 'transparent', cursor: 'pointer', padding: 0, color: 'inherit' },
|
|
2835
|
+
title: '移除此环境变量',
|
|
2836
|
+
onClick: () =>
|
|
2837
|
+
setCmKeepEnv((prev) => {
|
|
2838
|
+
const next = { ...prev };
|
|
2839
|
+
delete next[k];
|
|
2840
|
+
return next;
|
|
2841
|
+
}),
|
|
2842
|
+
},
|
|
2843
|
+
'✕',
|
|
2844
|
+
),
|
|
2845
|
+
),
|
|
2846
|
+
),
|
|
2847
|
+
)
|
|
2848
|
+
: null,
|
|
2849
|
+
h('textarea', {
|
|
2850
|
+
className: 'ch-input ch-field-input ch-mono',
|
|
2851
|
+
rows: 3,
|
|
2852
|
+
placeholder: 'GITHUB_TOKEN=${credential:GITHUB_TOKEN}\nAPI_KEY=your-key',
|
|
2853
|
+
value: cmEnvText,
|
|
2854
|
+
onChange: (e) => setCmEnvText(e.target.value),
|
|
2855
|
+
}),
|
|
2856
|
+
),
|
|
2529
2857
|
h(
|
|
2530
2858
|
'div',
|
|
2531
2859
|
{ className: 'ch-field' },
|
|
@@ -2541,7 +2869,7 @@ window.__ModuleLoader__.load({
|
|
|
2541
2869
|
h(
|
|
2542
2870
|
'div',
|
|
2543
2871
|
{ className: 'ch-code-box' },
|
|
2544
|
-
h('div', { className: 'ch-code-head' }, h('span', null, '
|
|
2872
|
+
h('div', { className: 'ch-code-head' }, h('span', null, '底层配置实时预览(密钥已脱敏)')),
|
|
2545
2873
|
h('pre', { className: 'ch-pre' }, previewJson),
|
|
2546
2874
|
),
|
|
2547
2875
|
),
|
|
@@ -2556,19 +2884,23 @@ window.__ModuleLoader__.load({
|
|
|
2556
2884
|
className: 'ch-btn ch-btn-primary',
|
|
2557
2885
|
disabled: !cmName.trim(),
|
|
2558
2886
|
onClick: async () => {
|
|
2887
|
+
const headers = cmTransport === 'streamable-http' ? buildHttpHeaders(false) : {};
|
|
2888
|
+
const env = cmTransport === 'stdio' ? buildStdioEnv(false) : {};
|
|
2559
2889
|
const res = await runMutation({
|
|
2560
2890
|
action: 'save_custom_mcp',
|
|
2561
2891
|
serverName: cmName.trim(),
|
|
2562
2892
|
transport: cmTransport,
|
|
2563
2893
|
url: cmUrl.trim(),
|
|
2894
|
+
headers,
|
|
2564
2895
|
command: cmCommand.trim(),
|
|
2565
2896
|
argsText: cmArgs.trim(),
|
|
2897
|
+
env,
|
|
2566
2898
|
serverCwd: cmCwd.trim(),
|
|
2567
2899
|
});
|
|
2568
2900
|
if (res) setDrawer(null);
|
|
2569
2901
|
},
|
|
2570
2902
|
},
|
|
2571
|
-
'保存并立即挂载',
|
|
2903
|
+
cmEditing ? '保存并重新挂载' : '保存并立即挂载',
|
|
2572
2904
|
),
|
|
2573
2905
|
),
|
|
2574
2906
|
);
|
package/index.js
CHANGED
|
@@ -447,17 +447,73 @@ function parseRepoInstallArgs(input) {
|
|
|
447
447
|
return normalized.split(/\s+/).filter(Boolean);
|
|
448
448
|
}
|
|
449
449
|
|
|
450
|
-
|
|
450
|
+
const CREDENTIAL_TEMPLATE_RE = /\$\{credential:[^}]+\}/;
|
|
451
|
+
|
|
452
|
+
export function sanitizeKeyValueMap(raw) {
|
|
453
|
+
const out = {};
|
|
454
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return out;
|
|
455
|
+
for (const [k, v] of Object.entries(raw)) {
|
|
456
|
+
const key = String(k || '').trim();
|
|
457
|
+
if (!key || key === '__proto__' || key === 'constructor' || key === 'prototype') continue;
|
|
458
|
+
const val = v == null ? '' : String(v);
|
|
459
|
+
if (!val.trim()) continue;
|
|
460
|
+
out[key] = val;
|
|
461
|
+
}
|
|
462
|
+
return out;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
export function maskSecretValue(raw) {
|
|
466
|
+
const str = String(raw || '');
|
|
467
|
+
if (!str) return '';
|
|
468
|
+
if (CREDENTIAL_TEMPLATE_RE.test(str)) return str;
|
|
469
|
+
const bearerMatch = /^(Bearer\s+)(.+)$/i.exec(str);
|
|
470
|
+
if (bearerMatch) {
|
|
471
|
+
return `${bearerMatch[1]}${maskSecretValue(bearerMatch[2])}`;
|
|
472
|
+
}
|
|
473
|
+
if (str.length <= 8) return '****';
|
|
474
|
+
return `${str.slice(0, 4)}****${str.slice(-4)}`;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
export function maskKeyValueMap(raw) {
|
|
478
|
+
const clean = sanitizeKeyValueMap(raw);
|
|
479
|
+
const out = {};
|
|
480
|
+
for (const [k, v] of Object.entries(clean)) {
|
|
481
|
+
out[k] = maskSecretValue(v);
|
|
482
|
+
}
|
|
483
|
+
return out;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
export function hasCredentialTemplate(cfg) {
|
|
487
|
+
if (!cfg || typeof cfg !== 'object') return false;
|
|
488
|
+
const values = [
|
|
489
|
+
cfg.url,
|
|
490
|
+
cfg.command,
|
|
491
|
+
cfg.cwd,
|
|
492
|
+
...(Array.isArray(cfg.args) ? cfg.args : []),
|
|
493
|
+
...Object.values(cfg.headers && typeof cfg.headers === 'object' ? cfg.headers : {}),
|
|
494
|
+
...Object.values(cfg.env && typeof cfg.env === 'object' ? cfg.env : {}),
|
|
495
|
+
];
|
|
496
|
+
return values.some(v => typeof v === 'string' && CREDENTIAL_TEMPLATE_RE.test(v));
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
export function formatMcpJsonSnippet(srv) {
|
|
500
|
+
const maskedHeaders = maskKeyValueMap(srv.headers);
|
|
501
|
+
const maskedEnv = maskKeyValueMap(srv.env);
|
|
502
|
+
const expand = Boolean(srv.expandTemplates) || hasCredentialTemplate(srv);
|
|
451
503
|
const entry = srv.transport === 'stdio'
|
|
452
504
|
? {
|
|
453
505
|
transport: 'stdio',
|
|
454
506
|
command: srv.command || 'npx',
|
|
455
507
|
...(srv.args?.length ? { args: srv.args } : {}),
|
|
508
|
+
...(Object.keys(maskedEnv).length ? { env: maskedEnv } : {}),
|
|
456
509
|
...(srv.cwd ? { cwd: srv.cwd } : {}),
|
|
510
|
+
...(expand ? { expandTemplates: true } : {}),
|
|
457
511
|
}
|
|
458
512
|
: {
|
|
459
513
|
transport: 'streamable-http',
|
|
460
514
|
url: srv.url || 'https://example.com/mcp',
|
|
515
|
+
...(Object.keys(maskedHeaders).length ? { headers: maskedHeaders } : {}),
|
|
516
|
+
...(expand ? { expandTemplates: true } : {}),
|
|
461
517
|
};
|
|
462
518
|
return JSON.stringify({ mcpServers: { [srv.name]: entry } }, null, 2);
|
|
463
519
|
}
|
|
@@ -733,18 +789,21 @@ export function apply(ctx) {
|
|
|
733
789
|
if (!cfg || cfg.enabled === false || state.disabledServers?.[srv] === true) continue;
|
|
734
790
|
if (customMcpDisposers.has(srv)) continue;
|
|
735
791
|
try {
|
|
792
|
+
const expandTemplates = Boolean(cfg.expandTemplates) || hasCredentialTemplate(cfg);
|
|
736
793
|
const entry = cfg.transport === 'stdio'
|
|
737
794
|
? {
|
|
738
795
|
transport: 'stdio',
|
|
739
796
|
command: cfg.command || '',
|
|
740
797
|
args: Array.isArray(cfg.args) ? cfg.args : [],
|
|
741
|
-
env: cfg.env
|
|
798
|
+
env: sanitizeKeyValueMap(cfg.env),
|
|
742
799
|
cwd: cfg.cwd || '',
|
|
800
|
+
...(expandTemplates ? { expandTemplates: true } : {}),
|
|
743
801
|
}
|
|
744
802
|
: {
|
|
745
803
|
transport: 'streamable-http',
|
|
746
804
|
url: cfg.url || '',
|
|
747
|
-
headers: cfg.headers
|
|
805
|
+
headers: sanitizeKeyValueMap(cfg.headers),
|
|
806
|
+
...(expandTemplates ? { expandTemplates: true } : {}),
|
|
748
807
|
};
|
|
749
808
|
const off = mgr.register(srv, entry);
|
|
750
809
|
customMcpDisposers.set(srv, off);
|
|
@@ -875,6 +934,19 @@ export function apply(ctx) {
|
|
|
875
934
|
const command = customCfg?.command || managedCfg?.command || hint?.command || '';
|
|
876
935
|
const args = customCfg?.args || managedCfg?.args || [];
|
|
877
936
|
const srvCwd = customCfg?.cwd || managedCfg?.cwd || '';
|
|
937
|
+
const rawHeaders = customCfg?.headers || managedCfg?.headers || {};
|
|
938
|
+
const rawEnv = customCfg?.env || managedCfg?.env || {};
|
|
939
|
+
const maskedHeaders = maskKeyValueMap(rawHeaders);
|
|
940
|
+
const maskedEnv = maskKeyValueMap(rawEnv);
|
|
941
|
+
const hasAuth = Object.keys(maskedHeaders).length > 0 || Object.keys(maskedEnv).length > 0;
|
|
942
|
+
const expandTemplates = Boolean(customCfg?.expandTemplates || managedCfg?.expandTemplates) || hasCredentialTemplate({
|
|
943
|
+
url,
|
|
944
|
+
command,
|
|
945
|
+
args,
|
|
946
|
+
cwd: srvCwd,
|
|
947
|
+
headers: rawHeaders,
|
|
948
|
+
env: rawEnv,
|
|
949
|
+
});
|
|
878
950
|
const source = customCfg ? 'custom' : managedView?.configured ? 'settings' : 'bundle';
|
|
879
951
|
|
|
880
952
|
const srvRecord = {
|
|
@@ -885,6 +957,10 @@ export function apply(ctx) {
|
|
|
885
957
|
command,
|
|
886
958
|
args,
|
|
887
959
|
cwd: srvCwd,
|
|
960
|
+
headers: maskedHeaders,
|
|
961
|
+
env: maskedEnv,
|
|
962
|
+
hasAuth,
|
|
963
|
+
expandTemplates,
|
|
888
964
|
patchPath: hint?.patchPath || '',
|
|
889
965
|
enabled: eff.enabled,
|
|
890
966
|
disableReason: eff.reason,
|
|
@@ -1387,16 +1463,31 @@ export function apply(ctx) {
|
|
|
1387
1463
|
if (!SERVER_NAME_RE.test(serverName)) {
|
|
1388
1464
|
return { ok: false, error: 'MCP 服务名称仅支持字母、数字、下划线或连字符(1-32位)' };
|
|
1389
1465
|
}
|
|
1466
|
+
const prevCfg = state.customServers[serverName] || {};
|
|
1467
|
+
const resolveMapWithKeep = (incoming, prevMap) => {
|
|
1468
|
+
const clean = sanitizeKeyValueMap(incoming);
|
|
1469
|
+
const merged = {};
|
|
1470
|
+
for (const [k, v] of Object.entries(clean)) {
|
|
1471
|
+
if (v === '__KEEP__' && prevMap && typeof prevMap[k] === 'string') {
|
|
1472
|
+
merged[k] = prevMap[k];
|
|
1473
|
+
} else if (v !== '__KEEP__') {
|
|
1474
|
+
merged[k] = v;
|
|
1475
|
+
}
|
|
1476
|
+
}
|
|
1477
|
+
return merged;
|
|
1478
|
+
};
|
|
1390
1479
|
const transport = payload.transport === 'stdio' ? 'stdio' : 'streamable-http';
|
|
1391
1480
|
if (transport === 'streamable-http') {
|
|
1392
1481
|
const url = String(payload.url || '').trim();
|
|
1393
1482
|
if (!/^https?:\/\//i.test(url)) {
|
|
1394
1483
|
return { ok: false, error: 'Streamable HTTP 需要有效的 http(s):// 地址' };
|
|
1395
1484
|
}
|
|
1485
|
+
const headers = resolveMapWithKeep(payload.headers, prevCfg.headers);
|
|
1396
1486
|
state.customServers[serverName] = {
|
|
1397
1487
|
transport: 'streamable-http',
|
|
1398
1488
|
url,
|
|
1399
|
-
headers
|
|
1489
|
+
headers,
|
|
1490
|
+
expandTemplates: Boolean(payload.expandTemplates) || hasCredentialTemplate({ url, headers }),
|
|
1400
1491
|
enabled: payload.enabled !== false,
|
|
1401
1492
|
};
|
|
1402
1493
|
} else {
|
|
@@ -1407,12 +1498,15 @@ export function apply(ctx) {
|
|
|
1407
1498
|
: String(payload.argsText || '').trim()
|
|
1408
1499
|
? String(payload.argsText).trim().split(/\s+/)
|
|
1409
1500
|
: [];
|
|
1501
|
+
const env = resolveMapWithKeep(payload.env, prevCfg.env);
|
|
1502
|
+
const serverCwd = String(payload.serverCwd || '').trim();
|
|
1410
1503
|
state.customServers[serverName] = {
|
|
1411
1504
|
transport: 'stdio',
|
|
1412
1505
|
command,
|
|
1413
1506
|
args,
|
|
1414
|
-
env
|
|
1415
|
-
cwd:
|
|
1507
|
+
env,
|
|
1508
|
+
cwd: serverCwd,
|
|
1509
|
+
expandTemplates: Boolean(payload.expandTemplates) || hasCredentialTemplate({ command, args, env, cwd: serverCwd }),
|
|
1416
1510
|
enabled: payload.enabled !== false,
|
|
1417
1511
|
};
|
|
1418
1512
|
}
|
|
@@ -1587,8 +1681,17 @@ export function apply(ctx) {
|
|
|
1587
1681
|
toolName: { type: 'string', description: 'Full MCP tool name (mcp__<server>__<tool>) for toggle_mcp_tool.' },
|
|
1588
1682
|
transport: { type: 'string', enum: ['streamable-http', 'stdio'], description: 'Transport for save_custom_mcp.' },
|
|
1589
1683
|
url: { type: 'string', description: 'Endpoint URL for streamable-http save_custom_mcp.' },
|
|
1684
|
+
headers: {
|
|
1685
|
+
type: 'object',
|
|
1686
|
+
description: 'Optional HTTP request headers for streamable-http authentication (e.g. {"Authorization": "Bearer ${credential:MCP_TOKEN}"}).',
|
|
1687
|
+
},
|
|
1590
1688
|
command: { type: 'string', description: 'Executable command for stdio save_custom_mcp.' },
|
|
1591
1689
|
args: { type: 'array', items: { type: 'string' }, description: 'Command arguments for stdio save_custom_mcp.' },
|
|
1690
|
+
env: {
|
|
1691
|
+
type: 'object',
|
|
1692
|
+
description: 'Optional environment variables for stdio authentication (e.g. {"GITHUB_TOKEN": "${credential:GITHUB_TOKEN}"}).',
|
|
1693
|
+
},
|
|
1694
|
+
serverCwd: { type: 'string', description: 'Optional working directory for stdio save_custom_mcp.' },
|
|
1592
1695
|
},
|
|
1593
1696
|
},
|
|
1594
1697
|
output: {
|
package/package.json
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fengguanghuai/dsh-capability-hub",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Codex-style unified capability hub for managing MCP servers, tools, skills, and switchable capability bundles in the top-left sidebar.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"dsh-plugin",
|
|
7
|
+
"deepseek-harness",
|
|
8
|
+
"mcp",
|
|
9
|
+
"skills",
|
|
10
|
+
"capability-hub"
|
|
11
|
+
],
|
|
5
12
|
"license": "MIT",
|
|
6
13
|
"author": "fengguanghuai",
|
|
14
|
+
"engines": {
|
|
15
|
+
"dsh": ">=0.2.0-0"
|
|
16
|
+
},
|
|
7
17
|
"repository": {
|
|
8
18
|
"type": "git",
|
|
9
19
|
"url": "git+https://github.com/fengguanghuai/dsh-capability-hub.git"
|
|
@@ -25,6 +35,8 @@
|
|
|
25
35
|
"cordis.patch.yml",
|
|
26
36
|
"locale/*.json",
|
|
27
37
|
"README.md",
|
|
38
|
+
"README.zh-CN.md",
|
|
39
|
+
"LICENSE",
|
|
28
40
|
"icon.svg"
|
|
29
41
|
],
|
|
30
42
|
"dsh": {
|