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
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from "node:fs";
|
|
2
2
|
import { dirname, join } from "node:path";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
|
-
import
|
|
5
|
-
import { applyEntryPatches, entryListSchema } from "@deepseek-ai/cordis-plugin-include";
|
|
4
|
+
import { applyEntryPatches, parseEntryYaml } from "@deepseek-ai/cordis-plugin-include";
|
|
6
5
|
import { diagnostic } from "../files/mcp-json.js";
|
|
7
6
|
import { readManagedRowIds } from "../files/patch-writer.js";
|
|
8
7
|
const MCP_CLIENT_PACKAGE = "@deepseek-ai/dsh-mcp-client";
|
|
8
|
+
const MCP_MANAGER_PACKAGE = "@deepseek-ai/dsh-mcp-manager";
|
|
9
9
|
const OWN_PACKAGE = "dsh-mcp-ops";
|
|
10
10
|
const PROFILE_PATCH_FILENAME = "cordis.patch.yml";
|
|
11
11
|
function ownPackageRoot() {
|
|
@@ -21,7 +21,7 @@ function readLayer(path, kind, io) {
|
|
|
21
21
|
}
|
|
22
22
|
let parsed;
|
|
23
23
|
try {
|
|
24
|
-
parsed =
|
|
24
|
+
parsed = parseEntryYaml(text);
|
|
25
25
|
} catch (error) {
|
|
26
26
|
return { path, kind, exists: true, readable: true, parseError: error instanceof Error ? error.message : String(error), patches: [], rows: [] };
|
|
27
27
|
}
|
|
@@ -89,7 +89,7 @@ function scanCordisComposition(options) {
|
|
|
89
89
|
}
|
|
90
90
|
const flat = layers.flatMap((layer) => layer.patches);
|
|
91
91
|
const effectiveRaw = applyEntryPatches([], structuredClone(flat), () => {
|
|
92
|
-
});
|
|
92
|
+
}).data;
|
|
93
93
|
const effective = effectiveRaw.map((entry) => {
|
|
94
94
|
const row = rowOf(entry, true, "");
|
|
95
95
|
return { ...row, path: pathOfDeclaration(layers, row) };
|
|
@@ -152,17 +152,37 @@ function declarationsOf(effective, managed) {
|
|
|
152
152
|
const managedIds = new Set(managed.flatMap((entry) => entry.rowIds));
|
|
153
153
|
const declarations = [];
|
|
154
154
|
for (const row of effective) {
|
|
155
|
-
if (row.name
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
155
|
+
if (row.name === MCP_CLIENT_PACKAGE) {
|
|
156
|
+
if (row.serverName === void 0) continue;
|
|
157
|
+
declarations.push({
|
|
158
|
+
serverName: row.serverName,
|
|
159
|
+
...row.id === void 0 ? {} : { rowId: row.id },
|
|
160
|
+
...row.config === void 0 ? {} : { config: row.config },
|
|
161
|
+
path: row.path,
|
|
162
|
+
disabled: row.disabled === true,
|
|
163
|
+
hasJsExpr: row.hasJsExpr,
|
|
164
|
+
managed: row.id !== void 0 && managedIds.has(row.id)
|
|
165
|
+
});
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
if (row.name !== MCP_MANAGER_PACKAGE) continue;
|
|
169
|
+
if (row.config === null || typeof row.config !== "object") continue;
|
|
170
|
+
const servers = row.config.servers;
|
|
171
|
+
if (servers === null || typeof servers !== "object") continue;
|
|
172
|
+
for (const [serverName, entry] of Object.entries(servers)) {
|
|
173
|
+
if (entry === null || typeof entry !== "object") continue;
|
|
174
|
+
declarations.push({
|
|
175
|
+
serverName,
|
|
176
|
+
...row.id === void 0 ? {} : { rowId: row.id },
|
|
177
|
+
// 合成一条与 mcp-client 同形的 config,让视图能显示 transport/url/command。
|
|
178
|
+
config: { serverName, ...entry },
|
|
179
|
+
path: row.path,
|
|
180
|
+
disabled: row.disabled === true,
|
|
181
|
+
hasJsExpr: row.hasJsExpr || containsJsExpr(entry),
|
|
182
|
+
managed: false,
|
|
183
|
+
adoptable: false
|
|
184
|
+
});
|
|
185
|
+
}
|
|
166
186
|
}
|
|
167
187
|
return declarations;
|
|
168
188
|
}
|
|
@@ -174,7 +194,7 @@ function cordisSourceResults(scan, locations) {
|
|
|
174
194
|
const capabilities = {};
|
|
175
195
|
for (const entry of mine) {
|
|
176
196
|
capabilities[entry.serverName] = {
|
|
177
|
-
adoptable: entry.rowId !== void 0 && !entry.hasJsExpr && !entry.managed,
|
|
197
|
+
adoptable: entry.adoptable !== false && entry.rowId !== void 0 && !entry.hasJsExpr && !entry.managed,
|
|
178
198
|
adopted: entry.managed && entry.disabled
|
|
179
199
|
};
|
|
180
200
|
}
|
|
@@ -215,7 +235,7 @@ function specFromCordisConfig(declaration) {
|
|
|
215
235
|
return out;
|
|
216
236
|
};
|
|
217
237
|
const timeout = typeof record.toolCallTimeoutMs === "number" ? record.toolCallTimeoutMs : void 0;
|
|
218
|
-
const known = /* @__PURE__ */ new Set(["transport", "serverName", "command", "args", "cwd", "env", "url", "headers", "toolCallTimeoutMs"]);
|
|
238
|
+
const known = /* @__PURE__ */ new Set(["transport", "serverName", "command", "args", "cwd", "env", "url", "headers", "toolCallTimeoutMs", "startupTimeoutMs", "closeTimeoutMs", "reconnect", "enabled"]);
|
|
219
239
|
const extraKeys = Object.keys(record).filter((key) => !known.has(key));
|
|
220
240
|
return {
|
|
221
241
|
serverName: declaration.serverName,
|
|
@@ -235,6 +255,7 @@ function specFromCordisConfig(declaration) {
|
|
|
235
255
|
}
|
|
236
256
|
export {
|
|
237
257
|
MCP_CLIENT_PACKAGE,
|
|
258
|
+
MCP_MANAGER_PACKAGE,
|
|
238
259
|
OWN_PACKAGE,
|
|
239
260
|
PROFILE_PATCH_FILENAME,
|
|
240
261
|
containsJsExpr,
|
package/lib/system-ca.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import tls from "node:tls";
|
|
3
|
+
const OS_CA_FILES = [
|
|
4
|
+
"/etc/ssl/cert.pem",
|
|
5
|
+
"/etc/ssl/certs/ca-certificates.crt",
|
|
6
|
+
"/etc/pki/tls/certs/ca-bundle.crt",
|
|
7
|
+
"/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem"
|
|
8
|
+
];
|
|
9
|
+
function splitPem(text) {
|
|
10
|
+
return text.match(/-----BEGIN CERTIFICATE-----[\s\S]*?-----END CERTIFICATE-----/g) ?? [];
|
|
11
|
+
}
|
|
12
|
+
function systemCaCertificates() {
|
|
13
|
+
const certificates = [];
|
|
14
|
+
if (typeof tls.getCACertificates === "function") {
|
|
15
|
+
try {
|
|
16
|
+
certificates.push(...tls.getCACertificates("system") ?? []);
|
|
17
|
+
} catch {
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
for (const file of OS_CA_FILES) {
|
|
21
|
+
try {
|
|
22
|
+
certificates.push(...splitPem(readFileSync(file, "utf8")));
|
|
23
|
+
} catch {
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return [...new Set(certificates)];
|
|
27
|
+
}
|
|
28
|
+
let trustState;
|
|
29
|
+
function ensureSystemCaTrust(options = {}) {
|
|
30
|
+
if (trustState !== void 0 && options.refresh !== true) return trustState;
|
|
31
|
+
const canSetDefault = typeof tls.getCACertificates === "function" && typeof tls.setDefaultCACertificates === "function";
|
|
32
|
+
if (!canSetDefault) {
|
|
33
|
+
trustState = { applied: false, added: 0, system: 0, reason: "node-api-unavailable" };
|
|
34
|
+
return trustState;
|
|
35
|
+
}
|
|
36
|
+
let defaults;
|
|
37
|
+
try {
|
|
38
|
+
defaults = tls.getCACertificates("default") ?? [];
|
|
39
|
+
} catch {
|
|
40
|
+
trustState = { applied: false, added: 0, system: 0, reason: "default-store-unreadable" };
|
|
41
|
+
return trustState;
|
|
42
|
+
}
|
|
43
|
+
let system;
|
|
44
|
+
try {
|
|
45
|
+
system = options.systemCertificates ?? systemCaCertificates();
|
|
46
|
+
} catch {
|
|
47
|
+
system = [];
|
|
48
|
+
}
|
|
49
|
+
if (system.length === 0) {
|
|
50
|
+
trustState = { applied: false, added: 0, system: 0, reason: "no-system-ca" };
|
|
51
|
+
return trustState;
|
|
52
|
+
}
|
|
53
|
+
const merged = [.../* @__PURE__ */ new Set([...defaults, ...system])];
|
|
54
|
+
if (merged.length === defaults.length) {
|
|
55
|
+
trustState = { applied: false, added: 0, system: system.length, reason: "already-trusted" };
|
|
56
|
+
return trustState;
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
tls.setDefaultCACertificates(merged);
|
|
60
|
+
} catch {
|
|
61
|
+
trustState = { applied: false, added: 0, system: system.length, reason: "set-failed" };
|
|
62
|
+
return trustState;
|
|
63
|
+
}
|
|
64
|
+
trustState = { applied: true, added: merged.length - defaults.length, system: system.length };
|
|
65
|
+
return trustState;
|
|
66
|
+
}
|
|
67
|
+
function systemFetch() {
|
|
68
|
+
ensureSystemCaTrust();
|
|
69
|
+
return fetch;
|
|
70
|
+
}
|
|
71
|
+
function resetSystemCaTrustState() {
|
|
72
|
+
trustState = void 0;
|
|
73
|
+
}
|
|
74
|
+
export {
|
|
75
|
+
ensureSystemCaTrust,
|
|
76
|
+
resetSystemCaTrustState,
|
|
77
|
+
systemCaCertificates,
|
|
78
|
+
systemFetch
|
|
79
|
+
};
|