dsh-mcp-ops 0.2.2 → 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/lib/service.js CHANGED
@@ -46,7 +46,7 @@ var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use
46
46
  var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
47
47
  var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
48
48
  var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
49
- var _oauthStart_dec, _envSet_dec, _envInject_dec, _envList_dec, _jsonWrite_dec, _jsonRead_dec, _test_dec, _setEnabled_dec, _removeServer_dec, _refreshServer_dec, _upsert_dec, _release_dec, _adopt_dec, _toolsMode_dec, _toolsSet_dec, _toolsList_dec, _refresh_dec, _list_dec, _a, _init;
49
+ var _oauthSignOut_dec, _oauthCancel_dec, _oauthStart_dec, _envSet_dec, _envInject_dec, _envList_dec, _jsonWrite_dec, _jsonRead_dec, _test_dec, _setEnabled_dec, _removeServer_dec, _refreshServer_dec, _upsert_dec, _release_dec, _adopt_dec, _toolsMode_dec, _toolsSet_dec, _toolsList_dec, _refresh_dec, _list_dec, _a, _init;
50
50
  import { Remote, TypertRemoteService } from "@deepseek-ai/dsh-typert-protocol";
51
51
  import { existsSync, mkdirSync, readFileSync, renameSync } from "node:fs";
52
52
  import { dirname, join } from "node:path";
@@ -55,19 +55,8 @@ import { createScope } from "@deepseek-ai/dsh-scope";
55
55
  import { normalizeEntry, serverEntries } from "./files/mcp-json.js";
56
56
  import { defaultWriteTarget } from "./files/locations.js";
57
57
  import { effectiveRow } from "./models.js";
58
- import { oauthAccessRef, oauthRef, serverEnvRefPrefix, serverRef } from "./refs.js";
58
+ import { serverEnvRefPrefix, serverRef } from "./refs.js";
59
59
  import { credentialsDocumentPath, groupServerEnvNames, readCredentialRefNames, serverEnvNamesOf } from "./credentials-doc.js";
60
- import {
61
- awaitLoopbackCallback,
62
- buildAuthorizationUrl,
63
- createPkcePair,
64
- createState,
65
- discoverMetadata,
66
- exchangeCode,
67
- parseClient,
68
- serializeClient
69
- } from "./oauth.js";
70
- import { WEB_CALLBACK_PATH, awaitWebCallback, handleWebCallback, sanitizeOrigin, webCallbackUri } from "./oauth-web.js";
71
60
  import { checkServerName } from "./models.js";
72
61
  import {
73
62
  FileChangedError,
@@ -87,10 +76,8 @@ import { readManagedBlock, writeManagedBlock } from "./files/patch-writer.js";
87
76
  import { createDocumentText, removeEntry, setEntryEnabled, setTopLevelKey, upsertEntry } from "./files/writer.js";
88
77
  import { errorText } from "./error-text.js";
89
78
  import { MountManager } from "./mount.js";
90
- import { clearToken, writeToken } from "./oauth-store.js";
91
- import { systemFetch } from "./system-ca.js";
92
79
  import { globalRef } from "./refs.js";
93
- import { canHoldCredentialRef, legacySecretRef, legacyServerRef, resolveOAuthRef, resolveServerRef } from "./refs.js";
80
+ import { canHoldCredentialRef, legacySecretRef, legacyServerRef, resolveServerRef } from "./refs.js";
94
81
  import { cordisSourceResults, scanCordisComposition, specFromCordisConfig } from "./sources/cordis-source.js";
95
82
  import { buildSnapshot, readFileSources } from "./sources/registry.js";
96
83
  import {
@@ -125,7 +112,7 @@ function sameConnectionSpec(a, b) {
125
112
  });
126
113
  return canonicalJson(pick(a)) === canonicalJson(pick(b));
127
114
  }
