pico-engine 1.6.4 → 1.8.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.
Files changed (98) hide show
  1. package/README.md +13 -8
  2. package/dist/RulesetRegistryLoaderFs.js +14 -2
  3. package/dist/auth/cookies.js +32 -0
  4. package/dist/auth/index.js +6 -1
  5. package/dist/channelIdentityPolicy.js +22 -0
  6. package/dist/cli.js +104 -69
  7. package/dist/engineConfig.js +280 -0
  8. package/dist/identity/IdentityService.js +90 -0
  9. package/dist/identity/crossPico.js +24 -8
  10. package/dist/identity/didoModule.js +80 -18
  11. package/dist/identity/establishSubscription.js +2 -2
  12. package/dist/identity/identityPortable.js +92 -0
  13. package/dist/identity/index.js +10 -1
  14. package/dist/identity/localPeerReconcile.js +65 -0
  15. package/dist/identity/peerDid4.js +175 -0
  16. package/dist/identity/peerDid4Create.js +90 -0
  17. package/dist/identity/portableExportPrepare.js +196 -0
  18. package/dist/identity/portableMove.js +87 -0
  19. package/dist/identity/skyIntro.js +6 -3
  20. package/dist/identity/skyProtocol.js +26 -1
  21. package/dist/identity/skyRotation.js +121 -0
  22. package/dist/identity/store.js +5 -1
  23. package/dist/identity/subscriptionEntSync.js +72 -0
  24. package/dist/identity/veramoDidComm.js +41 -2
  25. package/dist/identity/webvh.js +4 -2
  26. package/dist/identity/webvhRelocation.js +115 -0
  27. package/dist/index.js +82 -22
  28. package/dist/logging.js +8 -12
  29. package/dist/oauth/OAuthService.js +6 -2
  30. package/dist/policyConfigFromJson.js +112 -0
  31. package/dist/runMcp.js +27 -0
  32. package/dist/server.js +56 -24
  33. package/dist/subtreeWrangler.js +180 -0
  34. package/dist/uiChannelPolicies.js +15 -0
  35. package/krl/io.picolabs.oauth.krl +41 -2
  36. package/krl/io.picolabs.pds.krl +131 -10
  37. package/krl/io.picolabs.pico-engine-ui.krl +209 -21
  38. package/krl/io.picolabs.portable_subtree.krl +97 -0
  39. package/krl/io.picolabs.subscription.krl +180 -72
  40. package/krl/io.picolabs.wrangler.krl +296 -57
  41. package/mcp/devResources.js +118 -0
  42. package/mcp/devTools.js +351 -0
  43. package/mcp/engineClient.js +133 -0
  44. package/mcp/meshHttp.js +137 -0
  45. package/mcp/meshTools.js +189 -0
  46. package/mcp/runStdio.js +34 -0
  47. package/mcp/schemaToZod.js +56 -0
  48. package/package.json +20 -8
  49. package/public/docs/_sidebar.md +2 -1
  50. package/public/docs/llms-full.txt +479 -0
  51. package/public/docs/llms.txt +37 -0
  52. package/public/docs/openapi.yaml +78 -0
  53. package/public/docs/pico-engine.md +235 -4
  54. package/public/docs/pico-overview.md +117 -0
  55. package/public/docs/pico.md +3 -1
  56. package/public/docs/rulesets/README.md +25 -0
  57. package/public/docs/rulesets/io.picolabs.oauth.md +71 -0
  58. package/public/docs/rulesets/io.picolabs.pds.md +327 -0
  59. package/public/docs/rulesets/io.picolabs.pico-engine-ui.md +65 -0
  60. package/public/docs/rulesets/io.picolabs.portable_subtree.md +94 -0
  61. package/public/docs/rulesets/io.picolabs.subscription.md +398 -0
  62. package/public/docs/rulesets/io.picolabs.wrangler.md +471 -0
  63. package/public/pico-engine-ui.css +1 -1
  64. package/public/pico-engine-ui.js +28 -26
  65. package/src/RulesetRegistryLoaderFs.ts +18 -3
  66. package/src/auth/cookies.ts +34 -0
  67. package/src/auth/index.ts +7 -0
  68. package/src/channelIdentityPolicy.ts +29 -0
  69. package/src/cli.ts +68 -37
  70. package/src/engineConfig.ts +345 -0
  71. package/src/identity/IdentityService.ts +189 -1
  72. package/src/identity/crossPico.ts +57 -8
  73. package/src/identity/didoModule.ts +140 -23
  74. package/src/identity/establishSubscription.ts +2 -2
  75. package/src/identity/identityPortable.ts +153 -0
  76. package/src/identity/index.ts +14 -0
  77. package/src/identity/localPeerReconcile.ts +97 -0
  78. package/src/identity/peerDid4.ts +197 -0
  79. package/src/identity/peerDid4Create.ts +121 -0
  80. package/src/identity/portableExportPrepare.ts +302 -0
  81. package/src/identity/portableMove.ts +193 -0
  82. package/src/identity/skyIntro.ts +11 -11
  83. package/src/identity/skyProtocol.ts +46 -0
  84. package/src/identity/skyRotation.ts +211 -0
  85. package/src/identity/store.ts +5 -1
  86. package/src/identity/subscriptionEntSync.ts +97 -0
  87. package/src/identity/veramoDidComm.ts +52 -2
  88. package/src/identity/webvh.ts +4 -4
  89. package/src/identity/webvhRelocation.ts +167 -0
  90. package/src/index.ts +119 -25
  91. package/src/logging.ts +8 -14
  92. package/src/oauth/OAuthService.ts +11 -3
  93. package/src/policyConfigFromJson.ts +131 -0
  94. package/src/runMcp.ts +30 -0
  95. package/src/server.ts +79 -26
  96. package/src/subtreeWrangler.ts +278 -0
  97. package/src/uiChannelPolicies.ts +15 -0
  98. package/krl/io.picolabs.did-o.krl +0 -349
