@blackbelt-technology/pi-dashboard-mcp-client-plugin 0.10.0 → 0.12.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.
@@ -1,297 +0,0 @@
1
- /**
2
- * mcp-client-plugin · CORE mirror of pi's built-in MCP entry rules.
3
- *
4
- * pi 1.1.0 does not export `validateMcpServerConfig` (its exports map has
5
- * only `.`, `./rpc-entry`, `./client`, `./experimental/plugin`) and this
6
- * package has no pi dependency, so the checks are mirrored here from
7
- * `dist/core/mcp-servers.js` + `dist/extensions/mcp/config.js`. The writer
8
- * runs them before every write so it never persists an entry pi rejects.
9
- *
10
- * See change: migrate-mcp-to-pi-builtin (D3 "Validation"); mcp-client-project-overrides (D1).
11
- */
12
-
13
- import { isPlainObject } from "./path-utils.js";
14
-
15
- export const MCP_EXPOSURES = ["codemode", "deferred", "direct", "hidden"] as const;
16
- export type McpExposure = (typeof MCP_EXPOSURES)[number];
17
- /** Older exposure names pi still accepts and resolves. */
18
- export const MCP_EXPOSURE_ALIASES: Readonly<Record<string, McpExposure>> = { "codemode-deferred": "codemode" };
19
-
20
- const LOOPBACK_HOSTS = ["localhost", "127.0.0.1", "[::1]"];
21
- const SERVER_NAME = /^[A-Za-z0-9_-]+$/;
22
- /** Never usable as an object key (prototype pollution) — pi's regex alone admits `__proto__`. */
23
- const FORBIDDEN_NAMES = new Set(["__proto__", "constructor", "prototype"]);
24
-
25
- /**
26
- * Adapter-only (`pi-mcp-adapter`) entry keys. pi ignores unknown keys, so these
27
- * stay in a file but have no effect under the built-in MCP. `disabled: true`
28
- * is the dangerous one: pi treats such a server as ENABLED.
29
- */
30
- export const ADAPTER_ONLY_KEYS = [
31
- "disabled",
32
- "socket",
33
- "requestHeadersCommand",
34
- "bearerToken",
35
- "bearerTokenEnv",
36
- "bearerTokenStore",
37
- "lifecycle",
38
- "idleTimeout",
39
- "requestTimeoutMs",
40
- "exposeResources",
41
- "directTools",
42
- "toolPrefix",
43
- "includeTools",
44
- "excludeTools",
45
- "searchKeywords",
46
- "approveTools",
47
- "debug",
48
- "trace",
49
- "httpTransport",
50
- "pluginDataDir",
51
- "literalEnv",
52
- "protocolVersion",
53
- "inheritEnv",
54
- "caFile",
55
- "tasks",
56
- ] as const;
57
-
58
- /** Letters, digits, `_`, `-` (pi's rule), ≤128 chars, never a prototype key. */
59
- export function isValidServerName(name: string): boolean {
60
- return typeof name === "string" && name.length <= 128 && SERVER_NAME.test(name) && !FORBIDDEN_NAMES.has(name);
61
- }
62
-
63
- /** pi maps `-` to `_` for tool namespaces, so `a-b` and `a_b` collide. */
64
- export function mcpNamespace(name: string): string {
65
- return `mcp__${name.replace(/-/g, "_")}`;
66
- }
67
-
68
- function isLoopbackHost(hostname: string): boolean {
69
- return LOOPBACK_HOSTS.includes(hostname);
70
- }
71
-
72
- function isStringRecord(v: unknown): boolean {
73
- return isPlainObject(v) && Object.values(v).every((x) => typeof x === "string");
74
- }
75
-
76
- function isExposure(v: unknown): boolean {
77
- return typeof v === "string" && (MCP_EXPOSURES as readonly string[]).includes(v);
78
- }
79
-
80
- function resolveAlias(v: unknown): unknown {
81
- return typeof v === "string" ? (MCP_EXPOSURE_ALIASES[v] ?? v) : v;
82
- }
83
-
84
- /** Display form of an exposure value: aliases resolved, default `codemode`. */
85
- export function displayExposure(v: unknown): string {
86
- const r = resolveAlias(v);
87
- return typeof r === "string" ? r : "codemode";
88
- }
89
-
90
- function isLoopbackRedirectUri(value: string): boolean {
91
- if (!URL.canParse(value)) return false;
92
- const url = new URL(value);
93
- return url.protocol === "http:" && isLoopbackHost(url.hostname) && url.search === "" && url.hash === "";
94
- }
95
-
96
- function validateOAuth(value: unknown): string | undefined {
97
- if (value === undefined) return undefined;
98
- if (!isPlainObject(value)) return "oauth must be an object";
99
- if (value.clientId !== undefined && typeof value.clientId !== "string") return "oauth.clientId must be a string";
100
- if (value.clientSecret !== undefined && typeof value.clientSecret !== "string") {
101
- return "oauth.clientSecret must be a string";
102
- }
103
- const port = value.callbackPort;
104
- if (port !== undefined && (typeof port !== "number" || !Number.isInteger(port) || port < 1 || port > 65535)) {
105
- return "oauth.callbackPort must be a port number";
106
- }
107
- if (value.callbackUrl !== undefined) {
108
- if (typeof value.callbackUrl !== "string" || !isLoopbackRedirectUri(value.callbackUrl)) {
109
- return "oauth.callbackUrl must be an http URI on localhost, 127.0.0.1, or [::1] without query or fragment";
110
- }
111
- const urlPort = new URL(value.callbackUrl).port;
112
- if (urlPort && port !== undefined && Number(urlPort) !== port) {
113
- return "oauth.callbackUrl and oauth.callbackPort name different ports";
114
- }
115
- }
116
- if (value.scope !== undefined && typeof value.scope !== "string") return "oauth.scope must be a string";
117
- if (value.clientName !== undefined && (typeof value.clientName !== "string" || !value.clientName.trim())) {
118
- return "oauth.clientName must be a non-empty string";
119
- }
120
- const meta = value.authServerMetadataUrl;
121
- if (meta !== undefined) {
122
- const url = typeof meta === "string" && URL.canParse(meta) ? new URL(meta) : undefined;
123
- if (!url || !(url.protocol === "https:" || (url.protocol === "http:" && isLoopbackHost(url.hostname)))) {
124
- return "oauth.authServerMetadataUrl must be an https URL, or http on localhost, 127.0.0.1, or [::1]";
125
- }
126
- }
127
- return undefined;
128
- }
129
-
130
- /**
131
- * Mirror of pi 1.1.0 `validateMcpServerConfig(name, raw)`: `null` when pi
132
- * accepts the entry, else pi's error message.
133
- */
134
- export function validatePiEntry(name: string, raw: unknown): string | null {
135
- if (!SERVER_NAME.test(name)) return `invalid server name "${name}" (use letters, digits, "_" and "-")`;
136
- if (!isPlainObject(raw)) return `server "${name}" must be an object`;
137
- const v = raw as Record<string, unknown>;
138
- const exposure = resolveAlias(v.exposure);
139
- const exposures = MCP_EXPOSURES.map((e) => `"${e}"`).join(", ");
140
- if (v.exposure !== undefined && !isExposure(exposure)) return `server "${name}": exposure must be one of ${exposures}`;
141
- if (v.toolExposure !== undefined) {
142
- if (!isPlainObject(v.toolExposure)) return `server "${name}": toolExposure must map tool names to exposures`;
143
- for (const [tool, e] of Object.entries(v.toolExposure)) {
144
- if (!isExposure(resolveAlias(e))) return `server "${name}": toolExposure "${tool}" must be one of ${exposures}`;
145
- }
146
- }
147
- if (v.enabled !== undefined && typeof v.enabled !== "boolean") return `server "${name}": enabled must be a boolean`;
148
- if (v.description !== undefined && typeof v.description !== "string") {
149
- return `server "${name}": description must be a string`;
150
- }
151
- if (v.timeout !== undefined && (typeof v.timeout !== "number" || !(v.timeout > 0))) {
152
- return `server "${name}": timeout must be a positive number of seconds`;
153
- }
154
- const type = v.type;
155
- if (type === "sse") return `server "${name}": legacy SSE transport is not supported; use the streamable HTTP URL`;
156
- if (typeof v.url === "string" && (type === undefined || type === "http" || type === "streamable-http")) {
157
- if (!URL.canParse(v.url) || !/^https?:$/.test(new URL(v.url).protocol)) {
158
- return `server "${name}": url must be an http or https URL`;
159
- }
160
- if (v.headers !== undefined && !isStringRecord(v.headers)) return `server "${name}": headers must map names to strings`;
161
- const oauthError = validateOAuth(v.oauth);
162
- if (oauthError) return `server "${name}": ${oauthError}`;
163
- if (v.auth !== undefined) {
164
- if (!isPlainObject(v.auth) || typeof v.auth.provider !== "string" || !v.auth.provider) {
165
- return `server "${name}": auth.provider must be a provider name`;
166
- }
167
- const url = new URL(v.url);
168
- if (url.protocol !== "https:" && !isLoopbackHost(url.hostname)) {
169
- return `server "${name}": auth requires an https URL, or http on localhost, 127.0.0.1, or [::1]`;
170
- }
171
- }
172
- return null;
173
- }
174
- if (typeof v.command === "string" && (type === undefined || type === "stdio")) {
175
- if (v.args !== undefined && !(Array.isArray(v.args) && v.args.every((a) => typeof a === "string"))) {
176
- return `server "${name}": args must be an array of strings`;
177
- }
178
- if (v.env !== undefined && !isStringRecord(v.env)) return `server "${name}": env must map names to strings`;
179
- if (v.cwd !== undefined && typeof v.cwd !== "string") return `server "${name}": cwd must be a string`;
180
- return null;
181
- }
182
- return `server "${name}" needs either "command" (stdio) or "url" (streamable HTTP)`;
183
- }
184
-
185
- /** The transport pi picks: HTTP when `url` is set unless `type` is `stdio`. */
186
- export function transportOf(entry: Record<string, unknown>): "stdio" | "http" {
187
- if (typeof entry.url === "string" && entry.type !== "stdio") return "http";
188
- return "stdio";
189
- }
190
-
191
- /** Adapter-only keys present on an entry (plus non-object `auth` / `oauth: false`). */
192
- export function adapterLeftovers(entry: Record<string, unknown>): string[] {
193
- const keys: string[] = ADAPTER_ONLY_KEYS.filter((k) => Object.hasOwn(entry, k));
194
- if (entry.auth !== undefined && !isPlainObject(entry.auth)) keys.push("auth");
195
- if (entry.oauth === false) keys.push("oauth");
196
- return keys;
197
- }
198
-
199
- /** Keys pi ignores on this entry: adapter leftovers + the losing key of a dual transport. */
200
- export function ignoredKeys(entry: Record<string, unknown>): string[] {
201
- const keys = adapterLeftovers(entry);
202
- if (typeof entry.command === "string" && typeof entry.url === "string") {
203
- keys.push(transportOf(entry) === "http" ? "command" : "url");
204
- }
205
- return keys;
206
- }
207
-
208
- export type AuthMode = { kind: "provider"; provider: string } | { kind: "header" } | { kind: "oauth" };
209
-
210
- /** How pi authenticates an HTTP entry; `undefined` for stdio. */
211
- export function authModeOf(entry: Record<string, unknown>): AuthMode | undefined {
212
- if (transportOf(entry) !== "http") return undefined;
213
- if (isPlainObject(entry.auth) && typeof entry.auth.provider === "string" && entry.auth.provider) {
214
- return { kind: "provider", provider: entry.auth.provider };
215
- }
216
- if (isPlainObject(entry.headers) && Object.keys(entry.headers).some((k) => k.toLowerCase() === "authorization")) {
217
- return { kind: "header" };
218
- }
219
- return { kind: "oauth" };
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
- }
@@ -1,57 +0,0 @@
1
- /**
2
- * mcp-client-plugin · JSON-Schema validation for server entries.
3
- *
4
- * Uses the plugin's OWN Ajv instance — `strict: true`, `useDefaults: false`,
5
- * `allErrors: true` — NOT the runtime's `config-validator` (whose
6
- * `useDefaults: true` would inject schema defaults into an entry, and whose
7
- * strict mode rejects the `x-` annotation keywords). The writer additionally
8
- * mirrors pi's own entry rules (`pi-rules.ts`).
9
- *
10
- * See change: migrate-mcp-to-pi-builtin; earlier: extract-mcp-client-plugin (D7).
11
- */
12
-
13
- import Ajv, { type ErrorObject, type ValidateFunction } from "ajv";
14
- import schema from "../../schema/mcp-config.schema.json";
15
-
16
- export interface PatchValidation {
17
- ok: boolean;
18
- errors: ErrorObject[];
19
- }
20
-
21
- function buildAjv(): Ajv {
22
- const ajv = new Ajv({ strict: true, useDefaults: false, allErrors: true });
23
- // Custom annotation keywords: registration is what makes strict mode accept them.
24
- ajv.addKeyword({ keyword: "x-secret" });
25
- ajv.addKeyword({ keyword: "x-transport" });
26
- ajv.addKeyword({ keyword: "x-global-only" });
27
- ajv.addSchema(schema, "mcp-config");
28
- return ajv;
29
- }
30
-
31
- const ajv = buildAjv();
32
-
33
- function compile(ref: string): ValidateFunction {
34
- const fn = ajv.getSchema(`mcp-config#/$defs/${ref}`);
35
- if (!fn) throw new Error(`schema $def ${ref} did not compile`);
36
- return fn;
37
- }
38
-
39
- const validateServer = compile("ServerEntry");
40
- const validateOverride = compile("ProjectOverride");
41
-
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 ?? []) };
47
- }
48
-
49
- /** Field names from Ajv errors (drop the leading slash of `instancePath`; an `additionalProperties` refusal names the offending key). */
50
- export function errorFields(errors: ErrorObject[]): string[] {
51
- return errors
52
- .map((e) => e.instancePath.replace(/^\//, "").split("/")[0] || String(e.params?.additionalProperty ?? ""))
53
- .filter((f) => f.length > 0);
54
- }
55
-
56
- /** Exposed for the compile-contract test and the schema route. */
57
- export const mcpConfigSchema = schema;
@@ -1,141 +0,0 @@
1
- /**
2
- * mcp-client-plugin · `mcp-client.config` service factory.
3
- *
4
- * Composes the writer, the effective-view reader and (optionally) the
5
- * `pi mcp list` live-state reader behind the in-process service contract
6
- * other plugins consume. A hostless caller (the apple-tools CLI) gets the
7
- * identical implementation from this factory; without an `isProjectTrusted`
8
- * predicate every project counts as untrusted.
9
- *
10
- * See change: migrate-mcp-to-pi-builtin (D3); earlier: extract-mcp-client-plugin (D4).
11
- */
12
-
13
- import { mkdtempSync } from "node:fs";
14
- import { tmpdir } from "node:os";
15
- import { join } from "node:path";
16
- import { createConfigWriter } from "./config-writer.js";
17
- import { createEffectiveViewReader } from "./effective-view.js";
18
- import { defaultLayerPaths, type LayerPaths } from "./layers.js";
19
- import { createLiveStateReader } from "./live-state.js";
20
- import type { ConfigIO, LiveState, McpClientConfigService, PiMcpListRunner, ProjectTrustSource, Scope } from "./types.js";
21
-
22
- export interface McpClientConfigServiceDeps {
23
- configIO: ConfigIO;
24
- knownCwds: () => string[];
25
- /** pi's project-trust rule (`host.isProjectTrusted`). Absent → untrusted. */
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;
40
- /** Layer paths. Defaults to `$PI_CODING_AGENT_DIR/mcp.json` + `<cwd>/.pi/mcp.json`. */
41
- paths?: LayerPaths;
42
- /** Runs `pi mcp list --json`. Absent → live state reports `spawn-failed`. */
43
- runner?: PiMcpListRunner;
44
- /** Always-empty dir the global live-state list runs in. Defaults to a fresh mkdtemp. */
45
- scratchCwd?: string;
46
- liveTimeoutMs?: number;
47
- liveCacheTtlMs?: number;
48
- }
49
-
50
- /** The provided service plus the live-state reader the HTTP layer needs. */
51
- export interface McpClientRuntime extends McpClientConfigService {
52
- getLiveState(scope: Scope, opts?: { fresh?: boolean }): Promise<LiveState>;
53
- }
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
-
69
- export function createMcpClientConfigService(deps: McpClientConfigServiceDeps): McpClientRuntime {
70
- const paths = deps.paths ?? defaultLayerPaths();
71
- const piOnly = trustedByPiOnly(deps);
72
- const writer = createConfigWriter({
73
- configIO: deps.configIO,
74
- paths,
75
- knownCwds: deps.knownCwds,
76
- // Global-write collisions keep pi-only trust: dashboard trust never changes them.
77
- ...(piOnly ? { isProjectTrusted: piOnly } : {}),
78
- });
79
- const viewReader = createEffectiveViewReader({
80
- configIO: deps.configIO,
81
- paths,
82
- ...(deps.isProjectTrusted ? { isProjectTrusted: deps.isProjectTrusted } : {}),
83
- ...(deps.projectTrustSource ? { projectTrustSource: deps.projectTrustSource } : {}),
84
- ...(deps.coverInteractive ? { coverInteractive: deps.coverInteractive } : {}),
85
- });
86
- const runner: PiMcpListRunner =
87
- deps.runner ?? (() => Promise.reject(new Error("no pi mcp list runner configured")));
88
- const live = createLiveStateReader({
89
- runner,
90
- ...(deps.liveTimeoutMs !== undefined ? { timeoutMs: deps.liveTimeoutMs } : {}),
91
- ...(deps.liveCacheTtlMs !== undefined ? { cacheTtlMs: deps.liveCacheTtlMs } : {}),
92
- });
93
- let scratch = deps.scratchCwd;
94
- const scratchCwd = (): string => {
95
- scratch ??= mkdtempSync(join(tmpdir(), "pi-mcp-client-"));
96
- return scratch;
97
- };
98
-
99
- return {
100
- targetPath: (scope) => writer.targetPath(scope),
101
- readServerEntry: (name, scope) => writer.readServerEntry(name, scope),
102
- getEffectiveView: (scope) => viewReader.getEffectiveView(scope),
103
- ensureServerEntry: (name, fields, scope) => writer.ensureServerEntry(name, fields, scope),
104
- saveServer: (name, entry, scope, opts) => writer.saveServer(name, entry, scope, opts),
105
- removeServer: (name, scope) => writer.removeServer(name, scope),
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),
109
- convertAdapterLeftovers: (name, scope) => writer.convertAdapterLeftovers(name, scope),
110
-
111
- checkConfigFiles(opts) {
112
- const path = paths.globalPath();
113
- let mcpJson = writer.readParseStatus(path);
114
- // A dry run of the ensure the caller is about to perform, so check mode
115
- // and write mode agree on the refusal.
116
- if (mcpJson.ok && opts?.serverName !== undefined) {
117
- const refusal = writer.previewEnsure(opts.serverName, opts.fields ?? {}, { kind: "global" });
118
- if (refusal) mcpJson = { path, ok: false, message: refusal.message };
119
- }
120
- return { mcpJson };
121
- },
122
-
123
- getLiveState(scope, opts) {
124
- const cwd = scope.kind === "project" ? scope.cwd : scratchCwd();
125
- if (scope.kind === "project") writer.targetPath(scope); // admission
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
- });
139
- },
140
- };
141
- }