@absolutejs/mcp 0.22.0 → 0.23.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/CHANGELOG.md CHANGED
@@ -6,6 +6,12 @@ This file is generated by `absolute-changelog` from the entries in
6
6
  `changelog/`. Edit an entry, not this file — and add new ones under
7
7
  `changelog/unreleased/`.
8
8
 
9
+ ## 0.23.0 — 2026-09-13
10
+
11
+ ### Added
12
+
13
+ - **Preserve saved credit work results in identical text and structured host responses** (`createCreditWorkResult`)
14
+
9
15
  ## 0.22.0 — 2026-09-13
10
16
 
11
17
  ### Added
package/README.md CHANGED
@@ -437,3 +437,27 @@ on the Change Date.
437
437
  ## Interactive MCP Apps
438
438
 
439
439
  `createBillingApps()` adds reusable read-only credit, usage and receipt views with the official browser SDK. Apps capability negotiation, guarded resources and text fallbacks live in the package. See [MCP Apps](docs/mcp-apps.md) for integration, session migration, CSP restrictions and host validation boundaries.
440
+
441
+ ### Saved credit-work results
442
+
443
+ Use `createCreditWorkResult(requestId, work)` for initial completion, duplicate
444
+ requests and read-only recovery. Pass the account-bound saved `budget`, `charged`,
445
+ `status` and `result`; extra database fields are not projected. Both MCP `content`
446
+ and `structuredContent` carry the same JSON envelope:
447
+
448
+ ```json
449
+ {
450
+ "requestId": "proposal-1",
451
+ "status": "completed",
452
+ "maxCredits": 1,
453
+ "creditsCharged": 0,
454
+ "result": { "actionId": "action-1", "status": "proposed" }
455
+ }
456
+ ```
457
+
458
+ Read the tool outcome under `result`; the outer `status` describes credit work,
459
+ not action approval or delivery. Saved JSON is decoded once; plain text remains
460
+ a string, and serialized MCP results remain nested without discarding content.
461
+ The formatter never retries work. A missing saved result carries a same-ID polling
462
+ instruction. Bind account identity and authorization before retrieving the saved
463
+ work; this helper does not authorize access or filter the tool's saved payload.
package/changelog.json CHANGED
@@ -2,6 +2,19 @@
2
2
  "contract": 1,
3
3
  "name": "@absolutejs/mcp",
4
4
  "releases": [
5
+ {
6
+ "changes": [
7
+ {
8
+ "kind": "added",
9
+ "summary": "Preserve saved credit work results in identical text and structured host responses",
10
+ "symbols": [
11
+ "createCreditWorkResult"
12
+ ]
13
+ }
14
+ ],
15
+ "date": "2026-09-13",
16
+ "version": "0.23.0"
17
+ },
5
18
  {
6
19
  "changes": [
7
20
  {
package/dist/index.js CHANGED
@@ -2853,6 +2853,35 @@ Provide a stable requestId and the maximum service credits this work may charge.
2853
2853
  }
2854
2854
  };
2855
2855
  };
2856
+ // src/creditWorkResult.ts
2857
+ var savedResult = (value) => {
2858
+ if (value === null)
2859
+ return null;
2860
+ try {
2861
+ return JSON.parse(value);
2862
+ } catch {
2863
+ return value;
2864
+ }
2865
+ };
2866
+ var createCreditWorkResult = (requestId, work) => {
2867
+ if (typeof requestId !== "string" || !requestId || requestId.length > 128 || !Number.isSafeInteger(work.budget) || work.budget < 0 || !Number.isSafeInteger(work.charged) || work.charged < 0 || work.charged > work.budget || !["running", "completed", "failed"].includes(work.status) || work.result !== null && typeof work.result !== "string")
2868
+ throw new Error("Invalid saved credit work");
2869
+ const summary = {
2870
+ requestId,
2871
+ status: work.status,
2872
+ maxCredits: work.budget,
2873
+ creditsCharged: work.charged,
2874
+ result: savedResult(work.result),
2875
+ ...work.result === null ? {
2876
+ message: "No saved result is available. Poll get_credit_work with the same requestId; do not restart it with a new ID."
2877
+ } : {}
2878
+ };
2879
+ return {
2880
+ content: [{ type: "text", text: JSON.stringify(summary) }],
2881
+ structuredContent: summary,
2882
+ isError: work.status === "failed"
2883
+ };
2884
+ };
2856
2885
  export {
2857
2886
  COMMERCE_POLICY_SOURCES,
2858
2887
  COMMERCE_POLICY_VERSION,
@@ -2868,6 +2897,7 @@ export {
2868
2897
  createBillingReportTools,
2869
2898
  createCheckoutHandoffTool,
2870
2899
  createCreditBalanceTool,
2900
+ createCreditWorkResult,
2871
2901
  createMcpAuthorizationRequest,
2872
2902
  createMcpClient,
2873
2903
  createMcpHandler,
@@ -0,0 +1,13 @@
1
+ import type { McpToolResult } from "./types";
2
+ /** Public projection of account-bound, persisted work. Never pass an unfiltered
3
+ * database row or provider response as the saved result. */
4
+ export type McpCreditWorkSnapshot = {
5
+ budget: number;
6
+ charged: number;
7
+ status: "running" | "completed" | "failed";
8
+ result: string | null;
9
+ };
10
+ /** Keep text-only and structured-only hosts on the same result contract. This
11
+ * pure formatter never starts, retries, approves, or settles work. Use it for
12
+ * initial completion, duplicate requests, and read-only recovery alike. */
13
+ export declare const createCreditWorkResult: (requestId: string, work: McpCreditWorkSnapshot) => McpToolResult;
@@ -52,4 +52,5 @@ export { createBillingApps } from "./billingApps";
52
52
  export { createWorkflowApps } from "./workflowApps";
53
53
  export { createWorkflowTools, projectSetupStatus, projectWorkPreview, type McpSetupStatus, type McpWorkPreview, type McpWorkPreviewRequest, } from "./workflowTools";
54
54
  export { createSetupSelectionTools, projectSetupSelection, type SetupSelection, type SetupConfirmation, type SetupOption, } from "./setupSelection";
55
- export { createActionWorkflowTools, projectActionReview, projectActionJob, type ActionReview, type ActionConfirmation, type ActionJob } from "./actionWorkflow";
55
+ export { createActionWorkflowTools, projectActionReview, projectActionJob, type ActionReview, type ActionConfirmation, type ActionJob, } from "./actionWorkflow";
56
+ export { createCreditWorkResult, type McpCreditWorkSnapshot, } from "./creditWorkResult";
package/package.json CHANGED
@@ -90,5 +90,5 @@
90
90
  "canary:checkout": "bun canary/checkout.ts"
91
91
  },
92
92
  "types": "./dist/src/index.d.ts",
93
- "version": "0.22.0"
93
+ "version": "0.23.0"
94
94
  }