package/src/index.ts CHANGED
@@ -4,9 +4,20 @@ import * as makeDir from "make-dir";
4
4
  import * as path from "path";
5
5
  import type { Server } from "http";
6
6
  import { PicoEngineCore, RulesetRegistry } from "pico-engine-core";
7
- import { PicoDbKey, PicoFramework } from "pico-framework";
7
+ import {
8
+ EventPolicyRule,
9
+ PicoDbKey,
10
+ PicoFramework,
11
+ PolicyCeiling,
12
+ QueryPolicyRule,
13
+ } from "pico-framework";
8
14
  import { AuthService, WebAuthnAdapter, makeWebAuthnAdapter } from "./auth";
9
- import { IdentityStore, IdentityService, initDidoModule } from "./identity";
15
+ import {
16
+ IdentityStore,
17
+ IdentityService,
18
+ initDidoModule,
19
+ createSubtreePortableHooks,
20
+ } from "./identity";
10
21
  import { registerWebvhRoutes } from "./identity/webvhRoutes";
11
22
  import { OAuthService, initOAuthModule } from "./oauth";
12
23
  import {
@@ -17,11 +28,16 @@ import {
17
28
  import { openClassicLevelWithRecovery } from "./levelDb";
18
29
  import { provisionRoot, uiECIForRoot } from "./provisionRoot";
19
30
  import { createRulesetRegistryLoaderFs } from "./RulesetRegistryLoaderFs";
31
+ import { resolveBundledKrlUrl } from "./bundledKrl";
32
+ import { wranglerSubtreeImportServices } from "./subtreeWrangler";
20
33
  import { server } from "./server";
34
+ import {
35
+ installEngineRuntimeSettings,
36
+ resolveEngineSettings,
37
+ } from "./engineConfig";
21
38
  const charwise = require("charwise");
22
39
  const safeJsonCodec = require("level-json-coerce-null");
23
40
 
24
- const homeDir = require("home-dir");
25
41
  const version = require("../package.json").version;
26
42
 
27
43
  /**
@@ -99,6 +115,15 @@ export interface PicoEngineConfiguration {
99
115
  * Tests may set this to true.
100
116
  */
101
117
  autoCreateRootPico?: boolean;
118
+
119
+ /** Default max channel policy for root picos (1.8 policy ceiling). */
120
+ defaultRootPolicyCeiling?: PolicyCeiling;
121
+
122
+ /** Engine-wide event denies on every channel ECI (1.8). */
123
+ globalEventDeny?: EventPolicyRule[];
124
+
125
+ /** Engine-wide query denies on every channel ECI (1.8). */
126
+ globalQueryDeny?: QueryPolicyRule[];
102
127
  }
103
128
 
104
129
  export interface PicoEngine {
@@ -109,6 +134,7 @@ export interface PicoEngine {
109
134
  base_url: string;
110
135
 
111
136
  pf: PicoFramework;
137
+ core: PicoEngineCore;
112
138
  /** UI channel for the session root; null when no roots exist yet at boot. */
113
139
  uiECI: string | null;
114
140
  rsRegistry: RulesetRegistry;
@@ -121,24 +147,46 @@ export interface PicoEngine {
121
147
  shutdown(): Promise<void>;
122
148
  }
123
149
 
150
+ /** Integration harnesses (e.g. manifold-api Docker tests): boot with one root, no passkey. */
151
+ function autoCreateRootFromEnv(): boolean | undefined {
152
+ const v = process.env.PICO_ENGINE_AUTO_CREATE_ROOT;
153
+ if (typeof v !== "string" || v.trim().length === 0) {
154
+ return undefined;
155
+ }
156
+ const s = v.trim().toLowerCase();
157
+ if (s === "1" || s === "true" || s === "yes") {
158
+ return true;
159
+ }
160
+ if (s === "0" || s === "false" || s === "no") {
161
+ return false;
162
+ }
163
+ return undefined;
164
+ }
165
+
124
166
  export async function startEngine(
125
167
  configuration: PicoEngineConfiguration = {}
126
168
  ): Promise<PicoEngine> {
127
- let home = configuration.home;
128
- let port = configuration.port;
129
- let base_url = configuration.base_url;
130
-
131
- if (typeof home !== "string") {
132
- const envHome = process.env.PICO_ENGINE_HOME;
133
- if (
134
- typeof envHome === "string" &&
135
- envHome.length > 0 &&
136
- process.env.NODE_ENV === "test"
137
- ) {
138
- home = envHome;
139
- } else {
140
- home = homeDir(".pico-engine") as string;
141
- }
169
+ const settings = resolveEngineSettings({
170
+ home: configuration.home,
171
+ port: configuration.port,
172
+ base_url: configuration.base_url,
173
+ rpID: configuration.rpID,
174
+ rpName: configuration.rpName,
175
+ origin: configuration.origin,
176
+ allowSelfSignup: configuration.allowSelfSignup,
177
+ defaultRootPolicyCeiling: configuration.defaultRootPolicyCeiling,
178
+ globalEventDeny: configuration.globalEventDeny,
179
+ globalQueryDeny: configuration.globalQueryDeny,
180
+ });
181
+ installEngineRuntimeSettings(settings);
182
+
183
+ const home = settings.home;
184
+ let port = configuration.port ?? settings.port;
185
+ const baseUrlFromCaller = configuration.base_url;
186
+ /** Filled after listen when using port 0 or when config baseUrl port does not match. */
187
+ let base_url: string | undefined = baseUrlFromCaller;
188
+ if (base_url == null && port > 0) {
189
+ base_url = settings.baseUrl;
142
190
  }
143
191
  await makeDir(home);
144
192
 
@@ -163,7 +211,15 @@ export async function startEngine(
163
211
  log,
164
212
  modules: configuration.modules,
165
213
  useEventInputTime: configuration.useEventInputTime,
166
- autoCreateRootPico: configuration.autoCreateRootPico ?? false,
214
+ autoCreateRootPico:
215
+ configuration.autoCreateRootPico ??
216
+ autoCreateRootFromEnv() ??
217
+ false,
218
+ defaultRootPolicyCeiling:
219
+ configuration.defaultRootPolicyCeiling ??
220
+ settings.defaultRootPolicyCeiling,
221
+ globalEventDeny: configuration.globalEventDeny ?? settings.globalEventDeny,
222
+ globalQueryDeny: configuration.globalQueryDeny ?? settings.globalQueryDeny,
167
223
  getPicoLogs(picoId) {
168
224
  if (!logFilePath) {
169
225
  return Promise.resolve([]);
@@ -172,18 +228,49 @@ export async function startEngine(
172
228
  },
173
229
  });
174
230
  const pf = core.picoFramework;
231
+ core.resolveBundledRulesetUrl = resolveBundledKrlUrl;
232
+ core.subtreeImportServices = wranglerSubtreeImportServices(core.rsRegistry);
175
233
  const identity = new IdentityStore({ db: pf.db });
176
234
  let identityService!: IdentityService;
235
+ const onPicoCreated = async (
236
+ picoId: string,
237
+ ctx: { isRoot: boolean; parentPicoId: string }
238
+ ) => {
239
+ if (core.base_url) {
240
+ await identityService.ensureWebvhDid(picoId, { isRoot: ctx.isRoot });
241
+ }
242
+ };
177
243
  identityService = new IdentityService({
178
244
  store: identity,
179
245
  getBaseUrl: () => core.base_url || base_url || "",
180
246
  pf,
247
+ rsRegistry: core.rsRegistry,
248
+ resolveBundledRulesetUrl: resolveBundledKrlUrl,
249
+ reloadImportedSchedules: (picoIds) => core.reloadImportedSchedules(picoIds),
250
+ firePicoImported: async (result) => {
251
+ const importedRoot = pf.getPico(result.newRootPicoId);
252
+ if (!importedRoot) {
253
+ return;
254
+ }
255
+ await importedRoot.event({
256
+ eci: result.newRootEci,
257
+ domain: "wrangler",
258
+ name: "pico_imported",
259
+ data: {
260
+ attrs: {
261
+ oldRootPicoId: result.oldRootPicoId,
262
+ newRootPicoId: result.newRootPicoId,
263
+ eciMap: result.eciMap,
264
+ picoIdMap: result.picoIdMap,
265
+ portableIdentity: true,
266
+ },
267
+ },
268
+ time: Date.now(),
269
+ });
270
+ },
181
271
  });
182
- core.onPicoCreated = async (picoId, ctx) => {
183
- if (core.base_url) {
184
- await identityService.ensureWebvhDid(picoId, { isRoot: ctx.isRoot });
185
- }
186
- };
272
+ core.onPicoCreated = onPicoCreated;
273
+ core.subtreePortableHooks = createSubtreePortableHooks(identity, pf);
187
274
  core.modules["dido"] = initDidoModule(identityService);
188
275
 
189
276
  try {
@@ -212,7 +299,8 @@ export async function startEngine(
212
299
  rpID: configuration.rpID,
213
300
  rpName: configuration.rpName,
214
301
  origin: configuration.origin,
215
- allowSelfSignup: configuration.allowSelfSignup ?? false,
302
+ allowSelfSignup:
303
+ configuration.allowSelfSignup ?? settings.allowSelfSignup,
216
304
  flushBootstrapUrl: async (url) => {
217
305
  const flushed = await rsRegistry.flush(url);
218
306
  return { rid: flushed.rid };
@@ -273,6 +361,11 @@ export async function startEngine(
273
361
  });
274
362
  if (typeof base_url !== "string") {
275
363
  base_url = `http://localhost:${port}`;
364
+ } else if (
365
+ baseUrlFromCaller == null &&
366
+ (configuration.port === 0 || port !== settings.port)
367
+ ) {
368
+ base_url = `http://localhost:${port}`;
276
369
  }
277
370
  core.base_url = base_url;
278
371
 
@@ -319,6 +412,7 @@ export async function startEngine(
319
412
  base_url,
320
413
 
321
414
  pf,
415
+ core,
322
416
  uiECI,
323
417
  rsRegistry,
324
418
  auth,
package/src/logging.ts CHANGED
@@ -2,6 +2,7 @@ import * as fs from "fs";
2
2
  import * as readline from "readline";
3
3
  import { krlLogLevelCodeToHuman, PicoLogEntry } from "krl-stdlib";
4
4
  import * as path from "path";
5
+ import { getEngineRuntimeSettings } from "./engineConfig";
5
6
 
6
7
  const rfs = require("rotating-file-stream");
7
8
 
@@ -50,17 +51,12 @@ function getRotatingFileStream(filePath: string): NodeJS.WritableStream {
50
51
  }
51
52
 
52
53
  export function resolveEngineLogFilePath(home: string): string | null {
53
- const configured = process.env.PICO_ENGINE_LOG_FILE;
54
- if (
55
- configured === "0" ||
56
- configured === "-" ||
57
- configured === "stdout" ||
58
- configured === ""
59
- ) {
54
+ const settings = getEngineRuntimeSettings();
55
+ if (settings.logToStdout) {
60
56
  return null;
61
57
  }
62
- if (typeof configured === "string" && configured.length > 0) {
63
- return path.resolve(configured);
58
+ if (settings.logFile) {
59
+ return settings.logFile;
64
60
  }
65
61
  return path.resolve(home, "pico-engine.log");
66
62
  }
@@ -111,21 +107,19 @@ export async function getPicoLogs(
111
107
  });
112
108
 
113
109
  for await (const line of rl) {
114
- // Each line in the readline input will be successively available here as
115
- // `line`.
116
110
  if (line.indexOf(picoId) < 0) {
117
- continue; // not my pico
111
+ continue;
118
112
  }
119
113
  let entry;
120
114
  try {
121
115
  entry = JSON.parse(line);
122
116
  } catch (err) {}
123
117
  if (!entry || entry.picoId !== picoId) {
124
- continue; // not my pico
118
+ continue;
125
119
  }
126
120
  const time = new Date(entry.time);
127
121
  if (Date.now() - time.getTime() > 1000 * 60 * 60 * 12) {
128
- continue; // too old
122
+ continue;
129
123
  }
130
124
 
131
125
  const out: PicoLogEntry = {
@@ -7,6 +7,11 @@ import {
7
7
  } from "./channelEligibility";
8
8
  import { OAuthError } from "./errors";
9
9
  import { isChannelUnderRoot, meshRequiresOAuth as meshRequiresOAuthForEci } from "./meshOAuth";
10
+ import {
11
+ channelHasUnrestrictedAllow,
12
+ isDidcommIngressChannel,
13
+ wildcardSkyRequireBearerEnabled,
14
+ } from "../channelIdentityPolicy";
10
15
 
11
16
  const OAUTH_CHANNEL_PREFIX = "oauth-channel";
12
17
  const OAUTH_TOKEN_PREFIX = "oauth-token";
@@ -237,11 +242,14 @@ export class OAuthService {
237
242
  async skyRequiresBearer(eci: string): Promise<boolean> {
238
243
  try {
239
244
  const channel = this.lookupChannelReadOnly(eci);
245
+ if (isDidcommIngressChannel(channel)) {
246
+ return false;
247
+ }
240
248
  if (
241
- channel.tags.includes("didcomm") &&
242
- channel.tags.includes("ingress")
249
+ wildcardSkyRequireBearerEnabled() &&
250
+ channelHasUnrestrictedAllow(channel)
243
251
  ) {
244
- return false;
252
+ return true;
245
253
  }
246
254
  if (isOAuthEligibleChannel(channel)) {
247
255
  return true;
@@ -0,0 +1,131 @@
1
+ import type {
2
+ EventPolicy,
3
+ EventPolicyRule,
4
+ PolicyCeiling,
5
+ QueryPolicy,
6
+ QueryPolicyRule,
7
+ } from "pico-framework";
8
+
9
+ function isRecord(v: unknown): v is Record<string, unknown> {
10
+ return v != null && typeof v === "object" && !Array.isArray(v);
11
+ }
12
+
13
+ function cleanEventPolicyFromJson(orig: unknown): EventPolicy {
14
+ if (
15
+ !isRecord(orig) ||
16
+ !Array.isArray(orig.allow) ||
17
+ !Array.isArray(orig.deny)
18
+ ) {
19
+ throw new TypeError(
20
+ "eventPolicy expects { allow: EventPolicyRule[], deny: EventPolicyRule[] }",
21
+ );
22
+ }
23
+ const allow: EventPolicyRule[] = [];
24
+ for (const item of orig.allow) {
25
+ if (!isRecord(item) || typeof item.domain !== "string" || typeof item.name !== "string") {
26
+ throw new TypeError("eventPolicy allow entries need domain and name strings");
27
+ }
28
+ allow.push({ domain: item.domain.trim(), name: item.name.trim() });
29
+ }
30
+ const deny: EventPolicyRule[] = [];
31
+ for (const item of orig.deny) {
32
+ if (!isRecord(item) || typeof item.domain !== "string" || typeof item.name !== "string") {
33
+ throw new TypeError("eventPolicy deny entries need domain and name strings");
34
+ }
35
+ deny.push({ domain: item.domain.trim(), name: item.name.trim() });
36
+ }
37
+ return { allow, deny };
38
+ }
39
+
40
+ function cleanQueryPolicyFromJson(orig: unknown): QueryPolicy {
41
+ if (
42
+ !isRecord(orig) ||
43
+ !Array.isArray(orig.allow) ||
44
+ !Array.isArray(orig.deny)
45
+ ) {
46
+ throw new TypeError(
47
+ "queryPolicy expects { allow: QueryPolicyRule[], deny: QueryPolicyRule[] }",
48
+ );
49
+ }
50
+ const allow: QueryPolicyRule[] = [];
51
+ for (const item of orig.allow) {
52
+ if (!isRecord(item) || typeof item.rid !== "string" || typeof item.name !== "string") {
53
+ throw new TypeError("queryPolicy allow entries need rid and name strings");
54
+ }
55
+ allow.push({ rid: item.rid.trim(), name: item.name.trim() });
56
+ }
57
+ const deny: QueryPolicyRule[] = [];
58
+ for (const item of orig.deny) {
59
+ if (!isRecord(item) || typeof item.rid !== "string" || typeof item.name !== "string") {
60
+ throw new TypeError("queryPolicy deny entries need rid and name strings");
61
+ }
62
+ deny.push({ rid: item.rid.trim(), name: item.name.trim() });
63
+ }
64
+ return { allow, deny };
65
+ }
66
+
67
+ function parseEventRule(v: unknown): EventPolicyRule | null {
68
+ if (!isRecord(v)) return null;
69
+ if (typeof v.domain !== "string" || typeof v.name !== "string") return null;
70
+ return { domain: v.domain, name: v.name };
71
+ }
72
+
73
+ function parseQueryRule(v: unknown): QueryPolicyRule | null {
74
+ if (!isRecord(v)) return null;
75
+ if (typeof v.rid !== "string" || typeof v.name !== "string") return null;
76
+ return { rid: v.rid, name: v.name };
77
+ }
78
+
79
+ export function parsePolicyCeilingFromJson(
80
+ val: unknown,
81
+ fieldName: string,
82
+ ): PolicyCeiling | undefined {
83
+ if (val === undefined || val === null) {
84
+ return undefined;
85
+ }
86
+ if (!isRecord(val) || !val.eventPolicy || !val.queryPolicy) {
87
+ throw new Error(
88
+ `${fieldName} must be { eventPolicy: { allow, deny }, queryPolicy: { allow, deny } }`,
89
+ );
90
+ }
91
+ return {
92
+ eventPolicy: cleanEventPolicyFromJson(val.eventPolicy),
93
+ queryPolicy: cleanQueryPolicyFromJson(val.queryPolicy),
94
+ };
95
+ }
96
+
97
+ export function parseGlobalEventDenyFromJson(val: unknown): EventPolicyRule[] | undefined {
98
+ if (val === undefined || val === null) {
99
+ return undefined;
100
+ }
101
+ if (!Array.isArray(val)) {
102
+ throw new Error("globalEventDeny must be an array of { domain, name } rules");
103
+ }
104
+ const rules: EventPolicyRule[] = [];
105
+ for (const item of val) {
106
+ const rule = parseEventRule(item);
107
+ if (!rule) {
108
+ throw new Error("globalEventDeny: each entry needs domain and name strings");
109
+ }
110
+ rules.push(rule);
111
+ }
112
+ return rules;
113
+ }
114
+
115
+ export function parseGlobalQueryDenyFromJson(val: unknown): QueryPolicyRule[] | undefined {
116
+ if (val === undefined || val === null) {
117
+ return undefined;
118
+ }
119
+ if (!Array.isArray(val)) {
120
+ throw new Error("globalQueryDeny must be an array of { rid, name } rules");
121
+ }
122
+ const rules: QueryPolicyRule[] = [];
123
+ for (const item of val) {
124
+ const rule = parseQueryRule(item);
125
+ if (!rule) {
126
+ throw new Error("globalQueryDeny: each entry needs rid and name strings");
127
+ }
128
+ rules.push(rule);
129
+ }
130
+ return rules;
131
+ }
package/src/runMcp.ts ADDED
@@ -0,0 +1,30 @@
1
+ import {
2
+ installEngineRuntimeSettings,
3
+ resolveEngineSettings,
4
+ } from "./engineConfig";
5
+
6
+ /** Dev MCP stdio entry (pico-engine mcp --stdio). */
7
+ export async function runMcpCli(argv: string[]): Promise<void> {
8
+ const settings = resolveEngineSettings({});
9
+ installEngineRuntimeSettings(settings);
10
+ if (!process.env.PICO_ENGINE_BASE_URL) {
11
+ process.env.PICO_ENGINE_BASE_URL = settings.baseUrl;
12
+ }
13
+ if (!process.env.PICO_ENGINE_HOME) {
14
+ process.env.PICO_ENGINE_HOME = settings.home;
15
+ }
16
+ const args = argv.slice(1);
17
+ const stdio = args.includes("--stdio") || args.length === 0;
18
+ if (!stdio) {
19
+ console.error("Usage: pico-engine mcp --stdio");
20
+ console.error("");
21
+ console.error("Connects to a running local engine (PICO_ENGINE_BASE_URL).");
22
+ console.error("Requires localhost /c access or PICO_ENGINE_UI_ECI.");
23
+ process.exit(1);
24
+ }
25
+ // JS (not tsc): avoids pulling MCP SDK types into the main compile.
26
+ const { runDevMcpStdio } = require("../mcp/runStdio.js") as {
27
+ runDevMcpStdio: () => Promise<void>;
28
+ };
29
+ await runDevMcpStdio();
30
+ }