@blackbelt-technology/pi-dashboard-mcp-client-plugin 0.9.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
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* mcp-client-plugin · CORE effective-view reader over pi's two MCP layers.
|
|
3
3
|
*
|
|
4
|
-
* Mirrors pi 1.
|
|
4
|
+
* Mirrors pi 1.1.0 `loadMcpConfig`: the Pi-global layer loads first, then —
|
|
5
5
|
* only when pi trusts the project — `<cwd>/.pi/mcp.json`, whose entries
|
|
6
|
-
* REPLACE global entries of the same name as a whole
|
|
6
|
+
* REPLACE global entries of the same name as a whole, except an entry with no
|
|
7
|
+
* `command`/`url`/`type`: a project OVERRIDE of `enabled`/`exposure`/
|
|
8
|
+
* `toolExposure` merged onto the kept global entry (one row). Each entry is checked
|
|
7
9
|
* with the mirrored pi rules; an entry pi would reject or drop (invalid,
|
|
8
10
|
* `-`/`_` collision, project `auth`) is shown inactive with pi's message. An
|
|
9
11
|
* untrusted project's entries are shown inactive ("project not trusted").
|
|
@@ -13,21 +15,25 @@
|
|
|
13
15
|
* `{redacted}`) — the folder surface must never receive an inherited
|
|
14
16
|
* credential. Own-layer entries are returned verbatim (the client masks them).
|
|
15
17
|
*
|
|
16
|
-
* See change: migrate-mcp-to-pi-builtin (D3);
|
|
18
|
+
* See change: migrate-mcp-to-pi-builtin (D3); mcp-client-project-overrides (D1-D3);
|
|
19
|
+
* earlier: extract-mcp-client-plugin.
|
|
17
20
|
*/
|
|
18
21
|
|
|
22
|
+
import { isLegacyFolderCopy } from "./config-writer.js";
|
|
19
23
|
import { type LayerPaths, readLayer } from "./layers.js";
|
|
20
24
|
import { getByName, isPlainObject, setByName } from "./path-utils.js";
|
|
21
25
|
import {
|
|
22
26
|
adapterLeftovers,
|
|
23
27
|
authModeOf,
|
|
28
|
+
classifyProjectEntry,
|
|
24
29
|
displayExposure,
|
|
25
30
|
ignoredKeys,
|
|
31
|
+
keptGlobalOf,
|
|
26
32
|
mcpNamespace,
|
|
27
33
|
transportOf,
|
|
28
34
|
validatePiEntry,
|
|
29
35
|
} from "./pi-rules.js";
|
|
30
|
-
import type { ConfigIO, EffectiveServerView, EffectiveView, LayerStatus, Provenance, Scope } from "./types.js";
|
|
36
|
+
import type { ConfigIO, EffectiveServerView, EffectiveView, LayerStatus, ProjectTrustSource, Provenance, Scope } from "./types.js";
|
|
31
37
|
|
|
32
38
|
/** Credential-name pattern for record keys (key NAMES are never secret). */
|
|
33
39
|
export function isSecretKey(name: string): boolean {
|
|
@@ -62,10 +68,26 @@ export function redactEntry(entry: Record<string, unknown>): Record<string, unkn
|
|
|
62
68
|
return out;
|
|
63
69
|
}
|
|
64
70
|
|
|
71
|
+
function trustExtras(deps: EffectiveViewDeps, cwd: string): Pick<EffectiveView, "trustSource" | "trustCoverInteractive"> {
|
|
72
|
+
const out: Pick<EffectiveView, "trustSource" | "trustCoverInteractive"> = {};
|
|
73
|
+
try {
|
|
74
|
+
const source = deps.projectTrustSource?.(cwd);
|
|
75
|
+
if (source) out.trustSource = source;
|
|
76
|
+
if (deps.coverInteractive) out.trustCoverInteractive = deps.coverInteractive();
|
|
77
|
+
} catch {
|
|
78
|
+
/* additive disclosure only: never fails the view */
|
|
79
|
+
}
|
|
80
|
+
return out;
|
|
81
|
+
}
|
|
82
|
+
|
|
65
83
|
export interface EffectiveViewDeps {
|
|
66
84
|
configIO: ConfigIO;
|
|
67
85
|
paths: LayerPaths;
|
|
68
86
|
isProjectTrusted?: (cwd: string) => boolean;
|
|
87
|
+
/** Optional: who decided the trust (absent → `trustSource` omitted). */
|
|
88
|
+
projectTrustSource?: (cwd: string) => ProjectTrustSource | undefined;
|
|
89
|
+
/** Optional: `piTrustMirror.coverInteractive` (absent → omitted). */
|
|
90
|
+
coverInteractive?: () => boolean;
|
|
69
91
|
}
|
|
70
92
|
|
|
71
93
|
export interface EffectiveViewReader {
|
|
@@ -121,15 +143,16 @@ export function createEffectiveViewReader(deps: EffectiveViewDeps): EffectiveVie
|
|
|
121
143
|
const isProject = scope.kind === "project";
|
|
122
144
|
|
|
123
145
|
// Global layer, in pi's load order (collisions within the file: first wins).
|
|
146
|
+
// `keptGlobalOf` is the one definition of "kept" the writer shares.
|
|
124
147
|
const byName = new Map<string, EffectiveServerView>();
|
|
125
148
|
const loadedNs = new Map<string, string>(); // namespace → loaded name
|
|
149
|
+
const { kept, collisions } = keptGlobalOf(g.ok ? g.servers : {});
|
|
126
150
|
if (g.ok) {
|
|
127
151
|
for (const [name, raw] of Object.entries(g.servers)) {
|
|
128
152
|
const v = describe(name, raw, "pi-global", isProject);
|
|
129
|
-
if (
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
else loadedNs.set(mcpNamespace(name), name);
|
|
153
|
+
if (kept.has(name)) loadedNs.set(mcpNamespace(name), name);
|
|
154
|
+
else if (collisions.has(name)) {
|
|
155
|
+
deactivate(v, "name-collision", `server "${name}" conflicts with "${collisions.get(name)}"`);
|
|
133
156
|
}
|
|
134
157
|
byName.set(name, v);
|
|
135
158
|
}
|
|
@@ -148,7 +171,13 @@ export function createEffectiveViewReader(deps: EffectiveViewDeps): EffectiveVie
|
|
|
148
171
|
const folderRows: EffectiveServerView[] = [];
|
|
149
172
|
if (pl.ok) {
|
|
150
173
|
for (const [name, raw] of Object.entries(pl.servers)) {
|
|
174
|
+
const cls = classifyProjectEntry(name, raw, kept);
|
|
151
175
|
const v = describe(name, raw, "pi-folder", false);
|
|
176
|
+
if (cls.kind !== "replace") {
|
|
177
|
+
// override-shaped: classified below, never "needs command or url"
|
|
178
|
+
delete v.piError;
|
|
179
|
+
delete v.inactiveReason;
|
|
180
|
+
}
|
|
152
181
|
const global = byName.get(name);
|
|
153
182
|
if (!trusted) {
|
|
154
183
|
// pi never reads this file: the global entry (if any) stays in effect.
|
|
@@ -156,6 +185,27 @@ export function createEffectiveViewReader(deps: EffectiveViewDeps): EffectiveVie
|
|
|
156
185
|
folderRows.push(v);
|
|
157
186
|
continue;
|
|
158
187
|
}
|
|
188
|
+
if (cls.kind === "orphan" || cls.kind === "bad-keys" || cls.kind === "invalid") {
|
|
189
|
+
// pi reports the message and applies nothing: the global entry (if any) is unchanged.
|
|
190
|
+
deactivate(v, "invalid-entry", cls.message);
|
|
191
|
+
v.overrideIssue = cls.kind;
|
|
192
|
+
folderRows.push(v);
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
if (cls.kind === "override") {
|
|
196
|
+
// One row: the global server, merged, redacted like any global row in a project view.
|
|
197
|
+
const merged = describe(name, cls.merged, "pi-global", true);
|
|
198
|
+
const raw2 = raw as Record<string, unknown>;
|
|
199
|
+
const base = kept.get(name) as Record<string, unknown>;
|
|
200
|
+
merged.projectOverride = {
|
|
201
|
+
path: projectPath,
|
|
202
|
+
keys: cls.keys,
|
|
203
|
+
raw: { ...raw2 },
|
|
204
|
+
inherited: { enabled: base.enabled !== false, exposure: displayExposure(base.exposure) },
|
|
205
|
+
};
|
|
206
|
+
byName.set(name, merged);
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
159
209
|
if (v.piError) {
|
|
160
210
|
// pi drops an invalid project entry; the global one stays in effect.
|
|
161
211
|
folderRows.push(v);
|
|
@@ -174,7 +224,10 @@ export function createEffectiveViewReader(deps: EffectiveViewDeps): EffectiveVie
|
|
|
174
224
|
continue;
|
|
175
225
|
}
|
|
176
226
|
}
|
|
177
|
-
if (global)
|
|
227
|
+
if (global) {
|
|
228
|
+
v.overridesGlobal = true;
|
|
229
|
+
if (isLegacyFolderCopy(raw, kept.get(name))) v.legacyCopy = true;
|
|
230
|
+
}
|
|
178
231
|
loadedNs.set(mcpNamespace(name), name);
|
|
179
232
|
byName.set(name, v); // whole-entry replace
|
|
180
233
|
}
|
|
@@ -184,6 +237,7 @@ export function createEffectiveViewReader(deps: EffectiveViewDeps): EffectiveVie
|
|
|
184
237
|
scope: "project",
|
|
185
238
|
cwd,
|
|
186
239
|
trusted,
|
|
240
|
+
...trustExtras(deps, cwd),
|
|
187
241
|
servers: sortByName([...byName.values(), ...folderRows]),
|
|
188
242
|
layers,
|
|
189
243
|
};
|
package/src/core/index.ts
CHANGED
|
@@ -14,6 +14,7 @@ export {
|
|
|
14
14
|
createConfigWriter,
|
|
15
15
|
FOLDER_COPY_OMITTED,
|
|
16
16
|
folderCopyOf,
|
|
17
|
+
isLegacyFolderCopy,
|
|
17
18
|
NotAllowedCwdError,
|
|
18
19
|
} from "./config-writer.js";
|
|
19
20
|
export {
|
|
@@ -34,13 +35,20 @@ export {
|
|
|
34
35
|
ADAPTER_ONLY_KEYS,
|
|
35
36
|
adapterLeftovers,
|
|
36
37
|
authModeOf,
|
|
38
|
+
classifyProjectEntry,
|
|
37
39
|
displayExposure,
|
|
38
40
|
ignoredKeys,
|
|
41
|
+
isFullEntry,
|
|
42
|
+
isProjectOverride,
|
|
39
43
|
isValidServerName,
|
|
44
|
+
type KeptGlobal,
|
|
45
|
+
keptGlobalOf,
|
|
40
46
|
MCP_EXPOSURE_ALIASES,
|
|
41
47
|
MCP_EXPOSURES,
|
|
42
48
|
type McpExposure,
|
|
43
49
|
mcpNamespace,
|
|
50
|
+
OVERRIDE_KEYS,
|
|
51
|
+
type ProjectEntryClass,
|
|
44
52
|
transportOf,
|
|
45
53
|
validatePiEntry,
|
|
46
54
|
} from "./pi-rules.js";
|
|
@@ -52,6 +60,7 @@ export type {
|
|
|
52
60
|
ConfigRefusal,
|
|
53
61
|
ConfigRefusalCode,
|
|
54
62
|
ConfigWriteResult,
|
|
63
|
+
ConvertLegacyResult,
|
|
55
64
|
EffectiveServerView,
|
|
56
65
|
EffectiveView,
|
|
57
66
|
InactiveReason,
|
|
@@ -59,8 +68,11 @@ export type {
|
|
|
59
68
|
LiveServerState,
|
|
60
69
|
LiveState,
|
|
61
70
|
McpClientConfigService,
|
|
71
|
+
OverrideIssue,
|
|
62
72
|
ParseStatus,
|
|
63
73
|
PiMcpListRunner,
|
|
74
|
+
ProjectOverridePatch,
|
|
75
|
+
ProjectOverrideResult,
|
|
64
76
|
Provenance,
|
|
65
77
|
RemoveResult,
|
|
66
78
|
Scope,
|
package/src/core/path-utils.ts
CHANGED
|
@@ -27,3 +27,15 @@ export function setByName(obj: Record<string, unknown>, path: string[], value: u
|
|
|
27
27
|
}
|
|
28
28
|
cur[path[path.length - 1]] = value;
|
|
29
29
|
}
|
|
30
|
+
|
|
31
|
+
/** Structural JSON equality (plain objects, arrays, primitives). */
|
|
32
|
+
export function deepEqual(a: unknown, b: unknown): boolean {
|
|
33
|
+
if (a === b) return true;
|
|
34
|
+
if (Array.isArray(a) && Array.isArray(b)) return a.length === b.length && a.every((v, i) => deepEqual(v, b[i]));
|
|
35
|
+
if (isPlainObject(a) && isPlainObject(b)) {
|
|
36
|
+
const ka = Object.keys(a);
|
|
37
|
+
const kb = Object.keys(b);
|
|
38
|
+
return ka.length === kb.length && ka.every((k) => Object.hasOwn(b, k) && deepEqual(a[k], b[k]));
|
|
39
|
+
}
|
|
40
|
+
return false;
|
|
41
|
+
}
|
package/src/core/pi-rules.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* mcp-client-plugin · CORE mirror of pi's built-in MCP entry rules.
|
|
3
3
|
*
|
|
4
|
-
* pi 1.
|
|
4
|
+
* pi 1.1.0 does not export `validateMcpServerConfig` (its exports map has
|
|
5
5
|
* only `.`, `./rpc-entry`, `./client`, `./experimental/plugin`) and this
|
|
6
6
|
* package has no pi dependency, so the checks are mirrored here from
|
|
7
7
|
* `dist/core/mcp-servers.js` + `dist/extensions/mcp/config.js`. The writer
|
|
8
8
|
* runs them before every write so it never persists an entry pi rejects.
|
|
9
9
|
*
|
|
10
|
-
* See change: migrate-mcp-to-pi-builtin (D3 "Validation").
|
|
10
|
+
* See change: migrate-mcp-to-pi-builtin (D3 "Validation"); mcp-client-project-overrides (D1).
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import { isPlainObject } from "./path-utils.js";
|
|
@@ -128,7 +128,7 @@ function validateOAuth(value: unknown): string | undefined {
|
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
/**
|
|
131
|
-
* Mirror of pi 1.
|
|
131
|
+
* Mirror of pi 1.1.0 `validateMcpServerConfig(name, raw)`: `null` when pi
|
|
132
132
|
* accepts the entry, else pi's error message.
|
|
133
133
|
*/
|
|
134
134
|
export function validatePiEntry(name: string, raw: unknown): string | null {
|
|
@@ -218,3 +218,80 @@ export function authModeOf(entry: Record<string, unknown>): AuthMode | undefined
|
|
|
218
218
|
}
|
|
219
219
|
return { kind: "oauth" };
|
|
220
220
|
}
|
|
221
|
+
|
|
222
|
+
/** The only keys a project override may set (pi 1.1.0 `OVERRIDE_KEYS`). */
|
|
223
|
+
export const OVERRIDE_KEYS = ["enabled", "exposure", "toolExposure"] as const;
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* pi's `isOverride`: an entry that defines no server of its own. Strictly
|
|
227
|
+
* `=== undefined` — `null` and `""` count as SET, so `{url: null}` is a
|
|
228
|
+
* (broken) whole entry, never an override.
|
|
229
|
+
*/
|
|
230
|
+
export function isProjectOverride(value: unknown): value is Record<string, unknown> {
|
|
231
|
+
return isPlainObject(value) && value.command === undefined && value.url === undefined && value.type === undefined;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/** A *full* entry: a string `command` or a string `url`. */
|
|
235
|
+
export function isFullEntry(value: unknown): value is Record<string, unknown> {
|
|
236
|
+
return isPlainObject(value) && (typeof value.command === "string" || typeof value.url === "string");
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/** The global entries pi keeps: valid, and first-wins on a `-`/`_` namespace clash. */
|
|
240
|
+
export interface KeptGlobal {
|
|
241
|
+
kept: Map<string, Record<string, unknown>>;
|
|
242
|
+
/** Valid entries dropped as a namespace collision → the name that won. */
|
|
243
|
+
collisions: Map<string, string>;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* pi's global pass (`config.js:83-93`): an invalid or colliding global entry is
|
|
248
|
+
* never stored, so it can never be an override base. The effective view and
|
|
249
|
+
* every writer share this one function.
|
|
250
|
+
*/
|
|
251
|
+
export function keptGlobalOf(servers: Record<string, unknown>): KeptGlobal {
|
|
252
|
+
const kept = new Map<string, Record<string, unknown>>();
|
|
253
|
+
const collisions = new Map<string, string>();
|
|
254
|
+
const loadedNs = new Map<string, string>();
|
|
255
|
+
for (const [name, raw] of Object.entries(servers)) {
|
|
256
|
+
if (validatePiEntry(name, raw) !== null) continue;
|
|
257
|
+
const clash = loadedNs.get(mcpNamespace(name));
|
|
258
|
+
if (clash !== undefined && clash !== name) {
|
|
259
|
+
collisions.set(name, clash);
|
|
260
|
+
continue;
|
|
261
|
+
}
|
|
262
|
+
loadedNs.set(mcpNamespace(name), name);
|
|
263
|
+
kept.set(name, raw as Record<string, unknown>);
|
|
264
|
+
}
|
|
265
|
+
return { kept, collisions };
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
export type ProjectEntryClass =
|
|
269
|
+
| { kind: "replace" }
|
|
270
|
+
| { kind: "orphan"; message: string }
|
|
271
|
+
| { kind: "bad-keys"; message: string }
|
|
272
|
+
| { kind: "invalid"; message: string }
|
|
273
|
+
| { kind: "override"; merged: Record<string, unknown>; keys: string[] };
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* pi 1.1.0's project pass for one entry (`config.js:65-82`). Messages are pi's
|
|
277
|
+
* text without the `<path>: ` prefix.
|
|
278
|
+
*/
|
|
279
|
+
export function classifyProjectEntry(
|
|
280
|
+
name: string,
|
|
281
|
+
value: unknown,
|
|
282
|
+
keptGlobal?: ReadonlyMap<string, Record<string, unknown>>,
|
|
283
|
+
): ProjectEntryClass {
|
|
284
|
+
if (!isProjectOverride(value)) return { kind: "replace" };
|
|
285
|
+
const base = keptGlobal?.get(name);
|
|
286
|
+
if (!base) {
|
|
287
|
+
return { kind: "orphan", message: `server "${name}" needs "command" or "url", or a global server to override` };
|
|
288
|
+
}
|
|
289
|
+
const extra = Object.keys(value).filter((k) => !(OVERRIDE_KEYS as readonly string[]).includes(k));
|
|
290
|
+
if (extra.length > 0) {
|
|
291
|
+
return { kind: "bad-keys", message: `server "${name}": an override can only set ${OVERRIDE_KEYS.join(", ")}` };
|
|
292
|
+
}
|
|
293
|
+
const merged = { ...base, ...value };
|
|
294
|
+
const invalid = validatePiEntry(name, merged);
|
|
295
|
+
if (invalid) return { kind: "invalid", message: invalid };
|
|
296
|
+
return { kind: "override", merged, keys: Object.keys(value) };
|
|
297
|
+
}
|
|
@@ -37,15 +37,20 @@ function compile(ref: string): ValidateFunction {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
const validateServer = compile("ServerEntry");
|
|
40
|
+
const validateOverride = compile("ProjectOverride");
|
|
40
41
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
/** `kind` picks the `$defs` entry: a whole `"server"` entry (default) or a `"override"` (D8). */
|
|
43
|
+
export function validateServerEntry(entry: unknown, opts?: { kind?: "server" | "override" }): PatchValidation {
|
|
44
|
+
const fn = opts?.kind === "override" ? validateOverride : validateServer;
|
|
45
|
+
const valid = fn(entry) as boolean;
|
|
46
|
+
return { ok: valid, errors: valid ? [] : (fn.errors ?? []) };
|
|
44
47
|
}
|
|
45
48
|
|
|
46
|
-
/** Field names from Ajv errors (drop the leading slash of `instancePath`). */
|
|
49
|
+
/** Field names from Ajv errors (drop the leading slash of `instancePath`; an `additionalProperties` refusal names the offending key). */
|
|
47
50
|
export function errorFields(errors: ErrorObject[]): string[] {
|
|
48
|
-
return errors
|
|
51
|
+
return errors
|
|
52
|
+
.map((e) => e.instancePath.replace(/^\//, "").split("/")[0] || String(e.params?.additionalProperty ?? ""))
|
|
53
|
+
.filter((f) => f.length > 0);
|
|
49
54
|
}
|
|
50
55
|
|
|
51
56
|
/** Exposed for the compile-contract test and the schema route. */
|
package/src/core/service.ts
CHANGED
|
@@ -17,13 +17,26 @@ import { createConfigWriter } from "./config-writer.js";
|
|
|
17
17
|
import { createEffectiveViewReader } from "./effective-view.js";
|
|
18
18
|
import { defaultLayerPaths, type LayerPaths } from "./layers.js";
|
|
19
19
|
import { createLiveStateReader } from "./live-state.js";
|
|
20
|
-
import type { ConfigIO, LiveState, McpClientConfigService, PiMcpListRunner, Scope } from "./types.js";
|
|
20
|
+
import type { ConfigIO, LiveState, McpClientConfigService, PiMcpListRunner, ProjectTrustSource, Scope } from "./types.js";
|
|
21
21
|
|
|
22
22
|
export interface McpClientConfigServiceDeps {
|
|
23
23
|
configIO: ConfigIO;
|
|
24
24
|
knownCwds: () => string[];
|
|
25
25
|
/** pi's project-trust rule (`host.isProjectTrusted`). Absent → untrusted. */
|
|
26
26
|
isProjectTrusted?: (cwd: string) => boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Who decided the trust (`host.projectTrustSource`). Absent → the view omits the
|
|
29
|
+
* source and a dashboard-only trust cannot be told apart (no "not checked by pi").
|
|
30
|
+
*/
|
|
31
|
+
projectTrustSource?: (cwd: string) => ProjectTrustSource | undefined;
|
|
32
|
+
/** `piTrustMirror.coverInteractive` (for the folder page's scope sentence). */
|
|
33
|
+
coverInteractive?: () => boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Trust by pi alone (ignores dashboard trust) — decides which GLOBAL writes
|
|
36
|
+
* collide with a folder entry, so dashboard trust never changes that set.
|
|
37
|
+
* Absent → derived from `isProjectTrusted` + `projectTrustSource`.
|
|
38
|
+
*/
|
|
39
|
+
isProjectTrustedByPi?: (cwd: string) => boolean;
|
|
27
40
|
/** Layer paths. Defaults to `$PI_CODING_AGENT_DIR/mcp.json` + `<cwd>/.pi/mcp.json`. */
|
|
28
41
|
paths?: LayerPaths;
|
|
29
42
|
/** Runs `pi mcp list --json`. Absent → live state reports `spawn-failed`. */
|
|
@@ -39,18 +52,36 @@ export interface McpClientRuntime extends McpClientConfigService {
|
|
|
39
52
|
getLiveState(scope: Scope, opts?: { fresh?: boolean }): Promise<LiveState>;
|
|
40
53
|
}
|
|
41
54
|
|
|
55
|
+
/** Live state of a folder server trusted only by the dashboard. */
|
|
56
|
+
export const NOT_CHECKED_BY_PI = "not-checked-by-pi";
|
|
57
|
+
export const DASHBOARD_ONLY_NOTE =
|
|
58
|
+
"This folder is trusted by the dashboard only: running `pi mcp list` here (outside the dashboard) reports its servers as not loaded, because that command reads only pi's own trust store.";
|
|
59
|
+
|
|
60
|
+
/** A source that is not pi's own decision (dashboard trust is not pi trust). */
|
|
61
|
+
function trustedByPiOnly(deps: McpClientConfigServiceDeps): ((cwd: string) => boolean) | undefined {
|
|
62
|
+
if (deps.isProjectTrustedByPi) return deps.isProjectTrustedByPi;
|
|
63
|
+
const trusted = deps.isProjectTrusted;
|
|
64
|
+
if (!trusted) return undefined;
|
|
65
|
+
const source = deps.projectTrustSource;
|
|
66
|
+
return (cwd) => trusted(cwd) && source?.(cwd)?.kind !== "dashboard";
|
|
67
|
+
}
|
|
68
|
+
|
|
42
69
|
export function createMcpClientConfigService(deps: McpClientConfigServiceDeps): McpClientRuntime {
|
|
43
70
|
const paths = deps.paths ?? defaultLayerPaths();
|
|
71
|
+
const piOnly = trustedByPiOnly(deps);
|
|
44
72
|
const writer = createConfigWriter({
|
|
45
73
|
configIO: deps.configIO,
|
|
46
74
|
paths,
|
|
47
75
|
knownCwds: deps.knownCwds,
|
|
48
|
-
|
|
76
|
+
// Global-write collisions keep pi-only trust: dashboard trust never changes them.
|
|
77
|
+
...(piOnly ? { isProjectTrusted: piOnly } : {}),
|
|
49
78
|
});
|
|
50
79
|
const viewReader = createEffectiveViewReader({
|
|
51
80
|
configIO: deps.configIO,
|
|
52
81
|
paths,
|
|
53
82
|
...(deps.isProjectTrusted ? { isProjectTrusted: deps.isProjectTrusted } : {}),
|
|
83
|
+
...(deps.projectTrustSource ? { projectTrustSource: deps.projectTrustSource } : {}),
|
|
84
|
+
...(deps.coverInteractive ? { coverInteractive: deps.coverInteractive } : {}),
|
|
54
85
|
});
|
|
55
86
|
const runner: PiMcpListRunner =
|
|
56
87
|
deps.runner ?? (() => Promise.reject(new Error("no pi mcp list runner configured")));
|
|
@@ -73,6 +104,8 @@ export function createMcpClientConfigService(deps: McpClientConfigServiceDeps):
|
|
|
73
104
|
saveServer: (name, entry, scope, opts) => writer.saveServer(name, entry, scope, opts),
|
|
74
105
|
removeServer: (name, scope) => writer.removeServer(name, scope),
|
|
75
106
|
setEnabled: (name, enabled, scope) => writer.setEnabled(name, enabled, scope),
|
|
107
|
+
setProjectOverride: (name, patch, scope) => writer.setProjectOverride(name, patch, scope),
|
|
108
|
+
convertLegacyCopy: (name, scope) => writer.convertLegacyCopy(name, scope),
|
|
76
109
|
convertAdapterLeftovers: (name, scope) => writer.convertAdapterLeftovers(name, scope),
|
|
77
110
|
|
|
78
111
|
checkConfigFiles(opts) {
|
|
@@ -90,7 +123,19 @@ export function createMcpClientConfigService(deps: McpClientConfigServiceDeps):
|
|
|
90
123
|
getLiveState(scope, opts) {
|
|
91
124
|
const cwd = scope.kind === "project" ? scope.cwd : scratchCwd();
|
|
92
125
|
if (scope.kind === "project") writer.targetPath(scope); // admission
|
|
93
|
-
|
|
126
|
+
const read = live.read(cwd, opts);
|
|
127
|
+
if (scope.kind !== "project" || deps.projectTrustSource?.(cwd)?.kind !== "dashboard") return read;
|
|
128
|
+
// Trusted ONLY by the dashboard: `pi mcp list` reads just pi's own trust store
|
|
129
|
+
// (no approve flag), so it reports the folder's servers as not loaded. Report
|
|
130
|
+
// them as "not checked by pi" instead of disconnected.
|
|
131
|
+
return read.then((r) => {
|
|
132
|
+
if (!r.ok) return r;
|
|
133
|
+
const servers = { ...r.servers };
|
|
134
|
+
for (const s of viewReader.getEffectiveView(scope).servers) {
|
|
135
|
+
if (s.provenance === "pi-folder" && s.active) servers[s.name] = { state: NOT_CHECKED_BY_PI, tools: 0 };
|
|
136
|
+
}
|
|
137
|
+
return { ...r, servers, note: DASHBOARD_ONLY_NOTE };
|
|
138
|
+
});
|
|
94
139
|
},
|
|
95
140
|
};
|
|
96
141
|
}
|
package/src/core/types.ts
CHANGED
|
@@ -10,11 +10,12 @@
|
|
|
10
10
|
* See change: migrate-mcp-to-pi-builtin (D3); earlier: extract-mcp-client-plugin.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
+
import type { AdmissionToken } from "@blackbelt-technology/pi-dashboard-shared/cwd-guard.js";
|
|
13
14
|
import type { AuthMode } from "./pi-rules.js";
|
|
14
15
|
|
|
15
16
|
export type { AuthMode };
|
|
16
17
|
|
|
17
|
-
/** pi's MCP server entry (1.
|
|
18
|
+
/** pi's MCP server entry (1.1.0). Unknown keys are preserved, never dropped. */
|
|
18
19
|
export interface ServerEntry {
|
|
19
20
|
type?: "stdio" | "http" | "streamable-http" | string;
|
|
20
21
|
description?: string;
|
|
@@ -43,7 +44,20 @@ export interface ServerEntry {
|
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
/** Which Pi layer a read/write targets. */
|
|
46
|
-
export type Scope =
|
|
47
|
+
export type Scope =
|
|
48
|
+
| { kind: "global" }
|
|
49
|
+
| {
|
|
50
|
+
kind: "project";
|
|
51
|
+
cwd: string;
|
|
52
|
+
/**
|
|
53
|
+
* Request-scoped proof that a ROUTE already admitted `cwd` (async guard),
|
|
54
|
+
* so the writer / live reader do not re-run the synchronous guard. Built
|
|
55
|
+
* server-side only: never parsed from a request, never serialized. A scope
|
|
56
|
+
* without a live token falls back to the synchronous `isAllowedCwd`.
|
|
57
|
+
* See change: harden-plugin-cwd-admission (D4).
|
|
58
|
+
*/
|
|
59
|
+
admission?: AdmissionToken;
|
|
60
|
+
};
|
|
47
61
|
|
|
48
62
|
/** Injected filesystem surface. `readFile` returns null when the file is absent. */
|
|
49
63
|
export interface ConfigIO {
|
|
@@ -63,6 +77,7 @@ export type ConfigRefusalCode =
|
|
|
63
77
|
| "name-collision"
|
|
64
78
|
| "transport-conflict"
|
|
65
79
|
| "invalid-entry"
|
|
80
|
+
| "no-global-server"
|
|
66
81
|
| "write-failed";
|
|
67
82
|
|
|
68
83
|
export interface ConfigRefusal {
|
|
@@ -85,17 +100,36 @@ export type RemoveResult =
|
|
|
85
100
|
| { ok: false; refusal: ConfigRefusal };
|
|
86
101
|
|
|
87
102
|
/**
|
|
88
|
-
* `written` — the layer now carries the requested state
|
|
89
|
-
*
|
|
90
|
-
* `needs-choice` — an ENABLE of a folder copy that lacks the
|
|
91
|
-
* secrets: nothing is written; the caller offers "remove the
|
|
92
|
-
* "re-enter the omitted values".
|
|
103
|
+
* `written` — the layer now carries the requested state (a project-scope
|
|
104
|
+
* toggle of a global server writes only a project override).
|
|
105
|
+
* `needs-choice` — an ENABLE of a whole-entry folder copy that lacks the
|
|
106
|
+
* global entry's secrets: nothing is written; the caller offers "remove the
|
|
107
|
+
* folder entry" or "re-enter the omitted values".
|
|
93
108
|
*/
|
|
94
109
|
export type SetEnabledResult =
|
|
95
|
-
| { ok: true; action: "written"
|
|
110
|
+
| { ok: true; action: "written" }
|
|
96
111
|
| { ok: true; action: "needs-choice"; omitted: string[] }
|
|
97
112
|
| { ok: false; refusal: ConfigRefusal };
|
|
98
113
|
|
|
114
|
+
/**
|
|
115
|
+
* A project override patch: absent key = unchanged, `null` = delete the key.
|
|
116
|
+
* Exposure values may be pi's legacy aliases; they are written as given.
|
|
117
|
+
*/
|
|
118
|
+
export interface ProjectOverridePatch {
|
|
119
|
+
enabled?: boolean | null;
|
|
120
|
+
exposure?: string | null;
|
|
121
|
+
toolExposure?: Record<string, string> | null;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** `override` is the raw entry now in the file; undefined → the entry is absent (removed or never there). */
|
|
125
|
+
export type ProjectOverrideResult =
|
|
126
|
+
| { ok: true; override: Record<string, unknown> | undefined }
|
|
127
|
+
| { ok: false; refusal: ConfigRefusal };
|
|
128
|
+
|
|
129
|
+
export type ConvertLegacyResult =
|
|
130
|
+
| { ok: true; previous: ServerEntry }
|
|
131
|
+
| { ok: false; refusal: ConfigRefusal };
|
|
132
|
+
|
|
99
133
|
/** Parse status of one config file (write-suppressed). */
|
|
100
134
|
export interface ParseStatus {
|
|
101
135
|
path: string;
|
|
@@ -108,11 +142,29 @@ export type Provenance = "pi-global" | "pi-folder";
|
|
|
108
142
|
|
|
109
143
|
export type InactiveReason = "disabled" | "project-not-trusted" | "invalid-entry" | "name-collision" | "global-only-auth";
|
|
110
144
|
|
|
145
|
+
/** Why a folder row carries an override pi does not apply. */
|
|
146
|
+
export type OverrideIssue = "orphan" | "bad-keys" | "invalid";
|
|
147
|
+
|
|
111
148
|
export interface EffectiveServerView {
|
|
112
149
|
name: string;
|
|
113
150
|
provenance: Provenance;
|
|
114
151
|
/** A folder entry that replaces the global entry of the same name. */
|
|
115
152
|
overridesGlobal?: boolean;
|
|
153
|
+
/**
|
|
154
|
+
* A valid project override merged onto this (global) row: the folder file,
|
|
155
|
+
* the override keys, and the raw override (override keys carry no secrets).
|
|
156
|
+
*/
|
|
157
|
+
projectOverride?: {
|
|
158
|
+
path: string;
|
|
159
|
+
keys: string[];
|
|
160
|
+
raw: Record<string, unknown>;
|
|
161
|
+
/** The Pi-global values the override sits on (what "Inherit" means): `enabled`, display `exposure`. */
|
|
162
|
+
inherited: { enabled: boolean; exposure: string };
|
|
163
|
+
};
|
|
164
|
+
/** Folder row only: an override-shaped entry pi does not apply (and why). Not counted as a server. */
|
|
165
|
+
overrideIssue?: OverrideIssue;
|
|
166
|
+
/** Folder row only: a whole-entry copy of the global entry made by the old disable path. */
|
|
167
|
+
legacyCopy?: boolean;
|
|
116
168
|
/**
|
|
117
169
|
* The entry as written. In a project view, a GLOBAL entry's secret values
|
|
118
170
|
* (`headers`, `env` → `{redacted, keys}`; `oauth.clientSecret` →
|
|
@@ -144,17 +196,39 @@ export interface LayerStatus {
|
|
|
144
196
|
message?: string;
|
|
145
197
|
}
|
|
146
198
|
|
|
199
|
+
/**
|
|
200
|
+
* Who decided a folder's project trust (the host's `pi-trust-mirror` decision
|
|
201
|
+
* source). Browser-safe copy of the shared type — this package does not import it.
|
|
202
|
+
* See change: mirror-dashboard-trust-to-pi.
|
|
203
|
+
*/
|
|
204
|
+
export type ProjectTrustSource =
|
|
205
|
+
| { kind: "implicit" }
|
|
206
|
+
| { kind: "recorded"; path: string }
|
|
207
|
+
| { kind: "dashboard"; sourceKind: string; entry: string }
|
|
208
|
+
| { kind: "default"; value: "always" | "never" | "ask" };
|
|
209
|
+
|
|
147
210
|
export interface EffectiveView {
|
|
148
211
|
scope: "global" | "project";
|
|
149
212
|
cwd?: string;
|
|
150
213
|
/** Project views only: pi's trust decision for `cwd` (predicate absent → false). */
|
|
151
214
|
trusted?: boolean;
|
|
215
|
+
/**
|
|
216
|
+
* Project views only: who decided `trusted`. Omitted when the host provides no
|
|
217
|
+
* accessor (or the decision failed).
|
|
218
|
+
*/
|
|
219
|
+
trustSource?: ProjectTrustSource;
|
|
220
|
+
/**
|
|
221
|
+
* Project views only: `piTrustMirror.coverInteractive` — whether dashboard trust
|
|
222
|
+
* also covers terminal/interactive pi sessions. Omitted without the accessor.
|
|
223
|
+
*/
|
|
224
|
+
trustCoverInteractive?: boolean;
|
|
152
225
|
servers: EffectiveServerView[];
|
|
153
226
|
layers: LayerStatus[];
|
|
154
227
|
}
|
|
155
228
|
|
|
156
229
|
/** One server's live state as `pi mcp list --json` reports it. */
|
|
157
230
|
export interface LiveServerState {
|
|
231
|
+
/** pi's reported state, or `not-checked-by-pi` for a folder server trusted only by the dashboard. */
|
|
158
232
|
state: string;
|
|
159
233
|
tools: number;
|
|
160
234
|
error?: string;
|
|
@@ -193,6 +267,10 @@ export interface McpClientConfigService {
|
|
|
193
267
|
): ConfigWriteResult;
|
|
194
268
|
removeServer(name: string, scope: Scope): RemoveResult;
|
|
195
269
|
setEnabled(name: string, enabled: boolean, scope: Scope): SetEnabledResult;
|
|
270
|
+
/** Project scope only: patch the override of a Pi-global server (read-modify-write). */
|
|
271
|
+
setProjectOverride(name: string, patch: ProjectOverridePatch, scope: Scope): ProjectOverrideResult;
|
|
272
|
+
/** Project scope only: rewrite a legacy folder copy to an override; returns the previous raw entry. */
|
|
273
|
+
convertLegacyCopy(name: string, scope: Scope): ConvertLegacyResult;
|
|
196
274
|
/** `disabled: true` → `enabled: false`; drop every adapter-only key. */
|
|
197
275
|
convertAdapterLeftovers(name: string, scope: Scope): ConfigWriteResult;
|
|
198
276
|
/** Write-suppressed parse + (optional) dry run of `ensureServerEntry` at global scope. */
|
package/src/server/index.ts
CHANGED
|
@@ -11,14 +11,19 @@
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import type { ServerPluginContext } from "@blackbelt-technology/dashboard-plugin-runtime/server";
|
|
14
|
+
import type { IndeterminateInfo } from "@blackbelt-technology/pi-dashboard-shared/cwd-guard.js";
|
|
14
15
|
import { createRealConfigIO } from "../core/config-io.js";
|
|
15
16
|
import { createMcpClientConfigService } from "../core/service.js";
|
|
17
|
+
import type { ProjectTrustSource } from "../core/types.js";
|
|
16
18
|
import { createPiMcpListRunner } from "./pi-runner.js";
|
|
17
19
|
import { mountMcpClientRoutes } from "./routes.js";
|
|
18
20
|
|
|
19
21
|
const SERVICE_KEY = "mcp-client.config";
|
|
20
22
|
const HOST_KNOWN_FOLDERS = "host.knownFolderCwds";
|
|
21
23
|
const HOST_PROJECT_TRUST = "host.isProjectTrusted";
|
|
24
|
+
const HOST_PROJECT_TRUST_SOURCE = "host.projectTrustSource";
|
|
25
|
+
const HOST_COVER_INTERACTIVE = "host.piTrustCoverInteractive";
|
|
26
|
+
const HOST_CWD_ADMISSION_LOG = "host.cwdAdmissionOnIndeterminate";
|
|
22
27
|
|
|
23
28
|
async function registerPlugin(ctx: ServerPluginContext): Promise<void> {
|
|
24
29
|
ctx.logger.info("mcp-client server entry activated");
|
|
@@ -28,10 +33,16 @@ async function registerPlugin(ctx: ServerPluginContext): Promise<void> {
|
|
|
28
33
|
if (!hostTrust) {
|
|
29
34
|
ctx.logger.warn(`mcp-client: host service '${HOST_PROJECT_TRUST}' is unavailable — every project's .pi/mcp.json is shown as untrusted`);
|
|
30
35
|
}
|
|
36
|
+
// Optional additive disclosure: who decided the trust, and whether dashboard
|
|
37
|
+
// trust also covers interactive pi. See change: mirror-dashboard-trust-to-pi.
|
|
38
|
+
const trustSource = ctx.consume<(cwd: string) => ProjectTrustSource | undefined>(HOST_PROJECT_TRUST_SOURCE);
|
|
39
|
+
const coverInteractive = ctx.consume<() => boolean>(HOST_COVER_INTERACTIVE);
|
|
31
40
|
const runtime = createMcpClientConfigService({
|
|
32
41
|
configIO: createRealConfigIO(),
|
|
33
42
|
knownCwds,
|
|
34
43
|
...(hostTrust ? { isProjectTrusted: (cwd: string) => hostTrust(cwd) } : {}),
|
|
44
|
+
...(trustSource ? { projectTrustSource: (cwd: string) => trustSource(cwd) } : {}),
|
|
45
|
+
...(coverInteractive ? { coverInteractive: () => coverInteractive() } : {}),
|
|
35
46
|
runner: createPiMcpListRunner(),
|
|
36
47
|
});
|
|
37
48
|
|
|
@@ -39,7 +50,18 @@ async function registerPlugin(ctx: ServerPluginContext): Promise<void> {
|
|
|
39
50
|
// observes it during its own registration.
|
|
40
51
|
ctx.provide(SERVICE_KEY, runtime);
|
|
41
52
|
|
|
42
|
-
|
|
53
|
+
// Raise the access dialog on a user-initiated write for an unknown folder, and
|
|
54
|
+
// log undecidable admissions through the host's throttled sink. Both optional:
|
|
55
|
+
// a host without them keeps the plain 403 / no log.
|
|
56
|
+
// See change: harden-plugin-cwd-admission.
|
|
57
|
+
const onIndeterminate = ctx.consume<(info: IndeterminateInfo) => void>(HOST_CWD_ADMISSION_LOG);
|
|
58
|
+
mountMcpClientRoutes(ctx.fastify, {
|
|
59
|
+
runtime,
|
|
60
|
+
knownCwds,
|
|
61
|
+
networkGuard: ctx.networkGuard,
|
|
62
|
+
holdCwdDenial: ctx.holdCwdDenial,
|
|
63
|
+
admitOptions: onIndeterminate ? { onIndeterminate } : undefined,
|
|
64
|
+
});
|
|
43
65
|
}
|
|
44
66
|
|
|
45
67
|
export default registerPlugin;
|