128
- class McpOpsService extends (_a = TypertRemoteService, _list_dec = [Remote], _refresh_dec = [Remote], _toolsList_dec = [Remote], _toolsSet_dec = [Remote], _toolsMode_dec = [Remote], _adopt_dec = [Remote], _release_dec = [Remote], _upsert_dec = [Remote], _refreshServer_dec = [Remote], _removeServer_dec = [Remote], _setEnabled_dec = [Remote], _test_dec = [Remote], _jsonRead_dec = [Remote], _jsonWrite_dec = [Remote], _envList_dec = [Remote], _envInject_dec = [Remote], _envSet_dec = [Remote], _oauthStart_dec = [Remote], _a) {
115
+ class McpOpsService extends (_a = TypertRemoteService, _list_dec = [Remote], _refresh_dec = [Remote], _toolsList_dec = [Remote], _toolsSet_dec = [Remote], _toolsMode_dec = [Remote], _adopt_dec = [Remote], _release_dec = [Remote], _upsert_dec = [Remote], _refreshServer_dec = [Remote], _removeServer_dec = [Remote], _setEnabled_dec = [Remote], _test_dec = [Remote], _jsonRead_dec = [Remote], _jsonWrite_dec = [Remote], _envList_dec = [Remote], _envInject_dec = [Remote], _envSet_dec = [Remote], _oauthStart_dec = [Remote], _oauthCancel_dec = [Remote], _oauthSignOut_dec = [Remote], _a) {
129
116
  /**
130
117
  * @param ctx - Host 上下文。
131
118
  * @param config - 插件配置(bundle 行 `config`)。
@@ -196,13 +183,6 @@ class McpOpsService extends (_a = TypertRemoteService, _list_dec = [Remote], _re
196
183
  __publicField(this, "syncChain", Promise.resolve());
197
184
  /** 凭据更新事件的去抖定时器(B37)。 */
198
185
  __publicField(this, "credentialTimer");
199
- /**
200
- * Web 回调路由是否已经注册(B81)。
201
- *
202
- * `false` 的两种情形:组合里根本没有 `webServer`(Electron/TUI),或官方路由注册失败
203
- * (例如别的插件先占了同一路径)—— 两种都让 {@link startOAuth} 走回环,语义不变。
204
- */
205
- __publicField(this, "webCallbackReady", false);
206
186
  this.hostCtx = ctx;
207
187
  this.config = config;
208
188
  this.mounts = new MountManager(ctx);
@@ -227,25 +207,15 @@ class McpOpsService extends (_a = TypertRemoteService, _list_dec = [Remote], _re
227
207
  ctx.effect(() => () => {
228
208
  if (this.credentialTimer !== void 0) clearTimeout(this.credentialTimer);
229
209
  }, "dsh-mcp-ops:credentials-timer");
230
- const webHost = ctx.get("webServer");
231
- if (webHost !== void 0) {
232
- try {
233
- ctx.effect(
234
- () => webHost.register({ kind: "exact", path: WEB_CALLBACK_PATH, handler: handleWebCallback }),
235
- "dsh-mcp-ops:oauth callback"
236
- );
237
- this.webCallbackReady = true;
238
- } catch (error) {
239
- process.stderr.write(`dsh-mcp-ops: OAuth Web \u56DE\u8C03\u8DEF\u7531\u6CE8\u518C\u5931\u8D25\uFF0C\u56DE\u9000\u56DE\u73AF\uFF1A${error instanceof Error ? error.message : String(error)}
240
- `);
241
- }
242
- }
243
210
  }
244
211
  /**
245
212
  * 凭据更新事件的落点(B37):只有"本插件认识"的引用才触发同步。
246
213
  *
247
- * 认识的三种:服务器级引用(在已知名字集合里唯一命中)、OAuth token / client 引用、
248
- * 进程级引用。其余(别的插件、用户手写的)一律忽略 —— 这就是"精确归属"。
214
+ * 认识的两种:服务器级引用(在已知名字集合里唯一命中)与进程级引用。其余(别的插件、
215
+ * 用户手写的)一律忽略 —— 这就是"精确归属"。
216
+ *
217
+ * **OAuth 凭据不在其中**(0.3.0):token 由官方 client 持有并自行监听轮换、重建连接,
218
+ * 本插件既不认识那些键,也不需要在轮换时做任何事。
249
219
  *
250
220
  * 不直接 `restart`:走一次去抖的差分 `sync()`,指纹没变就什么都不发生(自己做过的写
251
221
  * 不会引起多余重启,真轮换才会)。
@@ -254,7 +224,7 @@ class McpOpsService extends (_a = TypertRemoteService, _list_dec = [Remote], _re
254
224
  */
255
225
  onCredentialUpdated(ref) {
256
226
  const names = this.snapshot.servers.map((server) => server.serverName);
257
- const owned = resolveServerRef(ref, names) !== void 0 || resolveOAuthRef(ref, names) !== void 0 || typeof ref === "string" && ref.startsWith("DSH_MCP_ENV_");
227
+ const owned = resolveServerRef(ref, names) !== void 0 || typeof ref === "string" && ref.startsWith("DSH_MCP_ENV_");
258
228
  if (!owned) return;
259
229
  if (this.credentialTimer !== void 0) clearTimeout(this.credentialTimer);
260
230
  this.credentialTimer = setTimeout(() => {
@@ -307,6 +277,10 @@ class McpOpsService extends (_a = TypertRemoteService, _list_dec = [Remote], _re
307
277
  *
308
278
  * @returns 名字数组(空数组表示没有外部配置)。
309
279
  */
280
+ /** 官方 MCP 管理器(挂载、探测与 OAuth 授权都经它)。 */
281
+ get manager() {
282
+ return this.hostCtx.mcpManager;
283
+ }
310
284
  managerOccupiedNames() {
311
285
  try {
312
286
  const mine = this.mounts.liveServerNames();
@@ -830,6 +804,7 @@ class McpOpsService extends (_a = TypertRemoteService, _list_dec = [Remote], _re
830
804
  await this.ready;
831
805
  const outcome = await this.toolControl.setMode(request?.mode);
832
806
  if (!outcome.ok) return outcome;
807
+ this.snapshot = await this.sync();
833
808
  return { ok: true, value: this.toolControl.list() };
834
809
  }
835
810
  async adopt(request) {
@@ -1089,17 +1064,6 @@ class McpOpsService extends (_a = TypertRemoteService, _list_dec = [Remote], _re
1089
1064
  }
1090
1065
  return { ...configs, tool_switches: switches };
1091
1066
  });
1092
- for (const kind of ["token", "client", "access"]) {
1093
- try {
1094
- const fromRef = kind === "access" ? oauthAccessRef(from) : oauthRef(from, kind === "client");
1095
- const toRef = kind === "access" ? oauthAccessRef(to) : oauthRef(to, kind === "client");
1096
- if (String(fromRef) === String(toRef)) continue;
1097
- const resolved = await this.hostCtx.credentials.resolve(fromRef);
1098
- if (resolved !== void 0 && resolved.value !== "") await this.hostCtx.credentials.set(toRef, resolved.value);
1099
- await this.hostCtx.credentials.unset(fromRef);
1100
- } catch {
1101
- }
1102
- }
1103
1067
  if (serverEnvRefPrefix(from) !== serverEnvRefPrefix(to)) {
1104
1068
  for (const envName of serverEnvNamesOf(this.credentialRefNames(), from)) {
1105
1069
  try {
@@ -1113,161 +1077,6 @@ class McpOpsService extends (_a = TypertRemoteService, _list_dec = [Remote], _re
1113
1077
  }
1114
1078
  }
1115
1079
  }
1116
- /**
1117
- * 取(或注册)OAuth 客户端信息。
1118
- *
1119
- * **复用条件(B82)**:缓存里的 `redirectUris` 必须**包含本次的 `redirectUri`**。
1120
- * RFC 6749 §3.1.2.3 要求授权请求的 `redirect_uri` 与注册时一致,而注册记录是持久化的 ——
1121
- * B81 之后回调可能是宿主 origin(Web 路)或稳定端口回环,换了形态/端口/origin 就会不一致,
1122
- * 只比对 clientId 会让授权服务器以含糊错误拒绝。老记录没有该字段 → 不敢复用 → 重新注册。
1123
- *
1124
- * 没存过、或需要重新注册时:有注册端点就做一次动态客户端注册(MCP 生态的通行做法)并用新的
1125
- * `redirectUris: [redirectUri]` **覆盖**缓存;注册不可用或失败时**保留**用户已有的 client
1126
- * 并留一行诊断(丢掉它等于让用户白授权一次),完全没缓存才退化到固定 client id。
1127
- *
1128
- * @param serverName - 服务器名。
1129
- * @param metadata - 服务器元数据。
1130
- * @param redirectUri - 本次授权将使用的回调地址(回环或 Web)。
1131
- * @returns 客户端信息。
1132
- */
1133
- async oauthClient(serverName, metadata, redirectUri) {
1134
- let cached;
1135
- try {
1136
- const stored = await this.hostCtx.credentials.resolve(oauthRef(serverName, true));
1137
- cached = parseClient(stored?.value);
1138
- } catch {
1139
- }
1140
- if (cached !== void 0 && cached.redirectUris?.includes(redirectUri) === true) return cached;
1141
- if (metadata.registrationEndpoint === void 0) {
1142
- if (cached === void 0) return { clientId: "dsh-mcp-ops" };
1143
- this.warnClientMismatch(serverName, redirectUri, cached, "\u670D\u52A1\u5668\u672A\u58F0\u660E\u52A8\u6001\u6CE8\u518C\u7AEF\u70B9");
1144
- return cached;
1145
- }
1146
- try {
1147
- const response = await systemFetch()(metadata.registrationEndpoint, {
1148
- method: "POST",
1149
- headers: { "content-type": "application/json", accept: "application/json" },
1150
- body: JSON.stringify({
1151
- client_name: "dsh-mcp-ops",
1152
- redirect_uris: [redirectUri],
1153
- grant_types: ["authorization_code"],
1154
- response_types: ["code"],
1155
- token_endpoint_auth_method: "none"
1156
- })
1157
- });
1158
- if (response.ok) {
1159
- const body = await response.json();
1160
- if (typeof body.client_id === "string") {
1161
- const client = {
1162
- clientId: body.client_id,
1163
- ...typeof body.client_secret === "string" ? { clientSecret: body.client_secret } : {},
1164
- redirectUris: [redirectUri]
1165
- };
1166
- await this.hostCtx.credentials.set(oauthRef(serverName, true), serializeClient(client));
1167
- return client;
1168
- }
1169
- }
1170
- } catch {
1171
- }
1172
- if (cached !== void 0) {
1173
- this.warnClientMismatch(serverName, redirectUri, cached, "\u91CD\u65B0\u6CE8\u518C\u5931\u8D25");
1174
- return cached;
1175
- }
1176
- return { clientId: "dsh-mcp-ops" };
1177
- }
1178
- /**
1179
- * 记录"缓存的 client 与本次回调地址不匹配、且无法重新注册"(B82)。
1180
- *
1181
- * 刻意 **不静默**:这种状态下 authorize 请求很可能被授权服务器拒绝,而且错误信息通常含糊
1182
- * ("invalid_client" / "invalid redirect_uri"),把这行诊断留在 stderr 能直接对上根因。
1183
- *
1184
- * @param serverName - 服务器名。
1185
- * @param redirectUri - 本次使用的回调地址。
1186
- * @param cached - 正在沿用的缓存 client。
1187
- * @param reason - 无法重新注册的原因(人类可读)。
1188
- */
1189
- warnClientMismatch(serverName, redirectUri, cached, reason) {
1190
- const registered = cached.redirectUris === void 0 ? "\uFF08\u8001\u8BB0\u5F55\uFF0C\u672A\u8BB0\u5F55 redirect_uris\uFF09" : cached.redirectUris.length === 0 ? "\uFF08\u7A7A\uFF09" : cached.redirectUris.join(", ");
1191
- process.stderr.write(
1192
- `dsh-mcp-ops: OAuth \u6CBF\u7528\u5DF2\u6709\u5BA2\u6237\u7AEF\uFF08${serverName}\uFF09\uFF1A${reason}\uFF0C\u672C\u6B21\u56DE\u8C03\u5730\u5740 ${redirectUri}\uFF0C\u6CE8\u518C\u8BB0\u5F55\u91CC\u7684 ${registered}\uFF08client ${cached.clientId}\uFF09\u2014\u2014 \u6388\u6743\u670D\u52A1\u5668\u53EF\u80FD\u56E0 redirect_uri \u4E0D\u4E00\u81F4\u800C\u62D2\u7EDD
1193
- `
1194
- );
1195
- }
1196
- /**
1197
- * 启动一次 OAuth 授权:定回调地址 → 返回授权地址 → 后台等回调换 token 并落库(B81)。
1198
- *
1199
- * **两条回调路**:
1200
- * - `origin` 有值且 Web 路由已注册 → 固定路径的宿主 origin 回调(`awaitWebCallback` + 常驻路由);
1201
- * - 否则 → 原有的稳定端口回环(`awaitLoopbackCallback`,T3 语义不变)。
1202
- *
1203
- * 两条路只在"怎么拿到 code"上不同:`state` 校验、超时、后台换 token、落 credentials 全部共用
1204
- * 下面这一段(刻意不复制两份)。
1205
- *
1206
- * @param serverName - 服务器名。
1207
- * @param url - 服务器地址(发现元数据用)。
1208
- * @param origin - 已经过 `sanitizeOrigin` 的浏览器 origin;`undefined` = 走回环。
1209
- * @returns 授权地址与回调地址。
1210
- */
1211
- async startOAuth(serverName, url, origin) {
1212
- const metadata = await discoverMetadata(url);
1213
- const state = createState();
1214
- const useWeb = origin !== void 0 && this.webCallbackReady;
1215
- let callback;
1216
- let redirectUri;
1217
- if (useWeb) {
1218
- callback = awaitWebCallback({ origin, state, budgetMs: 5 * 6e4 }).promise;
1219
- redirectUri = webCallbackUri(origin);
1220
- } else {
1221
- let resolveReady = () => {
1222
- };
1223
- const ready = new Promise((resolve) => {
1224
- resolveReady = resolve;
1225
- });
1226
- callback = awaitLoopbackCallback({
1227
- serverName,
1228
- state,
1229
- budgetMs: 5 * 6e4,
1230
- onReady: (uri) => resolveReady(uri)
1231
- });
1232
- redirectUri = await ready;
1233
- }
1234
- const client = await this.oauthClient(serverName, metadata, redirectUri);
1235
- const pkce = createPkcePair();
1236
- const authorizeUrl = buildAuthorizationUrl({
1237
- authorizationEndpoint: metadata.authorizationEndpoint,
1238
- clientId: client.clientId,
1239
- redirectUri,
1240
- state,
1241
- challenge: pkce.challenge,
1242
- ...metadata.scopesSupported === void 0 || metadata.scopesSupported.length === 0 ? {} : { scope: metadata.scopesSupported.join(" ") }
1243
- });
1244
- void callback.then(async (result) => {
1245
- if (result.iss !== void 0 && metadata.issuer !== void 0 && result.iss !== metadata.issuer) {
1246
- throw new Error(`OAuth issuer mismatch: callback says ${JSON.stringify(result.iss)}, metadata says ${JSON.stringify(metadata.issuer)}`);
1247
- }
1248
- const token = await exchangeCode({
1249
- tokenEndpoint: metadata.tokenEndpoint,
1250
- code: result.code,
1251
- verifier: pkce.verifier,
1252
- clientId: client.clientId,
1253
- redirectUri: result.redirectUri,
1254
- ...client.clientSecret === void 0 ? {} : { clientSecret: client.clientSecret }
1255
- });
1256
- await writeToken(this.hostCtx.credentials, serverName, token);
1257
- process.stderr.write(`dsh-mcp-ops: OAuth \u6388\u6743\u5B8C\u6210\uFF08${serverName}\uFF09\uFF0Ctoken \u5DF2\u5B58\u50A8
1258
- `);
1259
- await this.forceRestartOAuth(serverName).catch((error) => {
1260
- process.stderr.write(`dsh-mcp-ops: OAuth \u6388\u6743\u540E\u91CD\u5EFA\u5931\u8D25\uFF08${serverName}\uFF09\uFF1A${error instanceof Error ? error.message : String(error)}
1261
- `);
1262
- });
1263
- }).catch((error) => {
1264
- process.stderr.write(`dsh-mcp-ops: OAuth \u6388\u6743\u5931\u8D25\uFF08${serverName}\uFF09\uFF1A${error instanceof Error ? error.message : String(error)}
1265
- `);
1266
- });
1267
- process.stderr.write(`dsh-mcp-ops: OAuth \u6388\u6743\u5730\u5740\uFF08${serverName}\uFF09\uFF1A${authorizeUrl}
1268
- `);
1269
- return { authorizeUrl, redirectUri };
1270
- }
1271
1080
  /**
1272
1081
  * 把表单输入转成条目模型(同时算出要写进 credentials 的 secret)。
1273
1082
  *
@@ -1400,7 +1209,10 @@ class McpOpsService extends (_a = TypertRemoteService, _list_dec = [Remote], _re
1400
1209
  // 结果把**文件路径**当成了目录发给子进程(桌面版实测)。
1401
1210
  builtins: { MCP_JSON_DIR: sourceDirectory(row.sourcePath) },
1402
1211
  secrets: info.secrets,
1403
- secretProblems: info.problems
1212
+ secretProblems: info.problems,
1213
+ // 注入模式是**全局**状态(`configs.injectionMode`),每次同步都按当前值重算:
1214
+ // 切模式 → 注册项里的 `toolLoading` 变 → 指纹变 → 差分重建,不需要额外的重启路径。
1215
+ toolLoading: this.configs.injectionMode
1404
1216
  };
1405
1217
  }
1406
1218
  /**
@@ -1535,6 +1347,11 @@ class McpOpsService extends (_a = TypertRemoteService, _list_dec = [Remote], _re
1535
1347
  }
1536
1348
  const overlayPatch = {
1537
1349
  ...input.oauth === void 0 ? {} : { oauth: input.oauth },
1350
+ // scope / clientId 只在勾了 OAuth 时才有意义;取消勾选时一并清掉(否则下次勾回来会
1351
+ // 悄悄复用上次的 scope,用户以为改了其实没改)。
1352
+ ...input.oauth === true && input.oauthScope !== void 0 ? { oauthScope: input.oauthScope } : {},
1353
+ ...input.oauth === true && input.oauthClientId !== void 0 ? { oauthClientId: input.oauthClientId } : {},
1354
+ ...input.oauth === false ? { oauthScope: void 0, oauthClientId: void 0 } : {},
1538
1355
  ...input.timeoutMs !== void 0 ? { toolCallTimeoutMs: input.timeoutMs } : mode === "update" ? { toolCallTimeoutMs: void 0 } : {}
1539
1356
  };
1540
1357
  if (Object.keys(overlayPatch).length > 0) {
@@ -1607,7 +1424,6 @@ class McpOpsService extends (_a = TypertRemoteService, _list_dec = [Remote], _re
1607
1424
  } catch {
1608
1425
  }
1609
1426
  }
1610
- await clearToken(this.hostCtx.credentials, serverName);
1611
1427
  }
1612
1428
  for (const [envName, value] of Object.entries(row.spec.env)) {
1613
1429
  const ref = legacySecretRef(serverName, envName, value.value);
@@ -1693,9 +1509,10 @@ class McpOpsService extends (_a = TypertRemoteService, _list_dec = [Remote], _re
1693
1509
  globalEnv,
1694
1510
  injectGlobalEnv: global.injectGlobalEnvToStdio,
1695
1511
  secrets: merged,
1696
- ...input.oauth === void 0 ? {} : { overlay: { oauth: input.oauth } },
1697
- builtins: { MCP_JSON_DIR: sourceDirectory(this.targetLocation(locations)?.path ?? join(process.cwd(), ".mcp.json")) }
1698
- }, { oauth: input.oauth === true });
1512
+ ...input.oauth === void 0 ? {} : { overlay: { oauth: input.oauth, ...input.oauthScope === void 0 ? {} : { oauthScope: input.oauthScope }, ...input.oauthClientId === void 0 ? {} : { oauthClientId: input.oauthClientId } } },
1513
+ builtins: { MCP_JSON_DIR: sourceDirectory(this.targetLocation(locations)?.path ?? join(process.cwd(), ".mcp.json")) },
1514
+ toolLoading: this.configs.injectionMode
1515
+ });
1699
1516
  return {
1700
1517
  ok: true,
1701
1518
  value: {
@@ -1865,44 +1682,45 @@ class McpOpsService extends (_a = TypertRemoteService, _list_dec = [Remote], _re
1865
1682
  await this.sync();
1866
1683
  return { ok: true, value: payload.value };
1867
1684
  }
1868
- /**
1869
- * 授权完成后强制重建**这一个**服务器的注册(忽略指纹)。
1870
- *
1871
- * 为什么需要显式重建:授权前若没有新鲜 token,`sync()` 会把该服务器记为 `failed` 且不注册;
1872
- * 拿到 token 后只写凭据不会让"未注册"的服务器自动出现。这里重读一次行、重建挂载请求并
1873
- * 走 `mounts.restart()`,随后再 `sync()` 刷新整份视图。
1874
- *
1875
- * @param serverName - 刚完成授权的服务器名。
1876
- */
1877
- async forceRestartOAuth(serverName) {
1878
- const { locations, rows, overlays } = await this.readNow();
1879
- const globalEnv = await this.readGlobalEnv();
1880
- const global = this.readGlobal();
1881
- const scan = this.scanComposition();
1882
- const inputs = [...readFileSources(locations), ...cordisSourceResults(scan, locations)];
1883
- const preliminary = buildSnapshot(inputs, overlays, []);
1884
- const row = effectiveRow(preliminary.rows, serverName);
1885
- if (row === void 0 || !row.enabled || row.occupiedByComposition) return;
1886
- await this.mounts.restart(this.mountRequestOf(
1887
- row,
1888
- globalEnv,
1889
- global.injectGlobalEnvToStdio,
1890
- await this.secretInfoOf(row, serverEnvNamesOf(this.credentialRefNames(), serverName))
1891
- ));
1892
- this.snapshot = await this.sync();
1893
- }
1894
1685
  async oauthStart(request) {
1895
1686
  await this.ready;
1896
1687
  const serverName = typeof request?.serverName === "string" ? request.serverName : "";
1897
1688
  if (serverName === "") return failure("MCP_INVALID_SPEC", "serverName is required");
1898
- const url = typeof request?.url === "string" ? request.url : "";
1899
- if (url === "") return failure("MCP_INVALID_SPEC", "url is required for OAuth");
1900
- const origin = sanitizeOrigin(request?.origin);
1901
1689
  try {
1902
- const started = await this.startOAuth(serverName, url, origin);
1903
- return { ok: true, value: started };
1690
+ const attempt = await this.manager().startAuthorization(serverName);
1691
+ this.snapshot = await this.sync();
1692
+ return {
1693
+ ok: true,
1694
+ value: { attempt: projectAttempt(attempt), servers: this.snapshot.servers }
1695
+ };
1904
1696
  } catch (error) {
1905
- return failure("MCP_FILE_WRITE_FAILED", error instanceof Error ? error.message : String(error));
1697
+ return failure("MCP_OAUTH_FAILED", error instanceof Error ? error.message : String(error));
1698
+ }
1699
+ }
1700
+ async oauthCancel(request) {
1701
+ await this.ready;
1702
+ const serverName = typeof request?.serverName === "string" ? request.serverName : "";
1703
+ const attemptId = typeof request?.attemptId === "string" ? request.attemptId : "";
1704
+ if (serverName === "") return failure("MCP_INVALID_SPEC", "serverName is required");
1705
+ if (attemptId === "") return failure("MCP_INVALID_SPEC", "attemptId is required");
1706
+ try {
1707
+ await this.manager().cancelAuthorization(serverName, attemptId);
1708
+ this.snapshot = await this.sync();
1709
+ return { ok: true, value: { servers: this.snapshot.servers } };
1710
+ } catch (error) {
1711
+ return failure("MCP_OAUTH_FAILED", error instanceof Error ? error.message : String(error));
1712
+ }
1713
+ }
1714
+ async oauthSignOut(request) {
1715
+ await this.ready;
1716
+ const serverName = typeof request?.serverName === "string" ? request.serverName : "";
1717
+ if (serverName === "") return failure("MCP_INVALID_SPEC", "serverName is required");
1718
+ try {
1719
+ await this.manager().signOut(serverName);
1720
+ this.snapshot = await this.sync();
1721
+ return { ok: true, value: { servers: this.snapshot.servers } };
1722
+ } catch (error) {
1723
+ return failure("MCP_OAUTH_FAILED", error instanceof Error ? error.message : String(error));
1906
1724
  }
1907
1725
  }
1908
1726
  /**
@@ -1941,9 +1759,19 @@ __decorateElement(_init, 1, "envList", _envList_dec, McpOpsService);
1941
1759
  __decorateElement(_init, 1, "envInject", _envInject_dec, McpOpsService);
1942
1760
  __decorateElement(_init, 1, "envSet", _envSet_dec, McpOpsService);
1943
1761
  __decorateElement(_init, 1, "oauthStart", _oauthStart_dec, McpOpsService);
1762
+ __decorateElement(_init, 1, "oauthCancel", _oauthCancel_dec, McpOpsService);
1763
+ __decorateElement(_init, 1, "oauthSignOut", _oauthSignOut_dec, McpOpsService);
1944
1764
  __decoratorMetadata(_init, McpOpsService);
1945
1765
  /** 需要的 Host 服务:缺任何一个即不激活。 */
1946
1766
  __publicField(McpOpsService, "inject", ["credentials", "tools", "mcpManager"]);
1767
+ function projectAttempt(view) {
1768
+ return {
1769
+ attemptId: String(view.id),
1770
+ phase: view.phase,
1771
+ ...view.authorizationUrl === void 0 ? {} : { authorizationUrl: view.authorizationUrl },
1772
+ ...view.lastError === void 0 ? {} : { lastError: view.lastError }
1773
+ };
1774
+ }
1947
1775
  function failure(code, message) {
1948
1776
  return { ok: false, error: { code, message } };
1949
1777
  }
@@ -1,8 +1,7 @@
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 * as yaml from "js-yaml";
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";
@@ -22,7 +21,7 @@ function readLayer(path, kind, io) {
22
21
  }
23
22
  let parsed;
24
23
  try {
25
- parsed = yaml.load(text, { schema: entryListSchema });
24
+ parsed = parseEntryYaml(text);
26
25
  } catch (error) {
27
26
  return { path, kind, exists: true, readable: true, parseError: error instanceof Error ? error.message : String(error), patches: [], rows: [] };
28
27
  }
@@ -90,7 +89,7 @@ function scanCordisComposition(options) {
90
89
  }
91
90
  const flat = layers.flatMap((layer) => layer.patches);
92
91
  const effectiveRaw = applyEntryPatches([], structuredClone(flat), () => {
93
- });
92
+ }).data;
94
93
  const effective = effectiveRaw.map((entry) => {
95
94
  const row = rowOf(entry, true, "");
96
95
  return { ...row, path: pathOfDeclaration(layers, row) };