@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.
- package/README.md +1 -1
- package/package.json +7 -4
- package/src/client/FolderMcpPage.tsx +30 -6
- package/src/client/FolderMcpSection.tsx +3 -3
- package/src/client/ProjectSettings.tsx +2 -2
- package/src/client/ServerEditor.tsx +2 -2
- package/src/client/ServerList.tsx +2 -2
- package/src/client/api.ts +1 -1
- package/src/client/folder-view.ts +2 -2
- package/src/client/hooks.ts +2 -1
- package/src/client/schema.ts +1 -1
- package/src/core/index.ts +8 -78
- package/src/server/index.ts +4 -4
- package/src/server/pi-runner.ts +1 -1
- package/src/server/routes.ts +4 -4
- package/schema/mcp-config.schema.json +0 -64
- package/src/core/config-io.ts +0 -70
- package/src/core/config-writer.ts +0 -634
- package/src/core/effective-view.ts +0 -251
- package/src/core/layers.ts +0 -61
- package/src/core/live-state.ts +0 -134
- package/src/core/path-utils.ts +0 -41
- package/src/core/pi-rules.ts +0 -297
- package/src/core/schema-validation.ts +0 -57
- package/src/core/service.ts +0 -141
- package/src/core/types.ts +0 -278
package/src/core/types.ts
DELETED
|
@@ -1,278 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* mcp-client-plugin · CORE types.
|
|
3
|
-
*
|
|
4
|
-
* Shared vocabulary for the config writer, effective-view reader, live-state
|
|
5
|
-
* reader and the `mcp-client.config` service — all over pi's built-in MCP
|
|
6
|
-
* config (`~/.pi/agent/mcp.json` + trusted `<cwd>/.pi/mcp.json`). `./core`
|
|
7
|
-
* carries NO host, pi or React imports so the hostless `apple-tools`
|
|
8
|
-
* installer can consume it.
|
|
9
|
-
*
|
|
10
|
-
* See change: migrate-mcp-to-pi-builtin (D3); earlier: extract-mcp-client-plugin.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import type { AdmissionToken } from "@blackbelt-technology/pi-dashboard-shared/cwd-guard.js";
|
|
14
|
-
import type { AuthMode } from "./pi-rules.js";
|
|
15
|
-
|
|
16
|
-
export type { AuthMode };
|
|
17
|
-
|
|
18
|
-
/** pi's MCP server entry (1.1.0). Unknown keys are preserved, never dropped. */
|
|
19
|
-
export interface ServerEntry {
|
|
20
|
-
type?: "stdio" | "http" | "streamable-http" | string;
|
|
21
|
-
description?: string;
|
|
22
|
-
command?: string;
|
|
23
|
-
args?: string[];
|
|
24
|
-
env?: Record<string, string>;
|
|
25
|
-
cwd?: string;
|
|
26
|
-
url?: string;
|
|
27
|
-
headers?: Record<string, string>;
|
|
28
|
-
oauth?: {
|
|
29
|
-
clientId?: string;
|
|
30
|
-
clientSecret?: string;
|
|
31
|
-
callbackPort?: number;
|
|
32
|
-
callbackUrl?: string;
|
|
33
|
-
scope?: string;
|
|
34
|
-
clientName?: string;
|
|
35
|
-
authServerMetadataUrl?: string;
|
|
36
|
-
[k: string]: unknown;
|
|
37
|
-
};
|
|
38
|
-
auth?: { provider: string; [k: string]: unknown };
|
|
39
|
-
exposure?: string;
|
|
40
|
-
toolExposure?: Record<string, string>;
|
|
41
|
-
timeout?: number;
|
|
42
|
-
enabled?: boolean;
|
|
43
|
-
[k: string]: unknown;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/** Which Pi layer a read/write targets. */
|
|
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
|
-
};
|
|
61
|
-
|
|
62
|
-
/** Injected filesystem surface. `readFile` returns null when the file is absent. */
|
|
63
|
-
export interface ConfigIO {
|
|
64
|
-
readFile: (path: string) => string | null;
|
|
65
|
-
/**
|
|
66
|
-
* Atomic, hardened write (exclusive random temp file mode 0600, fsync, rename).
|
|
67
|
-
* Throws an Error whose `.code` may be EACCES / ENOSPC / ENOENT.
|
|
68
|
-
*/
|
|
69
|
-
writeFileAtomic: (path: string, content: string) => void;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/** The closed refusal set shared by every write path AND by `checkConfigFiles`. */
|
|
73
|
-
export type ConfigRefusalCode =
|
|
74
|
-
| "unparseable"
|
|
75
|
-
| "entry-not-object"
|
|
76
|
-
| "invalid-name"
|
|
77
|
-
| "name-collision"
|
|
78
|
-
| "transport-conflict"
|
|
79
|
-
| "invalid-entry"
|
|
80
|
-
| "no-global-server"
|
|
81
|
-
| "write-failed";
|
|
82
|
-
|
|
83
|
-
export interface ConfigRefusal {
|
|
84
|
-
code: ConfigRefusalCode;
|
|
85
|
-
message: string;
|
|
86
|
-
/** The offending file, when the refusal is file-scoped. */
|
|
87
|
-
path?: string;
|
|
88
|
-
/** For `write-failed`: the IO error code (EACCES / ENOSPC / ENOENT / ...). */
|
|
89
|
-
ioCode?: string;
|
|
90
|
-
/** For `transport-conflict`: the transport fields the resulting entry carries. */
|
|
91
|
-
fields?: string[];
|
|
92
|
-
/** For `name-collision`: the colliding server and where it is defined. */
|
|
93
|
-
conflict?: { name: string; path: string };
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export type ConfigWriteResult = { ok: true } | { ok: false; refusal: ConfigRefusal };
|
|
97
|
-
|
|
98
|
-
export type RemoveResult =
|
|
99
|
-
| { ok: true; removed: ServerEntry | undefined }
|
|
100
|
-
| { ok: false; refusal: ConfigRefusal };
|
|
101
|
-
|
|
102
|
-
/**
|
|
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".
|
|
108
|
-
*/
|
|
109
|
-
export type SetEnabledResult =
|
|
110
|
-
| { ok: true; action: "written" }
|
|
111
|
-
| { ok: true; action: "needs-choice"; omitted: string[] }
|
|
112
|
-
| { ok: false; refusal: ConfigRefusal };
|
|
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
|
-
|
|
133
|
-
/** Parse status of one config file (write-suppressed). */
|
|
134
|
-
export interface ParseStatus {
|
|
135
|
-
path: string;
|
|
136
|
-
ok: boolean;
|
|
137
|
-
/** Present iff `ok` is false: the parser error message. */
|
|
138
|
-
message?: string;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
export type Provenance = "pi-global" | "pi-folder";
|
|
142
|
-
|
|
143
|
-
export type InactiveReason = "disabled" | "project-not-trusted" | "invalid-entry" | "name-collision" | "global-only-auth";
|
|
144
|
-
|
|
145
|
-
/** Why a folder row carries an override pi does not apply. */
|
|
146
|
-
export type OverrideIssue = "orphan" | "bad-keys" | "invalid";
|
|
147
|
-
|
|
148
|
-
export interface EffectiveServerView {
|
|
149
|
-
name: string;
|
|
150
|
-
provenance: Provenance;
|
|
151
|
-
/** A folder entry that replaces the global entry of the same name. */
|
|
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;
|
|
168
|
-
/**
|
|
169
|
-
* The entry as written. In a project view, a GLOBAL entry's secret values
|
|
170
|
-
* (`headers`, `env` → `{redacted, keys}`; `oauth.clientSecret` →
|
|
171
|
-
* `{redacted}`) are redacted server-side; own-layer entries are verbatim.
|
|
172
|
-
*/
|
|
173
|
-
entry: Record<string, unknown>;
|
|
174
|
-
transport: "stdio" | "http";
|
|
175
|
-
enabled: boolean;
|
|
176
|
-
/** Exposure for display (alias resolved, default `codemode`). */
|
|
177
|
-
exposure: string;
|
|
178
|
-
/** Whether pi loads this entry for the view's directory. */
|
|
179
|
-
active: boolean;
|
|
180
|
-
inactiveReason?: InactiveReason;
|
|
181
|
-
/** pi's own message when it would reject or drop the entry. */
|
|
182
|
-
piError?: string;
|
|
183
|
-
/** Keys pi ignores on this entry (adapter leftovers, losing dual-transport key). */
|
|
184
|
-
ignoredKeys: string[];
|
|
185
|
-
/** The adapter-only subset of `ignoredKeys`; non-empty → "convert" is offered. */
|
|
186
|
-
adapterLeftovers: string[];
|
|
187
|
-
authMode?: AuthMode;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
export interface LayerStatus {
|
|
191
|
-
layer: Provenance;
|
|
192
|
-
path: string;
|
|
193
|
-
exists: boolean;
|
|
194
|
-
ok: boolean;
|
|
195
|
-
/** Present iff `ok` is false — pi skips the whole file. */
|
|
196
|
-
message?: string;
|
|
197
|
-
}
|
|
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
|
-
|
|
210
|
-
export interface EffectiveView {
|
|
211
|
-
scope: "global" | "project";
|
|
212
|
-
cwd?: string;
|
|
213
|
-
/** Project views only: pi's trust decision for `cwd` (predicate absent → false). */
|
|
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;
|
|
225
|
-
servers: EffectiveServerView[];
|
|
226
|
-
layers: LayerStatus[];
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
/** One server's live state as `pi mcp list --json` reports it. */
|
|
230
|
-
export interface LiveServerState {
|
|
231
|
-
/** pi's reported state, or `not-checked-by-pi` for a folder server trusted only by the dashboard. */
|
|
232
|
-
state: string;
|
|
233
|
-
tools: number;
|
|
234
|
-
error?: string;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
export type LiveState =
|
|
238
|
-
| { ok: true; servers: Record<string, LiveServerState>; errors: string[]; note?: string }
|
|
239
|
-
| { ok: false; reason: "spawn-failed" | "timeout" | "unparseable"; message: string };
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
* Runs `pi mcp list --json` in `cwd`. Resolves with stdout + exit code
|
|
243
|
-
* whatever the code; rejects only when the process cannot run. Must kill the
|
|
244
|
-
* child when `signal` aborts.
|
|
245
|
-
*/
|
|
246
|
-
export type PiMcpListRunner = (cwd: string, signal: AbortSignal) => Promise<{ stdout: string; code: number | null }>;
|
|
247
|
-
|
|
248
|
-
/** The in-process service provided as `mcp-client.config`. */
|
|
249
|
-
export interface McpClientConfigService {
|
|
250
|
-
/** The file a scope's write lands in. Throws `NotAllowedCwdError` for an unknown cwd. */
|
|
251
|
-
targetPath(scope: Scope): string;
|
|
252
|
-
/** The raw entry in the scope's layer (no merge), or undefined. */
|
|
253
|
-
readServerEntry(name: string, scope: Scope): ServerEntry | undefined;
|
|
254
|
-
getEffectiveView(scope: Scope): EffectiveView;
|
|
255
|
-
/** Merge `fields` over the existing layer entry (or create it), then validate. */
|
|
256
|
-
ensureServerEntry(name: string, fields: Partial<ServerEntry>, scope: Scope): ConfigWriteResult;
|
|
257
|
-
/**
|
|
258
|
-
* Replace the whole entry. `previousName` renames (the old key is removed);
|
|
259
|
-
* `create` refuses when the name already exists. Neither ever replaces
|
|
260
|
-
* another entry.
|
|
261
|
-
*/
|
|
262
|
-
saveServer(
|
|
263
|
-
name: string,
|
|
264
|
-
entry: ServerEntry,
|
|
265
|
-
scope: Scope,
|
|
266
|
-
opts?: { previousName?: string; create?: boolean },
|
|
267
|
-
): ConfigWriteResult;
|
|
268
|
-
removeServer(name: string, scope: Scope): RemoveResult;
|
|
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;
|
|
274
|
-
/** `disabled: true` → `enabled: false`; drop every adapter-only key. */
|
|
275
|
-
convertAdapterLeftovers(name: string, scope: Scope): ConfigWriteResult;
|
|
276
|
-
/** Write-suppressed parse + (optional) dry run of `ensureServerEntry` at global scope. */
|
|
277
|
-
checkConfigFiles(opts?: { serverName?: string; fields?: Partial<ServerEntry> }): { mcpJson: ParseStatus };
|
|
278
|
-
}
|