dsh-mcp-ops 0.2.1 → 0.3.0
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/README.md +39 -12
- package/lib/client.js +282 -145
- package/lib/configs.js +21 -8
- package/lib/host-locales.js +2 -20
- package/lib/index.js +7 -1
- package/lib/mount.js +353 -146
- package/lib/oauth-key.js +21 -0
- package/lib/probe.js +38 -43
- package/lib/refs.js +0 -34
- package/lib/service.js +113 -216
- package/lib/sources/cordis-source.js +38 -17
- package/lib/system-ca.js +79 -0
- package/lib/tool-control.js +91 -271
- package/package.json +14 -15
- package/lib/oauth-web.js +0 -119
- package/lib/oauth.js +0 -228
package/lib/configs.js
CHANGED
|
@@ -2,8 +2,12 @@ import { z } from "zod";
|
|
|
2
2
|
const CONFIGS_KEY = "configs";
|
|
3
3
|
const OVERLAY_KEY_SEPARATOR = "\0";
|
|
4
4
|
const overlaySchema = z.object({
|
|
5
|
-
/** 显式 OAuth 开关(缺省 false)。 */
|
|
5
|
+
/** 显式 OAuth 开关(缺省 false)。true 时注册项带 `oauth.credentialKey`,授权由官方承担。 */
|
|
6
6
|
oauth: z.boolean().optional(),
|
|
7
|
+
/** OAuth `scope` 覆盖(缺省交给官方:按服务器的 challenge 决定)。 */
|
|
8
|
+
oauthScope: z.string().optional(),
|
|
9
|
+
/** OAuth 预注册 client id(缺省交给官方:动态客户端注册)。 */
|
|
10
|
+
oauthClientId: z.string().optional(),
|
|
7
11
|
/** 文件未给出 `timeout` 时的覆盖;文件给了则以文件为准。 */
|
|
8
12
|
toolCallTimeoutMs: z.number().optional(),
|
|
9
13
|
/** 用户在本插件里强制启停(覆盖文件的 `disabled`)。 */
|
|
@@ -26,7 +30,7 @@ const globalEnvSchema = z.object({
|
|
|
26
30
|
value: z.string()
|
|
27
31
|
});
|
|
28
32
|
const DEFAULT_CONFIGS = {
|
|
29
|
-
injectionMode: "
|
|
33
|
+
injectionMode: "eager",
|
|
30
34
|
injectGlobalEnvToStdio: true,
|
|
31
35
|
overlays: {},
|
|
32
36
|
tool_switches: {},
|
|
@@ -37,7 +41,7 @@ function overlayKey(serverName) {
|
|
|
37
41
|
}
|
|
38
42
|
function isBlankOverlay(record) {
|
|
39
43
|
if (record === void 0) return true;
|
|
40
|
-
return record.oauth === void 0 && record.toolCallTimeoutMs === void 0 && record.enabledOverride === void 0 && record.injectGlobalEnv === void 0;
|
|
44
|
+
return record.oauth === void 0 && record.oauthScope === void 0 && record.oauthClientId === void 0 && record.toolCallTimeoutMs === void 0 && record.enabledOverride === void 0 && record.injectGlobalEnv === void 0;
|
|
41
45
|
}
|
|
42
46
|
function normalizeOverlayKey(key) {
|
|
43
47
|
const index = key.lastIndexOf(OVERLAY_KEY_SEPARATOR);
|
|
@@ -52,6 +56,12 @@ function configDiagnostic(detail, path) {
|
|
|
52
56
|
messageKey: "diagnostics.CONFIGS_INVALID"
|
|
53
57
|
};
|
|
54
58
|
}
|
|
59
|
+
function normalizeInjectionMode(raw) {
|
|
60
|
+
if (raw === "on-demand" || raw === "eager") return raw;
|
|
61
|
+
if (raw === "search") return "eager";
|
|
62
|
+
if (raw === "full") return "eager";
|
|
63
|
+
return void 0;
|
|
64
|
+
}
|
|
55
65
|
function normalizeConfigs(raw, path) {
|
|
56
66
|
const diagnostics = [];
|
|
57
67
|
if (raw === void 0 || raw === null) return { configs: DEFAULT_CONFIGS, diagnostics };
|
|
@@ -79,15 +89,16 @@ function normalizeConfigs(raw, path) {
|
|
|
79
89
|
}
|
|
80
90
|
return out;
|
|
81
91
|
};
|
|
82
|
-
|
|
83
|
-
if (record.injectionMode
|
|
84
|
-
|
|
92
|
+
const injectionMode = normalizeInjectionMode(record.injectionMode);
|
|
93
|
+
if (record.injectionMode !== void 0 && injectionMode === void 0) {
|
|
94
|
+
diagnostics.push(configDiagnostic("injectionMode", path));
|
|
95
|
+
}
|
|
85
96
|
let injectGlobalEnvToStdio = DEFAULT_CONFIGS.injectGlobalEnvToStdio;
|
|
86
97
|
if (typeof record.injectGlobalEnvToStdio === "boolean") injectGlobalEnvToStdio = record.injectGlobalEnvToStdio;
|
|
87
98
|
else if (record.injectGlobalEnvToStdio !== void 0) diagnostics.push(configDiagnostic("injectGlobalEnvToStdio", path));
|
|
88
99
|
return {
|
|
89
100
|
configs: {
|
|
90
|
-
injectionMode,
|
|
101
|
+
injectionMode: injectionMode ?? DEFAULT_CONFIGS.injectionMode,
|
|
91
102
|
injectGlobalEnvToStdio,
|
|
92
103
|
overlays: table("overlays", overlaySchema),
|
|
93
104
|
tool_switches: table("tool_switches", toolSwitchSchema),
|
|
@@ -119,7 +130,8 @@ function configsFromDomainSnapshot(snapshot) {
|
|
|
119
130
|
if (one.success) env[key] = one.data;
|
|
120
131
|
}
|
|
121
132
|
return {
|
|
122
|
-
|
|
133
|
+
// 旧域文件里同样可能是历史值(`search` / `full`):先按新值域归一。
|
|
134
|
+
injectionMode: normalizeInjectionMode(global.injectionMode) ?? DEFAULT_CONFIGS.injectionMode,
|
|
123
135
|
injectGlobalEnvToStdio: global.injectGlobalEnvToStdio !== false,
|
|
124
136
|
overlays,
|
|
125
137
|
tool_switches: switches,
|
|
@@ -138,6 +150,7 @@ export {
|
|
|
138
150
|
isBlankOverlay,
|
|
139
151
|
isDefaultConfigs,
|
|
140
152
|
normalizeConfigs,
|
|
153
|
+
normalizeInjectionMode,
|
|
141
154
|
normalizeOverlayKey,
|
|
142
155
|
overlayKey,
|
|
143
156
|
overlaySchema,
|
package/lib/host-locales.js
CHANGED
|
@@ -1,27 +1,9 @@
|
|
|
1
1
|
const zh = {
|
|
2
|
-
// `mcp_tool_search` 的模型可见文案。
|
|
3
|
-
toolSearchDesc: "\u6309\u5173\u952E\u8BCD\u68C0\u7D22\u5F53\u524D\u542F\u7528\u7684 MCP \u5DE5\u5177\uFF0C\u8FD4\u56DE\u5339\u914D\u5DE5\u5177\u7684\u540D\u79F0/\u63CF\u8FF0/\u53C2\u6570 schema\uFF0C\u5E76\u628A\u547D\u4E2D\u7684\u5DE5\u5177\u52A0\u5165\u70ED\u6CE8\u5165\u96C6\uFF08\u4E0B\u4E00\u8F6E\u6A21\u578B\u8BF7\u6C42\u5373\u53EF\u76F4\u63A5\u8C03\u7528\uFF09\u3002\u9700\u8981\u67D0\u4E2A MCP \u5DE5\u5177\u4F46\u4E0D\u77E5\u9053\u786E\u5207\u540D\u79F0\u65F6\u4F7F\u7528\u3002",
|
|
4
|
-
toolSearchQuery: "\u68C0\u7D22\u5173\u952E\u8BCD\uFF0C\u5982 gitlab merge request\u3001feishu \u6587\u6863\u3001hive \u8868\u7B49",
|
|
5
|
-
toolSearchLimit: "\u6700\u591A\u8FD4\u56DE\u6761\u6570\uFF0C\u9ED8\u8BA4 8\uFF0C\u6700\u5927 20",
|
|
6
|
-
searchHit: "\u5339\u914D MCP \u5DE5\u5177\uFF08\u5DF2\u70ED\u542F\u7528\uFF0C\u4E0B\u4E00\u8F6E\u53EF\u76F4\u63A5\u8C03\u7528\uFF09\uFF1A\n{lines}",
|
|
7
|
-
searchMiss: "\u672A\u627E\u5230\u5339\u914D\u7684 MCP \u5DE5\u5177\uFF0C\u53EF\u6362\u5173\u952E\u8BCD\u91CD\u8BD5\u3002",
|
|
8
|
-
searchDisabled: "\u6CA1\u6709\u53EF\u68C0\u7D22\u7684 MCP \u5DE5\u5177\uFF08\u670D\u52A1\u5668\u672A\u8FDE\u63A5\uFF0C\u6216\u5DE5\u5177\u5DF2\u88AB\u9010\u4E2A\u5173\u95ED\uFF09\u3002",
|
|
9
2
|
// 调用侧守卫的拒绝理由(B61)—— 这串文本会**原样进模型可见的错误**,所以说清"它存在但被关了"。
|
|
10
|
-
toolDisabled: "\u5DE5\u5177 {name} \u5DF2\u88AB\u7528\u6237\u5173\u95ED\uFF0C\u65E0\u6CD5\u8C03\u7528\uFF1B\u8BF7\u8BA9\u7528\u6237\u5728\u300C\u8BBE\u7F6E \u2192 MCP \u670D\u52A1\u300D\u91CC\u542F\u7528\u5B83\u3002"
|
|
11
|
-
// 注入的提示词段落。
|
|
12
|
-
toolControlPrompt: "MCP \u5DE5\u5177\u6309\u9700\u53EF\u7528\uFF1A\u9700\u8981\u67D0\u4E2A MCP \u5DE5\u5177\u65F6\u5148\u8C03\u7528 mcp_tool_search(query) \u68C0\u7D22\uFF0C\u547D\u4E2D\u540E\u8BE5\u5DE5\u5177\u4F1A\u81EA\u52A8\u6CE8\u5165\u5F53\u524D\u5BF9\u8BDD\uFF1B\u5F53\u524D\u53EF\u7528 MCP \u670D\u52A1\u5668\uFF1A{servers}\u3002",
|
|
13
|
-
noServers: "\uFF08\u65E0\uFF09"
|
|
3
|
+
toolDisabled: "\u5DE5\u5177 {name} \u5DF2\u88AB\u7528\u6237\u5173\u95ED\uFF0C\u65E0\u6CD5\u8C03\u7528\uFF1B\u8BF7\u8BA9\u7528\u6237\u5728\u300C\u8BBE\u7F6E \u2192 MCP \u670D\u52A1\u300D\u91CC\u542F\u7528\u5B83\u3002"
|
|
14
4
|
};
|
|
15
5
|
const en = {
|
|
16
|
-
|
|
17
|
-
toolSearchQuery: "Search keywords, e.g. gitlab merge request, feishu document, hive table",
|
|
18
|
-
toolSearchLimit: "Maximum number of results; default 8, max 20",
|
|
19
|
-
searchHit: "Matching MCP tools (hot-enabled, callable in the next request):\n{lines}",
|
|
20
|
-
searchMiss: "No matching MCP tools found; try different keywords.",
|
|
21
|
-
searchDisabled: "No MCP tools to search (no server connected, or every tool is switched off).",
|
|
22
|
-
toolDisabled: "The tool {name} is switched off by the user and cannot be called; ask the user to enable it in Settings \u2192 MCP servers.",
|
|
23
|
-
toolControlPrompt: "MCP tools are available on demand: when you need an MCP tool, first call mcp_tool_search(query); a hit is hot-injected into the current conversation. Enabled MCP servers: {servers}.",
|
|
24
|
-
noServers: "(none)"
|
|
6
|
+
toolDisabled: "The tool {name} is switched off by the user and cannot be called; ask the user to enable it in Settings \u2192 MCP servers."
|
|
25
7
|
};
|
|
26
8
|
const HOST_LOCALE_KEYS = Object.keys(zh);
|
|
27
9
|
function renderHostText(template, vars) {
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import Schema from "@deepseek-ai/schemastery";
|
|
2
2
|
import { McpOpsService } from "./service.js";
|
|
3
|
+
import { ensureSystemCaTrust } from "./system-ca.js";
|
|
3
4
|
const name = "mcp-ops";
|
|
4
|
-
const inject = ["credentials", "tools"];
|
|
5
|
+
const inject = ["credentials", "tools", "mcpManager"];
|
|
5
6
|
const Config = Schema.object({
|
|
6
7
|
injectGlobalEnvToStdio: Schema.boolean().default(true),
|
|
7
8
|
remoteTypeSpelling: Schema.union([
|
|
@@ -14,6 +15,11 @@ function apply(ctx, config) {
|
|
|
14
15
|
const banner = `dsh-mcp-ops: host half loaded \u2014 injectGlobalEnvToStdio=${String(config.injectGlobalEnvToStdio)}, remoteTypeSpelling=${config.remoteTypeSpelling}`;
|
|
15
16
|
if (process.env.DSH_MCP_OPS_DEBUG !== void 0) process.stderr.write(`${banner}
|
|
16
17
|
`);
|
|
18
|
+
const trust = ensureSystemCaTrust();
|
|
19
|
+
if (process.env.DSH_MCP_OPS_DEBUG !== void 0) {
|
|
20
|
+
process.stderr.write(`dsh-mcp-ops: system CA \u2014 applied=${String(trust.applied)} added=${String(trust.added)} system=${String(trust.system)}${trust.reason === void 0 ? "" : ` reason=${trust.reason}`}
|
|
21
|
+
`);
|
|
22
|
+
}
|
|
17
23
|
ctx.inject(["logger"], (loggerCtx) => {
|
|
18
24
|
loggerCtx.logger.info(banner);
|
|
19
25
|
});
|