@introspection-ai/recipes 0.50.0 → 0.52.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 (249) hide show
  1. package/README.md +3 -3
  2. package/dist/api/api-bindings.d.ts +3 -0
  3. package/dist/api/api-bindings.d.ts.map +1 -0
  4. package/dist/api/api-bindings.js +2 -0
  5. package/dist/api/api-bindings.js.map +1 -0
  6. package/dist/api/session.d.ts +1 -0
  7. package/dist/api/session.d.ts.map +1 -1
  8. package/dist/api-bindings.d.ts +101 -0
  9. package/dist/api-bindings.d.ts.map +1 -0
  10. package/dist/api-bindings.js +406 -0
  11. package/dist/api-bindings.js.map +1 -0
  12. package/dist/channels/arguments.d.ts +116 -0
  13. package/dist/channels/arguments.d.ts.map +1 -0
  14. package/dist/channels/arguments.generated.d.ts +15 -0
  15. package/dist/channels/arguments.generated.d.ts.map +1 -0
  16. package/dist/channels/arguments.generated.js +181 -0
  17. package/dist/channels/arguments.generated.js.map +1 -0
  18. package/dist/channels/arguments.js +8 -0
  19. package/dist/channels/arguments.js.map +1 -0
  20. package/dist/channels/module.d.ts +5 -0
  21. package/dist/channels/module.d.ts.map +1 -1
  22. package/dist/channels/module.js +10 -5
  23. package/dist/channels/module.js.map +1 -1
  24. package/dist/channels/tools.d.ts.map +1 -1
  25. package/dist/channels/tools.js +22 -59
  26. package/dist/channels/tools.js.map +1 -1
  27. package/dist/channels/types.d.ts +5 -0
  28. package/dist/channels/types.d.ts.map +1 -1
  29. package/dist/child/session.d.ts +5 -0
  30. package/dist/child/session.d.ts.map +1 -1
  31. package/dist/child/session.js +2 -0
  32. package/dist/child/session.js.map +1 -1
  33. package/dist/clock.d.ts +80 -0
  34. package/dist/clock.d.ts.map +1 -0
  35. package/dist/clock.js +169 -0
  36. package/dist/clock.js.map +1 -0
  37. package/dist/command-parameters.d.ts +37 -5
  38. package/dist/command-parameters.d.ts.map +1 -1
  39. package/dist/command-parameters.js +73 -11
  40. package/dist/command-parameters.js.map +1 -1
  41. package/dist/connector-tools.d.ts +18 -0
  42. package/dist/connector-tools.d.ts.map +1 -1
  43. package/dist/connector-tools.js +49 -6
  44. package/dist/connector-tools.js.map +1 -1
  45. package/dist/documents/module.d.ts.map +1 -1
  46. package/dist/documents/module.js +1 -3
  47. package/dist/documents/module.js.map +1 -1
  48. package/dist/documents/tools.d.ts.map +1 -1
  49. package/dist/documents/tools.js +3 -3
  50. package/dist/documents/tools.js.map +1 -1
  51. package/dist/egress.d.ts +23 -0
  52. package/dist/egress.d.ts.map +1 -0
  53. package/dist/egress.js +36 -0
  54. package/dist/egress.js.map +1 -0
  55. package/dist/issues/index.d.ts +7 -0
  56. package/dist/issues/index.d.ts.map +1 -0
  57. package/dist/issues/index.js +4 -0
  58. package/dist/issues/index.js.map +1 -0
  59. package/dist/issues/module.d.ts +38 -0
  60. package/dist/issues/module.d.ts.map +1 -0
  61. package/dist/issues/module.js +114 -0
  62. package/dist/issues/module.js.map +1 -0
  63. package/dist/issues/tool.d.ts +95 -0
  64. package/dist/issues/tool.d.ts.map +1 -0
  65. package/dist/issues/tool.js +479 -0
  66. package/dist/issues/tool.js.map +1 -0
  67. package/dist/issues/types.d.ts +280 -0
  68. package/dist/issues/types.d.ts.map +1 -0
  69. package/dist/issues/types.js +79 -0
  70. package/dist/issues/types.js.map +1 -0
  71. package/dist/mcp/cli/command-context.d.ts +20 -1
  72. package/dist/mcp/cli/command-context.d.ts.map +1 -1
  73. package/dist/mcp/cli/command-context.js.map +1 -1
  74. package/dist/mcp/cli/core.d.ts +0 -2
  75. package/dist/mcp/cli/core.d.ts.map +1 -1
  76. package/dist/mcp/cli/core.js +9 -33
  77. package/dist/mcp/cli/core.js.map +1 -1
  78. package/dist/mcp/cli/handshake-retry.d.ts +5 -0
  79. package/dist/mcp/cli/handshake-retry.d.ts.map +1 -0
  80. package/dist/mcp/cli/handshake-retry.js +32 -0
  81. package/dist/mcp/cli/handshake-retry.js.map +1 -0
  82. package/dist/mcp/daemon/index.js +3 -4
  83. package/dist/mcp/daemon/index.js.map +1 -1
  84. package/dist/mcp/pi-client.d.ts +2 -0
  85. package/dist/mcp/pi-client.d.ts.map +1 -1
  86. package/dist/mcp/pi-client.js +5 -1
  87. package/dist/mcp/pi-client.js.map +1 -1
  88. package/dist/mcp/pi-mcp-runtime.d.ts +25 -0
  89. package/dist/mcp/pi-mcp-runtime.d.ts.map +1 -0
  90. package/dist/mcp/pi-mcp-runtime.js +215 -0
  91. package/dist/mcp/pi-mcp-runtime.js.map +1 -0
  92. package/dist/mcp/pi-runtime.d.ts +7 -0
  93. package/dist/mcp/pi-runtime.d.ts.map +1 -0
  94. package/dist/mcp/pi-runtime.js +26 -0
  95. package/dist/mcp/pi-runtime.js.map +1 -0
  96. package/dist/mcp-chunks/chunk-3UVHZECT.js +31 -0
  97. package/dist/mcp-chunks/{chunk-PO2SOBEN.js → chunk-CGJ2XOSF.js} +43 -35
  98. package/dist/mcp-chunks/{chunk-GTETFUPQ.js → chunk-IMG2JMBS.js} +8 -8
  99. package/dist/mcp-chunks/{chunk-UFV6SVQG.js → chunk-LQKMNWDE.js} +2 -2
  100. package/dist/mcp-chunks/{chunk-S2F7DDP5.js → chunk-QUDOU7MQ.js} +1 -1
  101. package/dist/mcp-chunks/{cli-IYD7Y7MO.js → cli-BM23ZXPJ.js} +54 -54
  102. package/dist/mcp-chunks/{client-5MNBV3Z7.js → client-RKTAKDAY.js} +7 -7
  103. package/dist/mcp-chunks/{daemon-command-V3B3EMXD.js → daemon-command-VU6WTFCJ.js} +8 -8
  104. package/dist/mcp-chunks/{generate-cli-runner-PW5WJ7KI.js → generate-cli-runner-JAAPSWGX.js} +12 -12
  105. package/dist/mcp-chunks/{generated-daemon-runtime-3C4NWGAU.js → generated-daemon-runtime-LX4L2X7Z.js} +8 -8
  106. package/dist/mcp-chunks/pi-mcp-runtime-GHDEPXUL.js +1231 -0
  107. package/dist/mcp-chunks/{runtime-RMI3XCYJ.js → runtime-T63YI7TC.js} +6 -6
  108. package/dist/mcp-chunks/{serve-command-UF5SVREV.js → serve-command-75P4VBJ6.js} +7 -7
  109. package/dist/mcp-daemon.js +21 -19
  110. package/dist/mcp-run-worker.js +11 -10
  111. package/dist/pi-extension.d.ts +3 -0
  112. package/dist/pi-extension.d.ts.map +1 -1
  113. package/dist/pi-extension.js +82 -18
  114. package/dist/pi-extension.js.map +1 -1
  115. package/dist/productivity/arguments.d.ts +298 -0
  116. package/dist/productivity/arguments.d.ts.map +1 -0
  117. package/dist/productivity/arguments.generated.d.ts +28 -0
  118. package/dist/productivity/arguments.generated.d.ts.map +1 -0
  119. package/dist/productivity/arguments.generated.js +489 -0
  120. package/dist/productivity/arguments.generated.js.map +1 -0
  121. package/dist/productivity/arguments.js +10 -0
  122. package/dist/productivity/arguments.js.map +1 -0
  123. package/dist/productivity/http.d.ts.map +1 -1
  124. package/dist/productivity/http.js +12 -22
  125. package/dist/productivity/http.js.map +1 -1
  126. package/dist/productivity/index.d.ts +1 -1
  127. package/dist/productivity/index.d.ts.map +1 -1
  128. package/dist/productivity/index.js +1 -1
  129. package/dist/productivity/index.js.map +1 -1
  130. package/dist/productivity/module.d.ts +15 -2
  131. package/dist/productivity/module.d.ts.map +1 -1
  132. package/dist/productivity/module.js +24 -21
  133. package/dist/productivity/module.js.map +1 -1
  134. package/dist/productivity/tools.d.ts +6 -0
  135. package/dist/productivity/tools.d.ts.map +1 -1
  136. package/dist/productivity/tools.js +64 -224
  137. package/dist/productivity/tools.js.map +1 -1
  138. package/dist/productivity/types.d.ts +2 -0
  139. package/dist/productivity/types.d.ts.map +1 -1
  140. package/dist/productivity/types.js.map +1 -1
  141. package/dist/recipe/agent.d.ts +40 -10
  142. package/dist/recipe/agent.d.ts.map +1 -1
  143. package/dist/recipe/agent.js +209 -30
  144. package/dist/recipe/agent.js.map +1 -1
  145. package/dist/recipe/companions.d.ts +2 -1
  146. package/dist/recipe/companions.d.ts.map +1 -1
  147. package/dist/recipe/companions.js +11 -9
  148. package/dist/recipe/companions.js.map +1 -1
  149. package/dist/recipe/manifest.generated.d.ts +4 -1
  150. package/dist/recipe/manifest.generated.d.ts.map +1 -1
  151. package/dist/recipe/manifest.generated.js +5 -2
  152. package/dist/recipe/manifest.generated.js.map +1 -1
  153. package/dist/recipe/package.d.ts +28 -3
  154. package/dist/recipe/package.d.ts.map +1 -1
  155. package/dist/recipe/package.js +155 -1
  156. package/dist/recipe/package.js.map +1 -1
  157. package/dist/recipe/providers.d.ts +62 -0
  158. package/dist/recipe/providers.d.ts.map +1 -0
  159. package/dist/recipe/providers.js +95 -0
  160. package/dist/recipe/providers.js.map +1 -0
  161. package/dist/recipe/resolve.d.ts +7 -3
  162. package/dist/recipe/resolve.d.ts.map +1 -1
  163. package/dist/recipe/resolve.js +7 -2
  164. package/dist/recipe/resolve.js.map +1 -1
  165. package/dist/run-controller.d.ts +6 -0
  166. package/dist/run-controller.d.ts.map +1 -1
  167. package/dist/run-controller.js +2 -0
  168. package/dist/run-controller.js.map +1 -1
  169. package/dist/search/egress.d.ts +12 -0
  170. package/dist/search/egress.d.ts.map +1 -0
  171. package/dist/search/egress.js +24 -0
  172. package/dist/search/egress.js.map +1 -0
  173. package/dist/search/http.d.ts +16 -0
  174. package/dist/search/http.d.ts.map +1 -0
  175. package/dist/search/http.js +75 -0
  176. package/dist/search/http.js.map +1 -0
  177. package/dist/search/index.d.ts +10 -0
  178. package/dist/search/index.d.ts.map +1 -0
  179. package/dist/search/index.js +5 -0
  180. package/dist/search/index.js.map +1 -0
  181. package/dist/search/mcp.d.ts +58 -0
  182. package/dist/search/mcp.d.ts.map +1 -0
  183. package/dist/search/mcp.js +84 -0
  184. package/dist/search/mcp.js.map +1 -0
  185. package/dist/search/module.d.ts +28 -0
  186. package/dist/search/module.d.ts.map +1 -0
  187. package/dist/search/module.js +49 -0
  188. package/dist/search/module.js.map +1 -0
  189. package/dist/search/tool.d.ts +101 -0
  190. package/dist/search/tool.d.ts.map +1 -0
  191. package/dist/search/tool.js +518 -0
  192. package/dist/search/tool.js.map +1 -0
  193. package/dist/search/types.d.ts +257 -0
  194. package/dist/search/types.d.ts.map +1 -0
  195. package/dist/search/types.js +63 -0
  196. package/dist/search/types.js.map +1 -0
  197. package/dist/session.d.ts +21 -1
  198. package/dist/session.d.ts.map +1 -1
  199. package/dist/session.js +132 -43
  200. package/dist/session.js.map +1 -1
  201. package/dist/test-utils.d.ts +2 -0
  202. package/dist/test-utils.d.ts.map +1 -1
  203. package/dist/test-utils.js +3 -1
  204. package/dist/test-utils.js.map +1 -1
  205. package/dist/tool-search.d.ts +9 -0
  206. package/dist/tool-search.d.ts.map +1 -1
  207. package/dist/tool-search.js +23 -0
  208. package/dist/tool-search.js.map +1 -1
  209. package/dist/tools/bridge.d.ts +44 -0
  210. package/dist/tools/bridge.d.ts.map +1 -0
  211. package/dist/tools/bridge.js +106 -0
  212. package/dist/tools/bridge.js.map +1 -0
  213. package/dist/tools/cli.d.ts +20 -0
  214. package/dist/tools/cli.d.ts.map +1 -0
  215. package/dist/tools/cli.js +246 -0
  216. package/dist/tools/cli.js.map +1 -0
  217. package/dist/tools/entry.d.ts +2 -0
  218. package/dist/tools/entry.d.ts.map +1 -0
  219. package/dist/tools/entry.js +3 -0
  220. package/dist/tools/entry.js.map +1 -0
  221. package/dist/tools/shell.d.ts +12 -0
  222. package/dist/tools/shell.d.ts.map +1 -0
  223. package/dist/tools/shell.js +50 -0
  224. package/dist/tools/shell.js.map +1 -0
  225. package/dist/tuning/tpe.d.ts +112 -0
  226. package/dist/tuning/tpe.d.ts.map +1 -0
  227. package/dist/tuning/tpe.js +286 -0
  228. package/dist/tuning/tpe.js.map +1 -0
  229. package/docs/README.md +4 -1
  230. package/docs/channels/README.md +10 -0
  231. package/docs/documents/README.md +20 -19
  232. package/docs/host-api.md +10 -0
  233. package/docs/issues/README.md +183 -0
  234. package/docs/mcp-configuration.md +67 -2
  235. package/docs/pi-extension.md +5 -0
  236. package/docs/productivity/README.md +8 -3
  237. package/docs/providers.md +321 -0
  238. package/docs/recipe-format.md +103 -32
  239. package/docs/search/README.md +818 -0
  240. package/package.json +33 -10
  241. package/skills/documents/SKILL.md +2 -1
  242. package/skills/search/SKILL.md +72 -0
  243. package/dist/mcp-chunks/{auth-command-M7TQE3AL.js → auth-command-UYFOGGQR.js} +6 -6
  244. package/dist/mcp-chunks/{call-command-7LD7UEFK.js → call-command-6U5BNDR7.js} +17 -17
  245. package/dist/mcp-chunks/{chunk-PSE442BC.js → chunk-36D4FILJ.js} +26 -26
  246. package/dist/mcp-chunks/{config-command-6DXILFNO.js → config-command-ZSPJI34E.js} +10 -10
  247. package/dist/mcp-chunks/{emit-ts-command-NDCDFDRM.js → emit-ts-command-SY4LQE4S.js} +3 -3
  248. package/dist/mcp-chunks/{inspect-cli-command-4MGF5CPP.js → inspect-cli-command-JPX4ON6N.js} +4 -4
  249. package/dist/mcp-chunks/{resource-command-SRFQQROJ.js → resource-command-DUY4SVE5.js} +4 -4
