@blackbelt-technology/pi-dashboard-mcp-client-plugin 0.8.0 → 0.10.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/package.json +5 -3
- package/schema/mcp-config.schema.json +11 -1
- package/src/client/FolderMcpPage.tsx +183 -45
- package/src/client/FolderMcpSection.tsx +2 -1
- package/src/client/McpSettings.tsx +56 -39
- package/src/client/ProjectSettings.tsx +217 -0
- package/src/client/ServerList.tsx +430 -169
- package/src/client/api.ts +52 -2
- package/src/client/folder-view.ts +30 -8
- package/src/client/hooks.ts +38 -4
- package/src/client/index.tsx +0 -2
- package/src/client/settings-ui.ts +19 -0
- package/src/core/config-writer.ts +252 -25
- package/src/core/effective-view.ts +63 -9
- package/src/core/index.ts +12 -0
- package/src/core/path-utils.ts +12 -0
- package/src/core/pi-rules.ts +80 -3
- package/src/core/schema-validation.ts +10 -5
- package/src/core/service.ts +48 -3
- package/src/core/types.ts +86 -8
- package/src/server/index.ts +23 -1
- package/src/server/routes.ts +236 -48
package/src/server/routes.ts
CHANGED
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
* DELETE /api/mcp-client/servers/:name?scope=&cwd= → {ok, removed}
|
|
9
9
|
* PUT /api/mcp-client/servers/:name/enabled {scope, cwd?, enabled}
|
|
10
10
|
* POST /api/mcp-client/servers/:name/convert {scope, cwd?} — adapter leftovers → pi
|
|
11
|
+
* PUT /api/mcp-client/servers/:name/project-override {scope:"project", cwd, enabled?, exposure?, toolExposure?} — null = inherit
|
|
12
|
+
* POST /api/mcp-client/servers/:name/convert-to-override {scope:"project", cwd} — legacy folder copy → override
|
|
11
13
|
*
|
|
12
14
|
* Every route (GET included) is registered behind the host `networkGuard`
|
|
13
15
|
* (cookie/token/loopback auth): a write becomes executable configuration for
|
|
@@ -15,21 +17,35 @@
|
|
|
15
17
|
* decoded and validated, and a project cwd is admitted against the
|
|
16
18
|
* known-folder set, BEFORE any file is read or written.
|
|
17
19
|
*
|
|
18
|
-
* See change: migrate-mcp-to-pi-builtin (D3);
|
|
20
|
+
* See change: migrate-mcp-to-pi-builtin (D3); mcp-client-project-overrides (D6);
|
|
21
|
+
* earlier: extract-mcp-client-plugin (D7).
|
|
19
22
|
*/
|
|
20
23
|
|
|
21
|
-
import type { ServerPluginContext } from "@blackbelt-technology/dashboard-plugin-runtime/server";
|
|
22
|
-
import {
|
|
24
|
+
import type { CwdHoldOrigin, ServerPluginContext } from "@blackbelt-technology/dashboard-plugin-runtime/server";
|
|
25
|
+
import {
|
|
26
|
+
type AdmitCwdOptions,
|
|
27
|
+
admissionAllows,
|
|
28
|
+
admitCwd,
|
|
29
|
+
issueHeldAdmission,
|
|
30
|
+
releaseAdmission,
|
|
31
|
+
} from "@blackbelt-technology/pi-dashboard-shared/cwd-guard.js";
|
|
23
32
|
import type { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
|
|
24
|
-
import { isValidServerName } from "../core/pi-rules.js";
|
|
33
|
+
import { isValidServerName, OVERRIDE_KEYS } from "../core/pi-rules.js";
|
|
25
34
|
import { errorFields, mcpConfigSchema, validateServerEntry } from "../core/schema-validation.js";
|
|
26
35
|
import type { McpClientRuntime } from "../core/service.js";
|
|
27
|
-
import type { ConfigRefusal, Scope, ServerEntry } from "../core/types.js";
|
|
36
|
+
import type { ConfigRefusal, ProjectOverridePatch, Scope, ServerEntry } from "../core/types.js";
|
|
28
37
|
|
|
29
38
|
export interface McpClientRouteDeps {
|
|
30
39
|
runtime: McpClientRuntime;
|
|
31
40
|
knownCwds: () => string[];
|
|
32
41
|
networkGuard: ServerPluginContext["networkGuard"];
|
|
42
|
+
/**
|
|
43
|
+
* Host seam that raises the `cwd` access dialog. Optional: on a host without it
|
|
44
|
+
* a write on an unknown cwd is refused with the existing 403.
|
|
45
|
+
*/
|
|
46
|
+
holdCwdDenial?: ServerPluginContext["holdCwdDenial"];
|
|
47
|
+
/** `admitCwd` options (the host's `onIndeterminate` logger; test seams). */
|
|
48
|
+
admitOptions?: AdmitCwdOptions;
|
|
33
49
|
}
|
|
34
50
|
|
|
35
51
|
const PREFIX = "/api/mcp-client";
|
|
@@ -57,6 +73,8 @@ function refusalParts(refusal: ConfigRefusal): { status: number; body: Record<st
|
|
|
57
73
|
return { status: 400, body };
|
|
58
74
|
case "transport-conflict":
|
|
59
75
|
return { status: 400, body: { ...body, fields: refusal.fields ?? [] } };
|
|
76
|
+
case "no-global-server":
|
|
77
|
+
return { status: 409, body };
|
|
60
78
|
case "name-collision":
|
|
61
79
|
return { status: 409, body: { ...body, ...(refusal.conflict ? { conflict: refusal.conflict } : {}) } };
|
|
62
80
|
case "unparseable":
|
|
@@ -77,19 +95,89 @@ interface ScopeInput {
|
|
|
77
95
|
cwd?: unknown;
|
|
78
96
|
}
|
|
79
97
|
|
|
80
|
-
type ParsedScope =
|
|
98
|
+
type ParsedScope =
|
|
99
|
+
| { ok: true; scope: Scope }
|
|
100
|
+
| { ok: false; status: number; body: Record<string, unknown>; headers?: Record<string, string> };
|
|
101
|
+
|
|
102
|
+
/** The decision could not be made (a git probe failed): transient, never a refusal. */
|
|
103
|
+
function admissionUnavailable(cwd: string): Extract<ParsedScope, { ok: false }> {
|
|
104
|
+
return {
|
|
105
|
+
ok: false,
|
|
106
|
+
status: 503,
|
|
107
|
+
body: {
|
|
108
|
+
error: "cwd-admission-unavailable",
|
|
109
|
+
message: `cwd admission could not be decided right now: ${cwd}`,
|
|
110
|
+
retryAfterMs: 1000,
|
|
111
|
+
},
|
|
112
|
+
headers: { "Retry-After": "1" },
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function sendParseFailure(reply: FastifyReply, parsed: Extract<ParsedScope, { ok: false }>): FastifyReply {
|
|
117
|
+
if (parsed.headers) reply.headers(parsed.headers);
|
|
118
|
+
return reply.code(parsed.status).send(parsed.body);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** End a route-built scope's admission token. Call in the handler's `finally`. */
|
|
122
|
+
function releaseScope(scope: Scope): void {
|
|
123
|
+
if (scope.kind === "project" && scope.admission) releaseAdmission(scope.admission);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
interface ScopeRequest {
|
|
127
|
+
request: FastifyRequest;
|
|
128
|
+
reply: FastifyReply;
|
|
129
|
+
/** Set only on a user-initiated WRITE route: a refusal may raise the access dialog. */
|
|
130
|
+
holdOrigin?: CwdHoldOrigin;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** Ask the host to raise the access dialog for a refused write, and admit on a confirmed allow. */
|
|
134
|
+
async function admitViaHold(
|
|
135
|
+
cwd: string,
|
|
136
|
+
deps: McpClientRouteDeps,
|
|
137
|
+
req: ScopeRequest & { holdOrigin: CwdHoldOrigin },
|
|
138
|
+
): Promise<ParsedScope | null> {
|
|
139
|
+
if (!deps.holdCwdDenial) return null;
|
|
140
|
+
const decision = await deps.holdCwdDenial(req.request, req.reply, { cwd, origin: req.holdOrigin });
|
|
141
|
+
if (decision.kind === "indeterminate") return admissionUnavailable(cwd);
|
|
142
|
+
// The host returns a decision, never a token: mint our own, bound to this cwd.
|
|
143
|
+
const held = issueHeldAdmission(decision, cwd);
|
|
144
|
+
if (held.kind === "admit" && admissionAllows(held, cwd)) {
|
|
145
|
+
return { ok: true, scope: { kind: "project", cwd, admission: held.token } };
|
|
146
|
+
}
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** Admit a project `cwd`: `admit` → token-bearing scope; `indeterminate` → 503; `refuse` → hold (writes) or 403. */
|
|
151
|
+
async function admitProject(cwd: string, deps: McpClientRouteDeps, req: ScopeRequest): Promise<ParsedScope> {
|
|
152
|
+
const admission = await admitCwd(cwd, deps.knownCwds, deps.admitOptions);
|
|
153
|
+
if (admission.kind === "admit" && admissionAllows(admission, cwd)) {
|
|
154
|
+
return { ok: true, scope: { kind: "project", cwd, admission: admission.token } };
|
|
155
|
+
}
|
|
156
|
+
if (admission.kind === "indeterminate") return admissionUnavailable(cwd);
|
|
157
|
+
if (req.holdOrigin) {
|
|
158
|
+
const held = await admitViaHold(cwd, deps, { ...req, holdOrigin: req.holdOrigin });
|
|
159
|
+
if (held) return held;
|
|
160
|
+
}
|
|
161
|
+
return { ok: false, ...notAllowed(cwd) };
|
|
162
|
+
}
|
|
81
163
|
|
|
82
|
-
/**
|
|
83
|
-
|
|
164
|
+
/**
|
|
165
|
+
* Parse + ADMIT a scope before any IO. A project cwd is decided by the async
|
|
166
|
+
* tri-state guard: `admit` → a scope carrying a request-scoped token; `refuse` →
|
|
167
|
+
* on a write route the host may ask the operator (`holdCwdDenial`), else 403;
|
|
168
|
+
* `indeterminate` → 503 (never a refusal, never a prompt). A client-sent
|
|
169
|
+
* `admission` field is never read.
|
|
170
|
+
*/
|
|
171
|
+
async function parseScope(input: ScopeInput, deps: McpClientRouteDeps, req: ScopeRequest): Promise<ParsedScope> {
|
|
84
172
|
if (input.scope === "global") return { ok: true, scope: { kind: "global" } };
|
|
85
|
-
if (input.scope
|
|
86
|
-
|
|
87
|
-
return { ok: false, status: 400, body: { error: "invalid-body", message: "project scope requires a cwd" } };
|
|
88
|
-
}
|
|
89
|
-
if (!isAllowedCwd(input.cwd, knownCwds)) return { ok: false, ...notAllowed(input.cwd) };
|
|
90
|
-
return { ok: true, scope: { kind: "project", cwd: input.cwd } };
|
|
173
|
+
if (input.scope !== "project") {
|
|
174
|
+
return { ok: false, status: 400, body: { error: "invalid-body", message: "scope must be 'global' or 'project'" } };
|
|
91
175
|
}
|
|
92
|
-
|
|
176
|
+
const cwd = input.cwd;
|
|
177
|
+
if (typeof cwd !== "string" || cwd.length === 0) {
|
|
178
|
+
return { ok: false, status: 400, body: { error: "invalid-body", message: "project scope requires a cwd" } };
|
|
179
|
+
}
|
|
180
|
+
return admitProject(cwd, deps, req);
|
|
93
181
|
}
|
|
94
182
|
|
|
95
183
|
/** Decoded + validated path name, or null. */
|
|
@@ -106,32 +194,66 @@ function pathName(request: FastifyRequest): string | null {
|
|
|
106
194
|
}
|
|
107
195
|
|
|
108
196
|
/** `?cwd=` → scope, admitted; a repeated key (array) is refused. */
|
|
109
|
-
function queryScope(request: FastifyRequest,
|
|
197
|
+
async function queryScope(request: FastifyRequest, reply: FastifyReply, deps: McpClientRouteDeps): Promise<ParsedScope> {
|
|
110
198
|
const rawCwd = (request.query as { cwd?: unknown }).cwd;
|
|
111
199
|
if (rawCwd !== undefined && typeof rawCwd !== "string") {
|
|
112
200
|
return { ok: false, status: 400, body: { error: "invalid-cwd", message: "cwd must be a single string" } };
|
|
113
201
|
}
|
|
114
202
|
if (rawCwd === undefined || rawCwd === "") return { ok: true, scope: { kind: "global" } };
|
|
115
|
-
return parseScope({ scope: "project", cwd: rawCwd },
|
|
203
|
+
return parseScope({ scope: "project", cwd: rawCwd }, deps, { request, reply });
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/** The override patch carried by a request body, validated by type and enum (no scope or IO involved). */
|
|
207
|
+
function overridePatchOf(
|
|
208
|
+
body: Record<string, unknown>,
|
|
209
|
+
): { ok: true; patch: ProjectOverridePatch } | { ok: false; body: Record<string, unknown> } {
|
|
210
|
+
const patch: Record<string, unknown> = {};
|
|
211
|
+
const present: Record<string, unknown> = {};
|
|
212
|
+
for (const [k, v] of Object.entries(body)) {
|
|
213
|
+
if (k === "scope" || k === "cwd" || v === undefined) continue;
|
|
214
|
+
// Any other key (a secret, a typo) goes to the schema so it is refused, never dropped.
|
|
215
|
+
const known = (OVERRIDE_KEYS as readonly string[]).includes(k);
|
|
216
|
+
if (known) patch[k] = v;
|
|
217
|
+
if (!known || v !== null) present[k] = v;
|
|
218
|
+
}
|
|
219
|
+
const validation = validateServerEntry(present, { kind: "override" });
|
|
220
|
+
if (validation.ok) return { ok: true, patch: patch as ProjectOverridePatch };
|
|
221
|
+
const fields = errorFields(validation.errors);
|
|
222
|
+
return {
|
|
223
|
+
ok: false,
|
|
224
|
+
body: {
|
|
225
|
+
error: "schema",
|
|
226
|
+
message: `project override failed validation${fields.length ? ` (${fields.join(", ")})` : ""}`,
|
|
227
|
+
fields,
|
|
228
|
+
},
|
|
229
|
+
};
|
|
116
230
|
}
|
|
117
231
|
|
|
118
232
|
const INVALID_NAME = { error: "invalid-name", message: "invalid server name" };
|
|
119
233
|
|
|
120
234
|
export function mountMcpClientRoutes(fastify: FastifyInstance, deps: McpClientRouteDeps): void {
|
|
121
235
|
const guard = { preHandler: deps.networkGuard };
|
|
122
|
-
const { runtime
|
|
236
|
+
const { runtime } = deps;
|
|
123
237
|
|
|
124
238
|
fastify.get(`${PREFIX}/effective`, guard, async (request, reply) => {
|
|
125
|
-
const parsed = queryScope(request,
|
|
126
|
-
if (!parsed.ok) return reply
|
|
127
|
-
|
|
239
|
+
const parsed = await queryScope(request, reply, deps);
|
|
240
|
+
if (!parsed.ok) return sendParseFailure(reply, parsed);
|
|
241
|
+
try {
|
|
242
|
+
return runtime.getEffectiveView(parsed.scope);
|
|
243
|
+
} finally {
|
|
244
|
+
releaseScope(parsed.scope);
|
|
245
|
+
}
|
|
128
246
|
});
|
|
129
247
|
|
|
130
248
|
fastify.get(`${PREFIX}/live`, guard, async (request, reply) => {
|
|
131
|
-
const parsed = queryScope(request,
|
|
132
|
-
if (!parsed.ok) return reply
|
|
133
|
-
|
|
134
|
-
|
|
249
|
+
const parsed = await queryScope(request, reply, deps);
|
|
250
|
+
if (!parsed.ok) return sendParseFailure(reply, parsed);
|
|
251
|
+
try {
|
|
252
|
+
const fresh = (request.query as { fresh?: string }).fresh === "1";
|
|
253
|
+
return await runtime.getLiveState(parsed.scope, { fresh });
|
|
254
|
+
} finally {
|
|
255
|
+
releaseScope(parsed.scope);
|
|
256
|
+
}
|
|
135
257
|
});
|
|
136
258
|
|
|
137
259
|
fastify.get(`${PREFIX}/schema`, guard, async () => mcpConfigSchema);
|
|
@@ -140,8 +262,7 @@ export function mountMcpClientRoutes(fastify: FastifyInstance, deps: McpClientRo
|
|
|
140
262
|
const name = pathName(request);
|
|
141
263
|
if (!name) return reply.code(400).send(INVALID_NAME);
|
|
142
264
|
const body = (request.body ?? {}) as ScopeInput & { entry?: unknown; previousName?: unknown; create?: unknown };
|
|
143
|
-
|
|
144
|
-
if (!parsed.ok) return reply.code(parsed.status).send(parsed.body);
|
|
265
|
+
// Cheap body validation first, so an invalid body never raises an access dialog.
|
|
145
266
|
if (typeof body.entry !== "object" || body.entry === null || Array.isArray(body.entry)) {
|
|
146
267
|
return reply.code(400).send({ error: "invalid-body", message: "body must carry an `entry` object" });
|
|
147
268
|
}
|
|
@@ -154,46 +275,113 @@ export function mountMcpClientRoutes(fastify: FastifyInstance, deps: McpClientRo
|
|
|
154
275
|
.code(400)
|
|
155
276
|
.send({ error: "schema", message: "server entry failed validation", fields: errorFields(validation.errors) });
|
|
156
277
|
}
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
278
|
+
const parsed = await parseScope(body, deps, { request, reply, holdOrigin: "mcp:save" });
|
|
279
|
+
if (!parsed.ok) return sendParseFailure(reply, parsed);
|
|
280
|
+
try {
|
|
281
|
+
const result = runtime.saveServer(name, body.entry as ServerEntry, parsed.scope, {
|
|
282
|
+
...(typeof body.previousName === "string" ? { previousName: body.previousName } : {}),
|
|
283
|
+
...(body.create === true ? { create: true } : {}),
|
|
284
|
+
});
|
|
285
|
+
if (!result.ok) return sendRefusal(reply, result.refusal);
|
|
286
|
+
return { ok: true };
|
|
287
|
+
} finally {
|
|
288
|
+
releaseScope(parsed.scope);
|
|
289
|
+
}
|
|
163
290
|
});
|
|
164
291
|
|
|
165
292
|
fastify.delete(`${PREFIX}/servers/:name`, guard, async (request, reply) => {
|
|
166
293
|
const name = pathName(request);
|
|
167
294
|
if (!name) return reply.code(400).send(INVALID_NAME);
|
|
168
295
|
const query = request.query as { scope?: unknown; cwd?: unknown };
|
|
169
|
-
const parsed = parseScope({ scope: query.scope ?? "global", cwd: query.cwd },
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
296
|
+
const parsed = await parseScope({ scope: query.scope ?? "global", cwd: query.cwd }, deps, {
|
|
297
|
+
request,
|
|
298
|
+
reply,
|
|
299
|
+
holdOrigin: "mcp:delete",
|
|
300
|
+
});
|
|
301
|
+
if (!parsed.ok) return sendParseFailure(reply, parsed);
|
|
302
|
+
try {
|
|
303
|
+
const result = runtime.removeServer(name, parsed.scope);
|
|
304
|
+
if (!result.ok) return sendRefusal(reply, result.refusal);
|
|
305
|
+
return { ok: true, removed: result.removed };
|
|
306
|
+
} finally {
|
|
307
|
+
releaseScope(parsed.scope);
|
|
308
|
+
}
|
|
174
309
|
});
|
|
175
310
|
|
|
176
311
|
fastify.put(`${PREFIX}/servers/:name/enabled`, guard, async (request, reply) => {
|
|
177
312
|
const name = pathName(request);
|
|
178
313
|
if (!name) return reply.code(400).send(INVALID_NAME);
|
|
179
314
|
const body = (request.body ?? {}) as ScopeInput & { enabled?: unknown };
|
|
180
|
-
const parsed = parseScope(body, knownCwds);
|
|
181
|
-
if (!parsed.ok) return reply.code(parsed.status).send(parsed.body);
|
|
182
315
|
if (typeof body.enabled !== "boolean") {
|
|
183
316
|
return reply.code(400).send({ error: "invalid-body", message: "`enabled` must be a boolean" });
|
|
184
317
|
}
|
|
185
|
-
const
|
|
186
|
-
if (!
|
|
187
|
-
|
|
318
|
+
const parsed = await parseScope(body, deps, { request, reply, holdOrigin: "mcp:enable" });
|
|
319
|
+
if (!parsed.ok) return sendParseFailure(reply, parsed);
|
|
320
|
+
try {
|
|
321
|
+
const result = runtime.setEnabled(name, body.enabled, parsed.scope);
|
|
322
|
+
if (!result.ok) return sendRefusal(reply, result.refusal);
|
|
323
|
+
return result;
|
|
324
|
+
} finally {
|
|
325
|
+
releaseScope(parsed.scope);
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
fastify.put(`${PREFIX}/servers/:name/project-override`, guard, async (request, reply) => {
|
|
330
|
+
const name = pathName(request);
|
|
331
|
+
if (!name) return reply.code(400).send(INVALID_NAME);
|
|
332
|
+
const body = (request.body ?? {}) as ScopeInput & Record<string, unknown>;
|
|
333
|
+
// Every field's type and enum is checked before the scope is parsed, so a bad
|
|
334
|
+
// body can neither reveal whether a folder is admitted nor raise a dialog.
|
|
335
|
+
const checked = overridePatchOf(body);
|
|
336
|
+
if (!checked.ok) return reply.code(400).send(checked.body);
|
|
337
|
+
const patch = checked.patch;
|
|
338
|
+
if (body.scope !== "project") {
|
|
339
|
+
return reply.code(400).send({ error: "invalid-body", message: "a project override requires scope 'project'" });
|
|
340
|
+
}
|
|
341
|
+
const parsed = await parseScope(body, deps, { request, reply, holdOrigin: "mcp:enable" });
|
|
342
|
+
if (!parsed.ok) return sendParseFailure(reply, parsed);
|
|
343
|
+
try {
|
|
344
|
+
const result = runtime.setProjectOverride(name, patch, parsed.scope);
|
|
345
|
+
if (!result.ok) return sendRefusal(reply, result.refusal);
|
|
346
|
+
return result.override === undefined ? { ok: true, removed: true } : { ok: true, override: result.override };
|
|
347
|
+
} finally {
|
|
348
|
+
releaseScope(parsed.scope);
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
fastify.post(`${PREFIX}/servers/:name/convert-to-override`, guard, async (request, reply) => {
|
|
353
|
+
const name = pathName(request);
|
|
354
|
+
if (!name) return reply.code(400).send(INVALID_NAME);
|
|
355
|
+
const body = (request.body ?? {}) as ScopeInput;
|
|
356
|
+
if (body.scope !== "project") {
|
|
357
|
+
return reply.code(400).send({ error: "invalid-body", message: "converting a folder copy requires scope 'project'" });
|
|
358
|
+
}
|
|
359
|
+
const parsed = await parseScope(body, deps, { request, reply, holdOrigin: "mcp:convert" });
|
|
360
|
+
if (!parsed.ok) return sendParseFailure(reply, parsed);
|
|
361
|
+
try {
|
|
362
|
+
const result = runtime.convertLegacyCopy(name, parsed.scope);
|
|
363
|
+
if (!result.ok) return sendRefusal(reply, result.refusal);
|
|
364
|
+
return { ok: true, previous: result.previous };
|
|
365
|
+
} finally {
|
|
366
|
+
releaseScope(parsed.scope);
|
|
367
|
+
}
|
|
188
368
|
});
|
|
189
369
|
|
|
190
370
|
fastify.post(`${PREFIX}/servers/:name/convert`, guard, async (request, reply) => {
|
|
191
371
|
const name = pathName(request);
|
|
192
372
|
if (!name) return reply.code(400).send(INVALID_NAME);
|
|
193
|
-
const parsed = parseScope((request.body ?? {}) as ScopeInput,
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
373
|
+
const parsed = await parseScope((request.body ?? {}) as ScopeInput, deps, {
|
|
374
|
+
request,
|
|
375
|
+
reply,
|
|
376
|
+
holdOrigin: "mcp:convert",
|
|
377
|
+
});
|
|
378
|
+
if (!parsed.ok) return sendParseFailure(reply, parsed);
|
|
379
|
+
try {
|
|
380
|
+
const result = runtime.convertAdapterLeftovers(name, parsed.scope);
|
|
381
|
+
if (!result.ok) return sendRefusal(reply, result.refusal);
|
|
382
|
+
return { ok: true };
|
|
383
|
+
} finally {
|
|
384
|
+
releaseScope(parsed.scope);
|
|
385
|
+
}
|
|
198
386
|
});
|
|
199
387
|
}
|