@blackbelt-technology/pi-dashboard-mcp-client-plugin 0.9.0 → 0.11.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 +1 -1
- package/package.json +9 -4
- package/src/client/FolderMcpPage.tsx +207 -45
- package/src/client/FolderMcpSection.tsx +5 -4
- package/src/client/McpSettings.tsx +56 -39
- package/src/client/ProjectSettings.tsx +217 -0
- package/src/client/ServerEditor.tsx +2 -2
- package/src/client/ServerList.tsx +431 -170
- package/src/client/api.ts +52 -2
- package/src/client/folder-view.ts +30 -8
- package/src/client/hooks.ts +40 -5
- package/src/client/index.tsx +0 -2
- package/src/client/schema.ts +1 -1
- package/src/client/settings-ui.ts +19 -0
- package/src/core/index.ts +8 -66
- package/src/server/index.ts +26 -4
- package/src/server/pi-runner.ts +1 -1
- package/src/server/routes.ts +238 -50
- package/schema/mcp-config.schema.json +0 -54
- package/src/core/config-io.ts +0 -70
- package/src/core/config-writer.ts +0 -407
- package/src/core/effective-view.ts +0 -197
- package/src/core/layers.ts +0 -61
- package/src/core/live-state.ts +0 -134
- package/src/core/path-utils.ts +0 -29
- package/src/core/pi-rules.ts +0 -220
- package/src/core/schema-validation.ts +0 -52
- package/src/core/service.ts +0 -96
- package/src/core/types.ts +0 -200
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 { isValidServerName, OVERRIDE_KEYS } from "@blackbelt-technology/pi-dashboard-mcp-core/pi-rules.js";
|
|
26
|
+
import { errorFields, mcpConfigSchema, validateServerEntry } from "@blackbelt-technology/pi-dashboard-mcp-core/schema-validation.js";
|
|
27
|
+
import type { McpClientRuntime } from "@blackbelt-technology/pi-dashboard-mcp-core/service.js";
|
|
28
|
+
import type { ConfigRefusal, ProjectOverridePatch, Scope, ServerEntry } from "@blackbelt-technology/pi-dashboard-mcp-core/types.js";
|
|
29
|
+
import {
|
|
30
|
+
type AdmitCwdOptions,
|
|
31
|
+
admissionAllows,
|
|
32
|
+
admitCwd,
|
|
33
|
+
issueHeldAdmission,
|
|
34
|
+
releaseAdmission,
|
|
35
|
+
} from "@blackbelt-technology/pi-dashboard-shared/cwd-guard.js";
|
|
23
36
|
import type { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
|
|
24
|
-
import { isValidServerName } from "../core/pi-rules.js";
|
|
25
|
-
import { errorFields, mcpConfigSchema, validateServerEntry } from "../core/schema-validation.js";
|
|
26
|
-
import type { McpClientRuntime } from "../core/service.js";
|
|
27
|
-
import type { ConfigRefusal, 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
|
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
-
"$id": "https://pi-dashboard.local/schemas/mcp-config.schema.json",
|
|
4
|
-
"title": "pi built-in MCP server entry",
|
|
5
|
-
"description": "Hand-authored from pi 1.0.0 dist/core/mcp-servers.d.ts (McpServerConfig). Describes one `mcpServers.<name>` entry of ~/.pi/agent/mcp.json or <cwd>/.pi/mcp.json so the dashboard client can render editors without hard-coding field lists. Annotations: x-transport marks the two mutually exclusive transports (command xor url); x-secret marks credential-bearing fields (masked in the editor, redacted when inherited, omitted from folder copies); x-global-only marks fields pi reads only from the global file. The writer additionally mirrors pi's validateMcpServerConfig rules (pi-rules.ts).",
|
|
6
|
-
"$defs": {
|
|
7
|
-
"Exposure": {
|
|
8
|
-
"enum": ["codemode", "deferred", "direct", "hidden", "codemode-deferred"],
|
|
9
|
-
"description": "How the server's tools reach the model. Default codemode. codemode-deferred is pi's legacy alias of codemode, accepted on read and preserved."
|
|
10
|
-
},
|
|
11
|
-
"OAuthConfig": {
|
|
12
|
-
"type": "object",
|
|
13
|
-
"additionalProperties": true,
|
|
14
|
-
"properties": {
|
|
15
|
-
"clientId": { "type": "string" },
|
|
16
|
-
"clientSecret": { "type": "string", "x-secret": true },
|
|
17
|
-
"callbackPort": { "type": "integer", "minimum": 1, "maximum": 65535 },
|
|
18
|
-
"callbackUrl": { "type": "string" },
|
|
19
|
-
"scope": { "type": "string" },
|
|
20
|
-
"clientName": { "type": "string", "minLength": 1 },
|
|
21
|
-
"authServerMetadataUrl": { "type": "string" }
|
|
22
|
-
}
|
|
23
|
-
},
|
|
24
|
-
"AuthConfig": {
|
|
25
|
-
"type": "object",
|
|
26
|
-
"additionalProperties": true,
|
|
27
|
-
"required": ["provider"],
|
|
28
|
-
"properties": {
|
|
29
|
-
"provider": { "type": "string", "minLength": 1 }
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
"ServerEntry": {
|
|
33
|
-
"type": "object",
|
|
34
|
-
"additionalProperties": true,
|
|
35
|
-
"description": "One pi MCP server entry: stdio (command) or streamable HTTP (url).",
|
|
36
|
-
"properties": {
|
|
37
|
-
"type": { "enum": ["stdio", "http", "streamable-http"] },
|
|
38
|
-
"description": { "type": "string" },
|
|
39
|
-
"command": { "type": "string", "x-transport": "command" },
|
|
40
|
-
"args": { "type": "array", "items": { "type": "string" } },
|
|
41
|
-
"env": { "type": "object", "additionalProperties": { "type": "string" }, "x-secret": true },
|
|
42
|
-
"cwd": { "type": "string" },
|
|
43
|
-
"url": { "type": "string", "x-transport": "url" },
|
|
44
|
-
"headers": { "type": "object", "additionalProperties": { "type": "string" }, "x-secret": true },
|
|
45
|
-
"oauth": { "$ref": "#/$defs/OAuthConfig" },
|
|
46
|
-
"auth": { "$ref": "#/$defs/AuthConfig", "x-global-only": true },
|
|
47
|
-
"exposure": { "$ref": "#/$defs/Exposure" },
|
|
48
|
-
"toolExposure": { "type": "object", "additionalProperties": { "$ref": "#/$defs/Exposure" } },
|
|
49
|
-
"timeout": { "type": "number", "exclusiveMinimum": 0 },
|
|
50
|
-
"enabled": { "type": "boolean" }
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
package/src/core/config-io.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* mcp-client-plugin · real filesystem ConfigIO.
|
|
3
|
-
*
|
|
4
|
-
* The hardened atomic write moved here from `apple-tools/src/env.ts` so the
|
|
5
|
-
* core owns it and every consumer (dashboard server, hostless installer CLI)
|
|
6
|
-
* shares one implementation:
|
|
7
|
-
* - `wx` + a random name: never follow or clobber a pre-planted symlink.
|
|
8
|
-
* - mode 0600: a rename carries the temp file's mode onto the destination.
|
|
9
|
-
* - fsync before rename: no zero-length config after a crash.
|
|
10
|
-
* - unlink the temp on failure: no leftovers on ENOSPC/EACCES.
|
|
11
|
-
*
|
|
12
|
-
* See change: extract-mcp-client-plugin (task 2.1).
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
import { randomBytes } from "node:crypto";
|
|
16
|
-
import {
|
|
17
|
-
closeSync,
|
|
18
|
-
existsSync,
|
|
19
|
-
fsyncSync,
|
|
20
|
-
mkdirSync,
|
|
21
|
-
openSync,
|
|
22
|
-
readFileSync,
|
|
23
|
-
renameSync,
|
|
24
|
-
unlinkSync,
|
|
25
|
-
writeSync,
|
|
26
|
-
} from "node:fs";
|
|
27
|
-
import { dirname, join } from "node:path";
|
|
28
|
-
import type { ConfigIO } from "./types.js";
|
|
29
|
-
|
|
30
|
-
export function writeFileAtomic(path: string, content: string): void {
|
|
31
|
-
const dir = dirname(path);
|
|
32
|
-
mkdirSync(dir, { recursive: true });
|
|
33
|
-
const tmp = join(dir, `.${randomBytes(8).toString("hex")}.tmp`);
|
|
34
|
-
const fd = openSync(tmp, "wx", 0o600);
|
|
35
|
-
try {
|
|
36
|
-
const buf = Buffer.from(content, "utf8");
|
|
37
|
-
let off = 0;
|
|
38
|
-
while (off < buf.length) {
|
|
39
|
-
off += writeSync(fd, buf, off, buf.length - off);
|
|
40
|
-
}
|
|
41
|
-
fsyncSync(fd);
|
|
42
|
-
} catch (e) {
|
|
43
|
-
closeSync(fd);
|
|
44
|
-
try {
|
|
45
|
-
unlinkSync(tmp);
|
|
46
|
-
} catch {
|
|
47
|
-
/* best effort */
|
|
48
|
-
}
|
|
49
|
-
throw e;
|
|
50
|
-
}
|
|
51
|
-
closeSync(fd);
|
|
52
|
-
try {
|
|
53
|
-
renameSync(tmp, path);
|
|
54
|
-
} catch (e) {
|
|
55
|
-
try {
|
|
56
|
-
unlinkSync(tmp);
|
|
57
|
-
} catch {
|
|
58
|
-
/* best effort */
|
|
59
|
-
}
|
|
60
|
-
throw e;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/** A ConfigIO wired to the real filesystem. */
|
|
65
|
-
export function createRealConfigIO(): ConfigIO {
|
|
66
|
-
return {
|
|
67
|
-
readFile: (p) => (existsSync(p) ? readFileSync(p, "utf8") : null),
|
|
68
|
-
writeFileAtomic,
|
|
69
|
-
};
|
|
70
|
-
}
|