pi-codemcp 1.2.1 → 1.3.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/src/tools.ts CHANGED
@@ -144,6 +144,12 @@ const ExecuteParameters = Type.Object({
144
144
  description:
145
145
  "Sandboxed Python body. Call typed SDK methods such as await linear.list_issues(arguments) and return a compact final value.",
146
146
  }),
147
+ inputRef: Type.Optional(
148
+ Type.String({
149
+ minLength: 1,
150
+ description: "Opaque retained-result reference exposed to sandbox code as input",
151
+ }),
152
+ ),
147
153
  });
148
154
 
149
155
  export function registerCodeMcpTools(
@@ -159,7 +165,7 @@ export function registerCodeMcpTools(
159
165
  promptSnippet: "Discover compact MCP capabilities or inventory",
160
166
  promptGuidelines: [...SEARCH_PROMPT_GUIDELINES],
161
167
  parameters: SearchParameters,
162
- async execute(_toolCallId, params, signal, onUpdate) {
168
+ async execute(toolCallId, params, signal, onUpdate) {
163
169
  onUpdate?.({
164
170
  content: [{ type: "text", text: "Searching MCP tools..." }],
165
171
  details: undefined,
@@ -173,6 +179,7 @@ export function registerCodeMcpTools(
173
179
  limit: params.limit ?? 5,
174
180
  cursor: params.cursor ?? 0,
175
181
  ...(params.server === undefined ? {} : { server: params.server }),
182
+ trace_id: toolCallId,
176
183
  },
177
184
  signal,
178
185
  );
@@ -247,12 +254,16 @@ export function registerCodeMcpTools(
247
254
  promptSnippet: "Load exact typed contracts for selected MCP calls",
248
255
  promptGuidelines: [...INSPECT_PROMPT_GUIDELINES],
249
256
  parameters: InspectParameters,
250
- async execute(_toolCallId, params, signal, onUpdate) {
257
+ async execute(toolCallId, params, signal, onUpdate) {
251
258
  onUpdate?.({
252
259
  content: [{ type: "text", text: "Inspecting MCP tool contracts..." }],
253
260
  details: undefined,
254
261
  });
255
- const result = await lifecycle.request("inspect", { calls: params.calls }, signal);
262
+ const result = await lifecycle.request(
263
+ "inspect",
264
+ { calls: params.calls, trace_id: toolCallId },
265
+ signal,
266
+ );
256
267
  const output = formatCodeMcpOutput(result, outputLimits(lifecycle));
257
268
  const results = Array.isArray(result.results) ? result.results : [];
258
269
  return {
@@ -292,23 +303,34 @@ export function registerCodeMcpTools(
292
303
  name: "codemcp_execute",
293
304
  label: "MCP Execute",
294
305
  description:
295
- "Type-check and execute one bounded sandboxed Python MCP call graph. Use it when code can deterministically process intermediate results; preserve a model turn for semantic decisions or approvals. The sandbox has no host filesystem, environment, network, or subprocess access. Oversized results fail with bounded shape, size, and sample diagnostics.",
306
+ "Type-check and execute one bounded sandboxed Python MCP call graph. Filter, aggregate, or sample upstream data inside the sandbox instead of returning raw payloads; an optional inputRef exposes a retained oversized value as input without repeating upstream calls. Preserve a model turn for semantic decisions or approvals. The sandbox has no host filesystem, environment, network, or subprocess access. Oversized results fail with bounded shape, size, and sample diagnostics.",
296
307
  promptSnippet: "Run a bounded typed MCP workflow and return a compact result",
297
308
  promptGuidelines: [...EXECUTE_PROMPT_GUIDELINES],
298
309
  parameters: ExecuteParameters,
299
- async execute(_toolCallId, params, signal, onUpdate) {
310
+ async execute(toolCallId, params, signal, onUpdate) {
300
311
  onUpdate?.({
301
312
  content: [{ type: "text", text: "Type-checking MCP chain..." }],
302
313
  details: undefined,
303
314
  });
304
- const result = await lifecycle.request("execute", { code: params.code }, signal);
315
+ const result = await lifecycle.request(
316
+ "execute",
317
+ {
318
+ code: params.code,
319
+ trace_id: toolCallId,
320
+ ...(params.inputRef === undefined ? {} : { input_ref: params.inputRef }),
321
+ },
322
+ signal,
323
+ );
305
324
  const ok = result.ok === true;
306
325
  const modelValue = ok
307
326
  ? result.result
308
327
  : {
309
328
  failure_stage: result.failure_stage,
310
329
  error: result.error,
330
+ failure: result.failure,
311
331
  shape: result.shape,
332
+ result_ref: result.result_ref,
333
+ expires_in_seconds: result.expires_in_seconds,
312
334
  calls_made: result.calls_made,
313
335
  chain_calls: result.chain_calls,
314
336
  };
@@ -365,7 +387,7 @@ export function registerCodeMcpTools(
365
387
  promptSnippet: "Save a repeated MCP execution as a typed reusable native tool",
366
388
  promptGuidelines: [...SAVE_CHAIN_PROMPT_GUIDELINES],
367
389
  parameters: SaveChainParameters,
368
- async execute(_toolCallId, params, signal, onUpdate) {
390
+ async execute(toolCallId, params, signal, onUpdate) {
369
391
  const scope = requireChainScope(params.scope ?? "project");
370
392
  if (scope === "project" && lifecycle.projectChainsPath === undefined) {
371
393
  throw new Error(
@@ -385,6 +407,7 @@ export function registerCodeMcpTools(
385
407
  inputSchema: params.inputSchema,
386
408
  outputSchema: params.outputSchema,
387
409
  },
410
+ toolCallId,
388
411
  signal,
389
412
  );
390
413
  const result = {
@@ -455,11 +478,11 @@ export function registerCodeMcpTools(
455
478
  promptSnippet: "List or explicitly manage saved MCP chains",
456
479
  promptGuidelines: [...MANAGE_CHAIN_PROMPT_GUIDELINES],
457
480
  parameters: ManageChainsParameters,
458
- async execute(_toolCallId, params, signal, onUpdate) {
481
+ async execute(toolCallId, params, signal, onUpdate) {
459
482
  const action = params.action;
460
483
  let views: SavedChainView[];
461
484
  if (action === "list") {
462
- views = await chains.list(signal);
485
+ views = await chains.list(toolCallId, signal);
463
486
  } else {
464
487
  if (params.confirmedByUser !== true) {
465
488
  throw new Error(`${action} requires confirmedByUser=true after explicit user approval`);
@@ -476,16 +499,13 @@ export function registerCodeMcpTools(
476
499
  details: undefined,
477
500
  });
478
501
  if (action === "enable" || action === "disable") {
479
- const applied = await chains.applyEnabled(
480
- [{ name: params.name, scope, enabled: action === "enable" }],
481
- signal,
482
- );
483
- views = applied.chains;
502
+ await chains.setEnabled(params.name, scope, action === "enable", toolCallId, signal);
503
+ views = await chains.list(toolCallId, signal);
484
504
  } else if (action === "revalidate") {
485
- await chains.revalidate(params.name, scope, signal);
486
- views = await chains.list(signal);
505
+ await chains.revalidate(params.name, scope, toolCallId, signal);
506
+ views = await chains.list(toolCallId, signal);
487
507
  } else {
488
- views = await chains.delete(params.name, scope, signal);
508
+ views = await chains.delete(params.name, scope, toolCallId, signal);
489
509
  }
490
510
  }
491
511
  const result = {