@@ -0,0 +1,25 @@
1
+ import { type Tool } from "@earendil-works/pi-mcp";
2
+ import type { McporterConfig } from "./index.js";
3
+ export interface PiMcpCallOptions {
4
+ args?: Record<string, unknown>;
5
+ timeoutMs?: number;
6
+ signal?: AbortSignal;
7
+ }
8
+ /**
9
+ * The part of mcporter's runtime the `mcp` command and its daemon use, on
10
+ * `pi-mcp` clients: one connection per server, opened on first use and kept
11
+ * for the life of the process. It reads the same generated config.
12
+ */
13
+ export declare class PiMcpRuntime {
14
+ private readonly config;
15
+ private readonly env;
16
+ private readonly servers;
17
+ constructor(config: McporterConfig, env?: NodeJS.ProcessEnv);
18
+ static fromConfigFile(path?: string | undefined, env?: NodeJS.ProcessEnv): PiMcpRuntime;
19
+ listServers(): string[];
20
+ private server;
21
+ listTools(server: string, _options?: Record<string, unknown>): Promise<Tool[]>;
22
+ callTool(server: string, tool: string, options?: PiMcpCallOptions): Promise<unknown>;
23
+ close(): Promise<void>;
24
+ }
25
+ //# sourceMappingURL=pi-mcp-runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pi-mcp-runtime.d.ts","sourceRoot":"","sources":["../../src/mcp/pi-mcp-runtime.ts"],"names":[],"mappings":"AAEA,OAAO,EAML,KAAK,IAAI,EACV,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAKjD,MAAM,WAAW,gBAAgB;IAC/B,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AA2LD;;;;GAIG;AACH,qBAAa,YAAY;IAIrB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,GAAG;IAJtB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAuC;IAE/D,YACmB,MAAM,EAAE,cAAc,EACtB,GAAG,GAAE,MAAM,CAAC,UAAwB,EAUtD;IAED,MAAM,CAAC,cAAc,CACnB,IAAI,GAAE,MAAM,GAAG,SAAuC,EACtD,GAAG,GAAE,MAAM,CAAC,UAAwB,GACnC,YAAY,CASd;IAED,WAAW,IAAI,MAAM,EAAE,CAEtB;IAED,OAAO,CAAC,MAAM;IAMR,SAAS,CACb,MAAM,EAAE,MAAM,EACd,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACjC,OAAO,CAAC,IAAI,EAAE,CAAC,CAQjB;IAEK,QAAQ,CACZ,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,gBAAqB,GAC7B,OAAO,CAAC,OAAO,CAAC,CAuBlB;IAEK,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAI3B;CACF"}
@@ -0,0 +1,215 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { McpClient, McpConnectionClosedError, McpHttpError, McpSessionExpiredError, StreamableHttpTransport, } from "@earendil-works/pi-mcp";
3
+ import { MCP_CLIENT_ENV } from "./pi-runtime.js";
4
+ // Statuses after which a request that only reads can be sent again.
5
+ const TRANSIENT_STATUSES = new Set([408, 429, 500, 502, 503, 504]);
6
+ const READ_RETRY_DELAYS_MS = [250, 1_000];
7
+ /** How long to wait before another attempt: cut short by the deadline or the signal. */
8
+ function pause(ms, deadline, signal) {
9
+ const wait = deadline === undefined ? ms : Math.min(ms, deadline - Date.now());
10
+ return new Promise((resolve) => {
11
+ const timer = setTimeout(done, Math.max(0, wait));
12
+ signal?.addEventListener("abort", done, { once: true });
13
+ function done() {
14
+ clearTimeout(timer);
15
+ signal?.removeEventListener("abort", done);
16
+ resolve();
17
+ }
18
+ });
19
+ }
20
+ function interpolateEnv(value, env) {
21
+ return value.replace(/\$\{([A-Z0-9_]+)\}/gi, (_match, name) => env[name] ?? "");
22
+ }
23
+ /**
24
+ * The status a failed request carries, in the form mcporter's error classifier
25
+ * reads, so the `mcp` command describes a failure as it did on mcporter.
26
+ */
27
+ function describedError(error, server) {
28
+ if (error instanceof McpHttpError) {
29
+ return Object.assign(new Error(`HTTP ${error.status}: ${error.message}`, { cause: error }), {
30
+ code: error.status,
31
+ });
32
+ }
33
+ if (error instanceof Error && !(error instanceof McpConnectionClosedError))
34
+ return error;
35
+ return new Error(`MCP server '${server}' closed the connection: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
36
+ }
37
+ /** A request the server did not run, so sending it again cannot repeat a side effect. */
38
+ function notRun(error) {
39
+ return error instanceof McpSessionExpiredError;
40
+ }
41
+ // `fetch` reports a network failure, including a connection dropped mid-body,
42
+ // as a `TypeError`.
43
+ function transient(error) {
44
+ return ((error instanceof McpHttpError && TRANSIENT_STATUSES.has(error.status)) ||
45
+ error instanceof McpConnectionClosedError ||
46
+ error instanceof TypeError);
47
+ }
48
+ class ServerConnection {
49
+ id;
50
+ config;
51
+ env;
52
+ client;
53
+ connected;
54
+ constructor(id, config, env) {
55
+ this.id = id;
56
+ this.config = config;
57
+ this.env = env;
58
+ }
59
+ connect() {
60
+ this.client ??= (async () => {
61
+ const client = new McpClient({
62
+ name: "introspection-recipes",
63
+ version: "1",
64
+ });
65
+ client.onClose(() => this.drop(client));
66
+ await client.connect(new StreamableHttpTransport({
67
+ url: this.config.baseUrl,
68
+ headers: Object.fromEntries(Object.entries(this.config.headers ?? {}).map(([name, value]) => [
69
+ name,
70
+ interpolateEnv(value, this.env),
71
+ ])),
72
+ }));
73
+ this.connected = client;
74
+ return client;
75
+ })().catch((error) => {
76
+ this.client = undefined;
77
+ throw error;
78
+ });
79
+ return this.client;
80
+ }
81
+ /** Forgets `client`, so the next request connects afresh. A failed connect clears itself. */
82
+ drop(client) {
83
+ if (this.connected !== client)
84
+ return;
85
+ this.connected = undefined;
86
+ this.client = undefined;
87
+ }
88
+ /**
89
+ * Runs `request` on a live connection, connecting first if needed. What was
90
+ * never sent is retried: a failed connect, and a request whose MCP session
91
+ * had expired. A read is also retried after a transient failure. A
92
+ * `tools/call` that may have run is never sent twice.
93
+ */
94
+ async request(read, request, bounds = {}) {
95
+ const { deadline, signal } = bounds;
96
+ // Checked before every attempt, so a retry never sends a call after the
97
+ // caller's time ran out or it was cancelled.
98
+ const remaining = () => {
99
+ if (signal?.aborted)
100
+ throw describedError(signal.reason ?? new Error("aborted"), this.id);
101
+ if (deadline === undefined)
102
+ return undefined;
103
+ const left = deadline - Date.now();
104
+ if (left <= 0)
105
+ throw new Error(`MCP call to '${this.id}' timed out before it could be sent`);
106
+ return left;
107
+ };
108
+ for (let attempt = 0;; attempt += 1) {
109
+ remaining();
110
+ let client;
111
+ try {
112
+ client = await this.connect();
113
+ }
114
+ catch (error) {
115
+ // Only a server that answered with a transient status is tried again:
116
+ // one that refuses connections fails at once, so an offline optional
117
+ // server never holds up the others.
118
+ const answeredTransient = error instanceof McpHttpError && TRANSIENT_STATUSES.has(error.status);
119
+ if (!answeredTransient || attempt >= READ_RETRY_DELAYS_MS.length) {
120
+ throw describedError(error, this.id);
121
+ }
122
+ await pause(READ_RETRY_DELAYS_MS[attempt], deadline, signal);
123
+ continue;
124
+ }
125
+ try {
126
+ return await request(client, remaining());
127
+ }
128
+ catch (error) {
129
+ // An HTTP error status leaves the session usable; a lost connection
130
+ // or an expired session does not.
131
+ if (notRun(error) ||
132
+ error instanceof McpConnectionClosedError ||
133
+ error instanceof TypeError) {
134
+ this.drop(client);
135
+ void client.close().catch(() => { });
136
+ }
137
+ if (notRun(error) && attempt === 0)
138
+ continue;
139
+ if (read && transient(error) && attempt < READ_RETRY_DELAYS_MS.length) {
140
+ await pause(READ_RETRY_DELAYS_MS[attempt], deadline, signal);
141
+ continue;
142
+ }
143
+ throw describedError(error, this.id);
144
+ }
145
+ }
146
+ }
147
+ async close() {
148
+ const client = this.client;
149
+ this.client = undefined;
150
+ this.connected = undefined;
151
+ await client?.then((value) => value.close()).catch(() => { });
152
+ }
153
+ }
154
+ /**
155
+ * The part of mcporter's runtime the `mcp` command and its daemon use, on
156
+ * `pi-mcp` clients: one connection per server, opened on first use and kept
157
+ * for the life of the process. It reads the same generated config.
158
+ */
159
+ export class PiMcpRuntime {
160
+ config;
161
+ env;
162
+ servers = new Map();
163
+ constructor(config, env = process.env) {
164
+ this.config = config;
165
+ this.env = env;
166
+ for (const [id, server] of Object.entries(config.mcpServers)) {
167
+ if (server.auth === "oauth") {
168
+ throw new Error(`MCP server '${id}' is bound with an OAuth flow, which the pi-mcp client does not run; set ${MCP_CLIENT_ENV}=mcporter to use mcporter for it`);
169
+ }
170
+ this.servers.set(id, new ServerConnection(id, server, env));
171
+ }
172
+ }
173
+ static fromConfigFile(path = process.env.MCPORTER_CONFIG, env = process.env) {
174
+ if (!path)
175
+ throw new Error("MCPORTER_CONFIG is not set; the MCP session has no server config");
176
+ return new PiMcpRuntime(JSON.parse(readFileSync(path, "utf8")), env);
177
+ }
178
+ listServers() {
179
+ return [...this.servers.keys()];
180
+ }
181
+ server(id) {
182
+ const server = this.servers.get(id);
183
+ if (!server)
184
+ throw new Error(`Unknown MCP server '${id}'`);
185
+ return server;
186
+ }
187
+ async listTools(server, _options) {
188
+ const tools = await this.server(server).request(true, (client) => client.listTools());
189
+ const allowed = this.config.mcpServers[server]?.allowedTools;
190
+ return allowed
191
+ ? tools.filter((tool) => allowed.includes(tool.name))
192
+ : tools;
193
+ }
194
+ async callTool(server, tool, options = {}) {
195
+ const allowed = this.config.mcpServers[server]?.allowedTools;
196
+ if (allowed && !allowed.includes(tool)) {
197
+ throw new Error(`MCP tool '${server}.${tool}' is not in this session's allowed tools.`);
198
+ }
199
+ // The timeout covers connecting and any retry, not only the call itself.
200
+ const deadline = options.timeoutMs
201
+ ? Date.now() + options.timeoutMs
202
+ : undefined;
203
+ return await this.server(server).request(false, (client, remainingMs) => client.callTool(tool, options.args ?? {}, {
204
+ ...(remainingMs !== undefined ? { timeoutMs: remainingMs } : {}),
205
+ ...(options.signal ? { signal: options.signal } : {}),
206
+ }), {
207
+ ...(deadline !== undefined ? { deadline } : {}),
208
+ ...(options.signal ? { signal: options.signal } : {}),
209
+ });
210
+ }
211
+ async close() {
212
+ await Promise.all([...this.servers.values()].map((server) => server.close()));
213
+ }
214
+ }
215
+ //# sourceMappingURL=pi-mcp-runtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pi-mcp-runtime.js","sourceRoot":"","sources":["../../src/mcp/pi-mcp-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,OAAO,EACL,SAAS,EACT,wBAAwB,EACxB,YAAY,EACZ,sBAAsB,EACtB,uBAAuB,GAExB,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAUjD,oEAAoE;AACpE,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;AACnE,MAAM,oBA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,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAC3D,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,7 @@
1
+ import type { McpRuntime } from "./cli/command-context.js";
2
+ /** `mcporter` keeps the `mcp` command on mcporter's runtime, for a release or two after pi-mcp became the default. */
3
+ export declare const MCP_CLIENT_ENV = "PI_RECIPES_MCP_CLIENT";
4
+ export declare function usesPiMcpClient(env?: NodeJS.ProcessEnv): boolean;
5
+ /** The session's MCP runtime: pi-mcp's, or mcporter's when {@link MCP_CLIENT_ENV} asks for it or pi-mcp cannot serve the config. */
6
+ export declare function createMcpRuntime(configPath?: string | undefined): Promise<McpRuntime>;
7
+ //# sourceMappingURL=pi-runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pi-runtime.d.ts","sourceRoot":"","sources":["../../src/mcp/pi-runtime.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAG3D,sHAAsH;AACtH,eAAO,MAAM,cAAc,0BAA0B,CAAC;AAEtD,wBAAgB,eAAe,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,OAAO,CAE7E;AAeD,oIAAoI;AACpI,wBAAsB,gBAAgB,CACpC,UAAU,GAAE,MAAM,GAAG,SAAuC,GAC3D,OAAO,CAAC,UAAU,CAAC,CAOrB"}
@@ -0,0 +1,26 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { createRuntime } from "mcporter";
3
+ /** `mcporter` keeps the `mcp` command on mcporter's runtime, for a release or two after pi-mcp became the default. */
4
+ export const MCP_CLIENT_ENV = "PI_RECIPES_MCP_CLIENT";
5
+ export function usesPiMcpClient(env = process.env) {
6
+ return env[MCP_CLIENT_ENV]?.trim() !== "mcporter";
7
+ }
8
+ /**
9
+ * Whether pi-mcp can hold this session's connections. It needs the session's
10
+ * config, runs no OAuth flow (mcporter does, on a person's machine) and has
11
+ * no HTTP/1 fetch, so a config asking for either stays on mcporter.
12
+ */
13
+ function piMcpServes(configPath) {
14
+ if (!configPath)
15
+ return false;
16
+ const config = JSON.parse(readFileSync(configPath, "utf8"));
17
+ return !Object.values(config.mcpServers ?? {}).some((server) => server.auth === "oauth" || server.httpFetch === "node-http1");
18
+ }
19
+ /** The session's MCP runtime: pi-mcp's, or mcporter's when {@link MCP_CLIENT_ENV} asks for it or pi-mcp cannot serve the config. */
20
+ export async function createMcpRuntime(configPath = process.env.MCPORTER_CONFIG) {
21
+ // Loaded only here, so a session on mcporter never loads pi-mcp.
22
+ if (usesPiMcpClient() && piMcpServes(configPath))
23
+ return (await import("./pi-mcp-runtime.js")).PiMcpRuntime.fromConfigFile(configPath);
24
+ return await createRuntime(configPath ? { configPath } : {});
25
+ }
26
+ //# sourceMappingURL=pi-runtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pi-runtime.js","sourceRoot":"","sources":["../../src/mcp/pi-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAKzC,sHAAsH;AACtH,MAAM,CAAC,MAAM,cAAc,GAAG,uBAAuB,CAAC;AAEtD,MAAM,UAAU,eAAe,CAAC,GAAG,GAAsB,OAAO,CAAC,GAAG;IAClE,OAAO,GAAG,CAAC,cAAc,CAAC,EAAE,IAAI,EAAE,KAAK,UAAU,CAAC;AACpD,CAAC;AAED;;;;GAIG;AACH,SAAS,WAAW,CAAC,UAA8B;IACjD,IAAI,CAAC,UAAU;QAAE,OAAO,KAAK,CAAC;IAC9B,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,UAAU,EAAE,MAAM,CAAC,CAAmB,CAAC;IAC9E,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC,IAAI,CACjD,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,OAAO,IAAI,MAAM,CAAC,SAAS,KAAK,YAAY,CACzE,CAAC;AACJ,CAAC;AAED,oIAAoI;AACpI,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,UAAU,GAAuB,OAAO,CAAC,GAAG,CAAC,eAAe;IAE5D,iEAAiE;IACjE,IAAI,eAAe,EAAE,IAAI,WAAW,CAAC,UAAU,CAAC;QAC9C,OAAO,CAAC,MAAM,MAAM,CAAC,qBAAqB,CAAC,CAAC,CAAC,YAAY,CAAC,cAAc,CACtE,UAAU,CACX,CAAC;IACJ,OAAO,MAAM,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AAC/D,CAAC"}
@@ -0,0 +1,31 @@
1
+ import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
+ import {
3
+ createRuntime
4
+ } from "./chunk-36D4FILJ.js";
5
+
6
+ // src/mcp/pi-runtime.ts
7
+ import { readFileSync } from "node:fs";
8
+ var MCP_CLIENT_ENV = "PI_RECIPES_MCP_CLIENT";
9
+ function usesPiMcpClient(env = process.env) {
10
+ return env[MCP_CLIENT_ENV]?.trim() !== "mcporter";
11
+ }
12
+ function piMcpServes(configPath) {
13
+ if (!configPath) return false;
14
+ const config = JSON.parse(readFileSync(configPath, "utf8"));
15
+ return !Object.values(config.mcpServers ?? {}).some(
16
+ (server) => server.auth === "oauth" || server.httpFetch === "node-http1"
17
+ );
18
+ }
19
+ async function createMcpRuntime(configPath = process.env.MCPORTER_CONFIG) {
20
+ if (usesPiMcpClient() && piMcpServes(configPath))
21
+ return (await import("./pi-mcp-runtime-GHDEPXUL.js")).PiMcpRuntime.fromConfigFile(
22
+ configPath
23
+ );
24
+ return await createRuntime(configPath ? { configPath } : {});
25
+ }
26
+
27
+ export {
28
+ MCP_CLIENT_ENV,
29
+ usesPiMcpClient,
30
+ createMcpRuntime
31
+ };
@@ -1,11 +1,12 @@
1
1
  import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
+ import {
3
+ createMcpRuntime,
4
+ usesPiMcpClient
5
+ } from "./chunk-3UVHZECT.js";
2
6
  import {
3
7
  createCallResult,
4
8
  describeConnectionIssue
5
9
  } from "./chunk-3SXP4S2A.js";
6
- import {
7
- createRuntime
8
- } from "./chunk-PSE442BC.js";
9
10
  import {
10
11
  __commonJS,
11
12
  __require,
@@ -10188,11 +10189,40 @@ import {
10188
10189
  writeFile
10189
10190
  } from "node:fs/promises";
10190
10191
  import { dirname as dirname2, join as join2 } from "node:path";
10191
- import { setTimeout as delay } from "node:timers/promises";
10192
+ import { setTimeout as delay2 } from "node:timers/promises";
10192
10193
  import { stdin as input, stderr, stdout } from "node:process";
10193
10194
  import { inspect, parseArgs } from "node:util";
10194
10195
  import { isMainThread, Worker } from "node:worker_threads";
10195
10196
 
10197
+ // src/mcp/cli/handshake-retry.ts
10198
+ import { setTimeout as delay } from "node:timers/promises";
10199
+ var HANDSHAKE_RETRY_DELAYS_MS = [500, 1500];
10200
+ function refusedHandshake(error) {
10201
+ let current = error;
10202
+ for (let depth = 0; current instanceof Error && depth < 5; depth += 1) {
10203
+ if (/Version negotiation failed: the server answered the probe with HTTP 5\d\d/.test(
10204
+ current.message
10205
+ )) {
10206
+ return true;
10207
+ }
10208
+ current = current.cause;
10209
+ }
10210
+ return false;
10211
+ }
10212
+ async function callToolWithHandshakeRetry(runtime, server, tool, options, deadlineMs = Number.POSITIVE_INFINITY) {
10213
+ for (let attempt = 0; ; attempt += 1) {
10214
+ try {
10215
+ return await runtime.callTool(server, tool, options());
10216
+ } catch (error) {
10217
+ const wait = HANDSHAKE_RETRY_DELAYS_MS[attempt];
10218
+ if (wait === void 0 || !refusedHandshake(error) || Date.now() + wait >= deadlineMs) {
10219
+ throw error;
10220
+ }
10221
+ await delay(wait);
10222
+ }
10223
+ }
10224
+ }
10225
+
10196
10226
  // src/mcp/contract.ts
10197
10227
  var MAX_EXAMPLE_ARRAY_ITEMS = 3;
10198
10228
  var SAFE_CLI_KEY = /^[A-Za-z_][A-Za-z0-9_.-]*$/;
@@ -12516,6 +12546,8 @@ var PI_KEYS = /* @__PURE__ */ new Set([
12516
12546
  "channels",
12517
12547
  "documents",
12518
12548
  "productivity",
12549
+ "search",
12550
+ "issues",
12519
12551
  "evals",
12520
12552
  "mcp",
12521
12553
  "runtime"
@@ -12816,7 +12848,7 @@ function loadMcporterCli() {
12816
12848
  if (mcporterCliPromise) return mcporterCliPromise;
12817
12849
  const previousDisableAutorun = process.env.MCPORTER_DISABLE_AUTORUN;
12818
12850
  process.env.MCPORTER_DISABLE_AUTORUN = "1";
12819
- mcporterCliPromise = import("./cli-IYD7Y7MO.js").finally(() => {
12851
+ mcporterCliPromise = import("./cli-BM23ZXPJ.js").finally(() => {
12820
12852
  if (previousDisableAutorun === void 0) {
12821
12853
  delete process.env.MCPORTER_DISABLE_AUTORUN;
12822
12854
  } else {
@@ -12827,7 +12859,7 @@ function loadMcporterCli() {
12827
12859
  }
12828
12860
  async function acquireRuntime() {
12829
12861
  const shared = currentMcpCommandContext()?.runtime;
12830
- return shared ? { runtime: shared, owned: false } : { runtime: await createRuntime(), owned: true };
12862
+ return shared ? { runtime: shared, owned: false } : { runtime: await createMcpRuntime(), owned: true };
12831
12863
  }
12832
12864
  async function closeOwnedRuntime(runtime, owned) {
12833
12865
  if (owned) await runtime.close();
@@ -13217,7 +13249,7 @@ async function discoverServerCatalog(runtime, server, timeoutMs) {
13217
13249
  }
13218
13250
  const remainingMs = deadline - Date.now();
13219
13251
  if (remainingMs > 0) {
13220
- await delay(Math.min(CATALOG_LOCK_POLL_MS, remainingMs));
13252
+ await delay2(Math.min(CATALOG_LOCK_POLL_MS, remainingMs));
13221
13253
  }
13222
13254
  }
13223
13255
  if (!ownsLock) {
@@ -13747,32 +13779,6 @@ function improveRunToolError(error, server, tool, knownTools) {
13747
13779
  cause: error
13748
13780
  });
13749
13781
  }
13750
- var HANDSHAKE_RETRY_DELAYS_MS = [500, 1500];
13751
- function refusedHandshake(error) {
13752
- let current = error;
13753
- for (let depth = 0; current instanceof Error && depth < 5; depth += 1) {
13754
- if (/Version negotiation failed: the server answered the probe with HTTP 5\d\d/.test(
13755
- current.message
13756
- )) {
13757
- return true;
13758
- }
13759
- current = current.cause;
13760
- }
13761
- return false;
13762
- }
13763
- async function callToolWithHandshakeRetry(runtime, server, tool, options, deadlineMs = Number.POSITIVE_INFINITY) {
13764
- for (let attempt = 0; ; attempt += 1) {
13765
- try {
13766
- return await runtime.callTool(server, tool, options());
13767
- } catch (error) {
13768
- const wait = HANDSHAKE_RETRY_DELAYS_MS[attempt];
13769
- if (wait === void 0 || !refusedHandshake(error) || Date.now() + wait >= deadlineMs) {
13770
- throw error;
13771
- }
13772
- await delay(wait);
13773
- }
13774
- }
13775
- }
13776
13782
  async function createTools(opts) {
13777
13783
  const { runtime, owned } = await acquireRuntime();
13778
13784
  const session = await readSession();
@@ -14285,6 +14291,7 @@ async function callWithMcporter(args) {
14285
14291
  let owned = false;
14286
14292
  try {
14287
14293
  ({ runtime, owned } = await acquireRuntime());
14294
+ if (usesPiMcpClient()) return await callWithSharedRuntime(runtime, args);
14288
14295
  const { handleCall } = await loadMcporterCli();
14289
14296
  await handleCall(runtime, args);
14290
14297
  return process.exitCode ?? 0;
@@ -14345,12 +14352,13 @@ async function callWithSharedRuntime(runtime, args) {
14345
14352
  parsed.schemaStringCoercionCandidates,
14346
14353
  timeoutMs
14347
14354
  );
14355
+ const signal = currentMcpCommandContext()?.signal;
14348
14356
  const call = callToolWithHandshakeRetry(runtime, server, tool, () => ({
14349
14357
  args: values,
14350
14358
  timeoutMs,
14351
- disableOAuth: true
14359
+ disableOAuth: true,
14360
+ ...signal ? { signal } : {}
14352
14361
  }));
14353
- const signal = currentMcpCommandContext()?.signal;
14354
14362
  let cancelled;
14355
14363
  const raw = signal ? await Promise.race([
14356
14364
  call,
@@ -16,18 +16,11 @@ import {
16
16
  resolveSystemPowerShellPath,
17
17
  secureDaemonDirectory,
18
18
  upgradeLegacyDaemonDirectory
19
- } from "./chunk-PSE442BC.js";
19
+ } from "./chunk-36D4FILJ.js";
20
20
  import {
21
21
  NON_INTERACTIVE_ELICITATION_HINT,
22
22
  createNonInteractiveElicitationResponder
23
23
  } from "./chunk-F2X4Y2TQ.js";
24
- import {
25
- isOAuthFlowError,
26
- resolveOAuthTimeoutFromEnv
27
- } from "./chunk-2YV72LUA.js";
28
- import {
29
- withRuntimeEnvironment
30
- } from "./chunk-V42T3QNK.js";
31
24
  import {
32
25
  MCPORTER_VERSION
33
26
  } from "./chunk-QNXOIF5U.js";
@@ -35,6 +28,13 @@ import {
35
28
  getChromeDevtoolsRelayDecision,
36
29
  normalizeTimeout
37
30
  } from "./chunk-6O42UGLI.js";
31
+ import {
32
+ isOAuthFlowError,
33
+ resolveOAuthTimeoutFromEnv
34
+ } from "./chunk-2YV72LUA.js";
35
+ import {
36
+ withRuntimeEnvironment
37
+ } from "./chunk-V42T3QNK.js";
38
38
  import {
39
39
  RawEntrySchema,
40
40
  VaultEncryptionPolicySchema,
@@ -20,12 +20,12 @@ import {
20
20
  resolveProgressInterval,
21
21
  stopVerifiedLegacyDaemons,
22
22
  waitForDaemonReady
23
- } from "./chunk-GTETFUPQ.js";
23
+ } from "./chunk-IMG2JMBS.js";
24
24
  import {
25
25
  canonicalUserConfiguration,
26
26
  getDaemonLogPath,
27
27
  secureDaemonDirectory
28
- } from "./chunk-PSE442BC.js";
28
+ } from "./chunk-36D4FILJ.js";
29
29
  import {
30
30
  ChromeDevtoolsRelayDiscoveryError
31
31
  } from "./chunk-6O42UGLI.js";
@@ -4,7 +4,7 @@ import {
4
4
  } from "./chunk-HNQSUT44.js";
5
5
  import {
6
6
  DaemonClient
7
- } from "./chunk-GTETFUPQ.js";
7
+ } from "./chunk-IMG2JMBS.js";
8
8
  import {
9
9
  isKeepAliveServer
10
10
  } from "./chunk-MHUMLEBO.js";