@oobe-protocol-labs/sap-mcp-server 0.9.21 → 0.9.35

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 (190) hide show
  1. package/.env.example +11 -1
  2. package/CHANGELOG.md +233 -6
  3. package/README.md +3 -3
  4. package/USER_DOCS/00_START_HERE.md +9 -1
  5. package/USER_DOCS/01_HOSTED_REMOTE_MCP.md +1 -1
  6. package/USER_DOCS/04_CLIENT_CONFIGS.md +3 -3
  7. package/USER_DOCS/06_DESKTOP_GUI_WIZARD.md +5 -5
  8. package/config.example.json +1 -1
  9. package/config.secure-example.json +1 -1
  10. package/dist/config/env.d.ts +18 -0
  11. package/dist/config/env.d.ts.map +1 -1
  12. package/dist/config/env.js +14 -2
  13. package/dist/config/env.js.map +1 -1
  14. package/dist/config/mcp-client-injection.js +3 -3
  15. package/dist/config/paths.d.ts +9 -1
  16. package/dist/config/paths.d.ts.map +1 -1
  17. package/dist/config/paths.js +15 -1
  18. package/dist/config/paths.js.map +1 -1
  19. package/dist/config/wizard.d.ts.map +1 -1
  20. package/dist/config/wizard.js +3 -1
  21. package/dist/config/wizard.js.map +1 -1
  22. package/dist/core/constants.d.ts +1 -1
  23. package/dist/core/constants.js +1 -1
  24. package/dist/core/logger.js +1 -1
  25. package/dist/memory/async-processor.d.ts +107 -0
  26. package/dist/memory/async-processor.d.ts.map +1 -0
  27. package/dist/memory/async-processor.js +204 -0
  28. package/dist/memory/async-processor.js.map +1 -0
  29. package/dist/memory/auto-record.d.ts +47 -0
  30. package/dist/memory/auto-record.d.ts.map +1 -0
  31. package/dist/memory/auto-record.js +133 -0
  32. package/dist/memory/auto-record.js.map +1 -0
  33. package/dist/memory/database.d.ts +103 -0
  34. package/dist/memory/database.d.ts.map +1 -0
  35. package/dist/memory/database.js +337 -0
  36. package/dist/memory/database.js.map +1 -0
  37. package/dist/memory/hermes-bridge.d.ts +70 -0
  38. package/dist/memory/hermes-bridge.d.ts.map +1 -0
  39. package/dist/memory/hermes-bridge.js +155 -0
  40. package/dist/memory/hermes-bridge.js.map +1 -0
  41. package/dist/memory/index.d.ts +23 -0
  42. package/dist/memory/index.d.ts.map +1 -0
  43. package/dist/memory/index.js +22 -0
  44. package/dist/memory/index.js.map +1 -0
  45. package/dist/memory/memory-store.d.ts +76 -0
  46. package/dist/memory/memory-store.d.ts.map +1 -0
  47. package/dist/memory/memory-store.js +231 -0
  48. package/dist/memory/memory-store.js.map +1 -0
  49. package/dist/memory/stream-buffer-store.d.ts +69 -0
  50. package/dist/memory/stream-buffer-store.d.ts.map +1 -0
  51. package/dist/memory/stream-buffer-store.js +182 -0
  52. package/dist/memory/stream-buffer-store.js.map +1 -0
  53. package/dist/memory/tool-call-store.d.ts +68 -0
  54. package/dist/memory/tool-call-store.d.ts.map +1 -0
  55. package/dist/memory/tool-call-store.js +189 -0
  56. package/dist/memory/tool-call-store.js.map +1 -0
  57. package/dist/memory/types.d.ts +197 -0
  58. package/dist/memory/types.d.ts.map +1 -0
  59. package/dist/memory/types.js +15 -0
  60. package/dist/memory/types.js.map +1 -0
  61. package/dist/memory/utils.d.ts +30 -0
  62. package/dist/memory/utils.d.ts.map +1 -0
  63. package/dist/memory/utils.js +47 -0
  64. package/dist/memory/utils.js.map +1 -0
  65. package/dist/payments/hosted-tool-eligibility.d.ts.map +1 -1
  66. package/dist/payments/hosted-tool-eligibility.js +4 -6
  67. package/dist/payments/hosted-tool-eligibility.js.map +1 -1
  68. package/dist/payments/monetization-gate.d.ts +39 -0
  69. package/dist/payments/monetization-gate.d.ts.map +1 -1
  70. package/dist/payments/monetization-gate.js +165 -11
  71. package/dist/payments/monetization-gate.js.map +1 -1
  72. package/dist/payments/pricing.d.ts.map +1 -1
  73. package/dist/payments/pricing.js +69 -0
  74. package/dist/payments/pricing.js.map +1 -1
  75. package/dist/payments/x402-paid-call.js +1 -1
  76. package/dist/premium/builtin-plugins.d.ts +42 -0
  77. package/dist/premium/builtin-plugins.d.ts.map +1 -1
  78. package/dist/premium/builtin-plugins.js +91 -10
  79. package/dist/premium/builtin-plugins.js.map +1 -1
  80. package/dist/premium/manifest-builder.d.ts.map +1 -1
  81. package/dist/premium/manifest-builder.js +43 -7
  82. package/dist/premium/manifest-builder.js.map +1 -1
  83. package/dist/premium/meme-radar-capabilities.js +9 -9
  84. package/dist/premium/meme-radar-capabilities.js.map +1 -1
  85. package/dist/premium/plugin-validator.d.ts.map +1 -1
  86. package/dist/premium/plugin-validator.js +62 -1
  87. package/dist/premium/plugin-validator.js.map +1 -1
  88. package/dist/premium/provider-bridge.d.ts +25 -1
  89. package/dist/premium/provider-bridge.d.ts.map +1 -1
  90. package/dist/premium/provider-bridge.js +130 -20
  91. package/dist/premium/provider-bridge.js.map +1 -1
  92. package/dist/premium/session-manager.d.ts.map +1 -1
  93. package/dist/premium/session-manager.js +12 -3
  94. package/dist/premium/session-manager.js.map +1 -1
  95. package/dist/premium/tech-fundamentals-capabilities.js +5 -5
  96. package/dist/premium/tech-fundamentals-capabilities.js.map +1 -1
  97. package/dist/premium/trading-capabilities.js +5 -5
  98. package/dist/premium/trading-capabilities.js.map +1 -1
  99. package/dist/premium/webhook-engine.d.ts.map +1 -1
  100. package/dist/premium/webhook-engine.js +7 -1
  101. package/dist/premium/webhook-engine.js.map +1 -1
  102. package/dist/prompts/context/sap-agent-context.prompt.js +1 -1
  103. package/dist/prompts/payments/explain-x402-settlement.prompt.js +1 -1
  104. package/dist/remote/premium-routes.d.ts.map +1 -1
  105. package/dist/remote/premium-routes.js +3 -2
  106. package/dist/remote/premium-routes.js.map +1 -1
  107. package/dist/remote/public-home/sections.d.ts.map +1 -1
  108. package/dist/remote/public-home/sections.js +2 -3
  109. package/dist/remote/public-home/sections.js.map +1 -1
  110. package/dist/remote/public-home/styles.d.ts +1 -1
  111. package/dist/remote/public-home/styles.js +2 -2
  112. package/dist/remote/server.d.ts.map +1 -1
  113. package/dist/remote/server.js +19 -4
  114. package/dist/remote/server.js.map +1 -1
  115. package/dist/server/server-metadata.js +1 -1
  116. package/dist/strategies/strategy-store.d.ts +82 -0
  117. package/dist/strategies/strategy-store.d.ts.map +1 -0
  118. package/dist/strategies/strategy-store.js +165 -0
  119. package/dist/strategies/strategy-store.js.map +1 -0
  120. package/dist/tools/agent-start-tool.d.ts.map +1 -1
  121. package/dist/tools/agent-start-tool.js +97 -10
  122. package/dist/tools/agent-start-tool.js.map +1 -1
  123. package/dist/tools/client-sdk-tools.d.ts.map +1 -1
  124. package/dist/tools/client-sdk-tools.js +152 -9
  125. package/dist/tools/client-sdk-tools.js.map +1 -1
  126. package/dist/tools/estimate-tool-cost.js +1 -1
  127. package/dist/tools/estimate-tool-cost.js.map +1 -1
  128. package/dist/tools/index.d.ts +1 -0
  129. package/dist/tools/index.d.ts.map +1 -1
  130. package/dist/tools/index.js +2 -0
  131. package/dist/tools/index.js.map +1 -1
  132. package/dist/tools/magicblock-tools.js +5 -5
  133. package/dist/tools/magicblock-tools.js.map +1 -1
  134. package/dist/tools/memory-tools.d.ts +26 -0
  135. package/dist/tools/memory-tools.d.ts.map +1 -0
  136. package/dist/tools/memory-tools.js +533 -0
  137. package/dist/tools/memory-tools.js.map +1 -0
  138. package/dist/tools/perp-tools.d.ts +7 -9
  139. package/dist/tools/perp-tools.d.ts.map +1 -1
  140. package/dist/tools/perp-tools.js +386 -367
  141. package/dist/tools/perp-tools.js.map +1 -1
  142. package/dist/tools/premium-tools.d.ts.map +1 -1
  143. package/dist/tools/premium-tools.js +8 -2
  144. package/dist/tools/premium-tools.js.map +1 -1
  145. package/dist/tools/profile-tools.d.ts.map +1 -1
  146. package/dist/tools/profile-tools.js +18 -1
  147. package/dist/tools/profile-tools.js.map +1 -1
  148. package/dist/tools/quick-context-tool.d.ts.map +1 -1
  149. package/dist/tools/quick-context-tool.js +100 -9
  150. package/dist/tools/quick-context-tool.js.map +1 -1
  151. package/dist/tools/register-tools.d.ts.map +1 -1
  152. package/dist/tools/register-tools.js +3 -0
  153. package/dist/tools/register-tools.js.map +1 -1
  154. package/dist/tools/sap-sdk-tools.js +3 -3
  155. package/dist/tools/sap-sdk-tools.js.map +1 -1
  156. package/dist/tools/session-context-packet.d.ts +19 -0
  157. package/dist/tools/session-context-packet.d.ts.map +1 -0
  158. package/dist/tools/session-context-packet.js +256 -0
  159. package/dist/tools/session-context-packet.js.map +1 -0
  160. package/dist/tools/skills-tools.d.ts +10 -0
  161. package/dist/tools/skills-tools.d.ts.map +1 -1
  162. package/dist/tools/skills-tools.js +19 -0
  163. package/dist/tools/skills-tools.js.map +1 -1
  164. package/dist/tools/transaction-tools.d.ts +1 -0
  165. package/dist/tools/transaction-tools.d.ts.map +1 -1
  166. package/dist/tools/transaction-tools.js +248 -9
  167. package/dist/tools/transaction-tools.js.map +1 -1
  168. package/dist/tools/x402-paid-call-tool.d.ts.map +1 -1
  169. package/dist/tools/x402-paid-call-tool.js +55 -21
  170. package/dist/tools/x402-paid-call-tool.js.map +1 -1
  171. package/dist/wizard-core/desktop-flow.d.ts.map +1 -1
  172. package/dist/wizard-core/desktop-flow.js +4 -2
  173. package/dist/wizard-core/desktop-flow.js.map +1 -1
  174. package/docs/06_PAYMENTS_X402_AND_PAYSH.md +14 -5
  175. package/docs/07_ENDPOINTS_AND_CLIENTS.md +1 -1
  176. package/docs/09_TOOLS_SKILLS_AND_AGENT_GUIDE.md +13 -5
  177. package/docs/13_BOUNTY_PROGRAM_PROPOSAL.md +1 -1
  178. package/docs/14_DESKTOP_WIZARD_RELEASE.md +3 -3
  179. package/docs/15_DASHBOARD_SCREENSHARE_SCRIPT.md +1 -1
  180. package/docs/BRANCH_AND_CI.md +2 -2
  181. package/docs/README.md +1 -1
  182. package/package.json +3 -1
  183. package/server.json +3 -3
  184. package/skills/README.md +1 -1
  185. package/skills/sap-agentkit/SKILL.md +1 -2
  186. package/skills/sap-defi/SKILL.md +31 -2
  187. package/skills/sap-mcp/SKILL.md +24 -13
  188. package/skills/sap-mcp/TOOL_REFERENCE.md +2 -4
  189. package/skills/sap-payments-x402/SKILL.md +15 -3
  190. package/assets/logos/drift.svg +0 -12
@@ -0,0 +1,189 @@
1
+ /**
2
+ * @module memory/tool-call-store
3
+ * @description Store for recording and searching tool call history.
4
+ *
5
+ * All methods are synchronous (better-sqlite3 is synchronous). FTS5 search
6
+ * returns relevance-ranked results using the inverted index.
7
+ */
8
+ import { memoryDatabase } from './database.js';
9
+ import { truncate } from './utils.js';
10
+ /**
11
+ * @name ToolCallStore
12
+ * @description Records and queries tool call execution history.
13
+ *
14
+ * Every tool call (paid or free) is recorded with its input, output, outcome,
15
+ * cost, and latency. The FTS5 index enables full-text search across all
16
+ * recorded calls for pattern detection and failure analysis.
17
+ */
18
+ export class ToolCallStore {
19
+ /**
20
+ * @name record
21
+ * @description Records a tool call execution in the memory database.
22
+ * @param record - Tool call data to record.
23
+ * @returns The auto-incremented ID of the inserted record, or -1 if degraded.
24
+ */
25
+ record(record) {
26
+ if (memoryDatabase.isDegraded())
27
+ return -1;
28
+ memoryDatabase.init();
29
+ const stmt = memoryDatabase.getStatement('insert_tool_call');
30
+ if (!stmt)
31
+ return -1;
32
+ const maxBytes = 8192;
33
+ const result = stmt.run({
34
+ toolName: record.toolName,
35
+ sessionId: record.sessionId,
36
+ callerProfile: record.callerProfile,
37
+ input: truncate(record.input, maxBytes),
38
+ output: truncate(record.output, maxBytes),
39
+ outcome: record.outcome,
40
+ costUsd: record.costUsd ?? null,
41
+ txSignature: record.txSignature ?? null,
42
+ latencyMs: record.latencyMs ?? null,
43
+ });
44
+ return result.lastInsertRowid;
45
+ }
46
+ /**
47
+ * @name search
48
+ * @description Full-text search across tool call history using FTS5.
49
+ * @param options - Search options including query, filters, and pagination.
50
+ * @returns Search results with relevance ranking.
51
+ */
52
+ search(options) {
53
+ if (memoryDatabase.isDegraded()) {
54
+ return { results: [], total: 0, hasMore: false };
55
+ }
56
+ memoryDatabase.init();
57
+ const db = memoryDatabase.getDb();
58
+ const limit = Math.min(options.limit ?? 20, 100);
59
+ const offset = options.offset ?? 0;
60
+ // Build FTS5 query with optional filters.
61
+ let whereClause = '';
62
+ const params = { limit, offset };
63
+ if (options.toolName) {
64
+ whereClause += ' AND t.tool_name = @toolName';
65
+ params['toolName'] = options.toolName;
66
+ }
67
+ if (options.outcome) {
68
+ whereClause += ' AND t.outcome = @outcome';
69
+ params['outcome'] = options.outcome;
70
+ }
71
+ // FTS5 MATCH query — use bm25 ranking for relevance.
72
+ const ftsQuery = this.buildFtsQuery(options.query);
73
+ const sql = `
74
+ SELECT t.id, t.tool_name, t.session_id, t.caller_profile, t.input, t.output,
75
+ t.outcome, t.cost_usd, t.tx_signature, t.latency_ms,
76
+ t.created_at, t.updated_at
77
+ FROM tool_calls_fts fts
78
+ JOIN tool_calls t ON t.id = fts.rowid
79
+ WHERE tool_calls_fts MATCH @ftsQuery
80
+ ${whereClause}
81
+ ORDER BY ${options.sort === 'newest' ? 't.created_at DESC' : options.sort === 'oldest' ? 't.created_at ASC' : 'bm25(tool_calls_fts)'}
82
+ LIMIT @limit OFFSET @offset
83
+ `;
84
+ params['ftsQuery'] = ftsQuery;
85
+ try {
86
+ const results = db.prepare(sql).all(params);
87
+ const countSql = `
88
+ SELECT COUNT(*) as total
89
+ FROM tool_calls_fts fts
90
+ JOIN tool_calls t ON t.id = fts.rowid
91
+ WHERE tool_calls_fts MATCH @ftsQuery ${whereClause}
92
+ `;
93
+ const countResult = db.prepare(countSql).get(params);
94
+ const total = countResult?.total ?? 0;
95
+ return {
96
+ results,
97
+ total,
98
+ hasMore: offset + results.length < total,
99
+ };
100
+ }
101
+ catch {
102
+ return { results: [], total: 0, hasMore: false };
103
+ }
104
+ }
105
+ /**
106
+ * @name count
107
+ * @description Returns the total number of tool call records.
108
+ */
109
+ count() {
110
+ if (memoryDatabase.isDegraded())
111
+ return 0;
112
+ memoryDatabase.init();
113
+ const stmt = memoryDatabase.getStatement('count_tool_calls');
114
+ if (!stmt)
115
+ return 0;
116
+ return stmt.get().count;
117
+ }
118
+ /**
119
+ * @name outcomeBreakdown
120
+ * @description Returns counts grouped by outcome.
121
+ */
122
+ outcomeBreakdown() {
123
+ if (memoryDatabase.isDegraded()) {
124
+ return { success: 0, error: 0, partial: 0 };
125
+ }
126
+ memoryDatabase.init();
127
+ const stmt = memoryDatabase.getStatement('count_tool_calls_by_outcome');
128
+ if (!stmt)
129
+ return { success: 0, error: 0, partial: 0 };
130
+ const rows = stmt.all();
131
+ const result = { success: 0, error: 0, partial: 0 };
132
+ for (const row of rows) {
133
+ result[row.outcome] = row.count;
134
+ }
135
+ return result;
136
+ }
137
+ /**
138
+ * @name lastToolCallAt
139
+ * @description Returns the timestamp of the most recent tool call.
140
+ */
141
+ lastToolCallAt() {
142
+ if (memoryDatabase.isDegraded())
143
+ return null;
144
+ memoryDatabase.init();
145
+ const stmt = memoryDatabase.getStatement('last_tool_call_at');
146
+ if (!stmt)
147
+ return null;
148
+ const row = stmt.get();
149
+ return row?.created_at ?? null;
150
+ }
151
+ /**
152
+ * @name archive
153
+ * @description Archives tool call records older than the retention period.
154
+ * @param retentionDays - Number of days to keep records. Default 90.
155
+ * @returns Number of records archived.
156
+ */
157
+ archive(retentionDays = 90) {
158
+ if (memoryDatabase.isDegraded())
159
+ return 0;
160
+ memoryDatabase.init();
161
+ const db = memoryDatabase.getDb();
162
+ const result = db.prepare(`DELETE FROM tool_calls WHERE created_at < datetime('now', ?)`).run(`-${retentionDays} days`);
163
+ return result.changes;
164
+ }
165
+ /**
166
+ * @name buildFtsQuery
167
+ * @description Converts a natural language query into a FTS5 MATCH expression.
168
+ * Handles multi-word queries by quoting phrases and prefixing with OR for
169
+ * broader recall.
170
+ * @internal
171
+ */
172
+ buildFtsQuery(query) {
173
+ // Escape FTS5 special characters and wrap in quotes for phrase matching.
174
+ const escaped = query.replace(/["'*:]/g, ' ').trim();
175
+ if (!escaped)
176
+ return '*';
177
+ // For multi-word queries, use OR to match any word (broader recall).
178
+ const words = escaped.split(/\s+/).filter(w => w.length > 0);
179
+ if (words.length === 1)
180
+ return `"${words[0]}"*`;
181
+ return words.map(w => `"${w}"*`).join(' OR ');
182
+ }
183
+ }
184
+ /**
185
+ * @name toolCallStore
186
+ * @description Singleton instance of the tool call store.
187
+ */
188
+ export const toolCallStore = new ToolCallStore();
189
+ //# sourceMappingURL=tool-call-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-call-store.js","sourceRoot":"","sources":["../../src/memory/tool-call-store.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAGtC;;;;;;;GAOG;AACH,MAAM,OAAO,aAAa;IACxB;;;;;OAKG;IACH,MAAM,CAAC,MAA8D;QACnE,IAAI,cAAc,CAAC,UAAU,EAAE;YAAE,OAAO,CAAC,CAAC,CAAC;QAC3C,cAAc,CAAC,IAAI,EAAE,CAAC;QAEtB,MAAM,IAAI,GAAG,cAAc,CAAC,YAAY,CAAC,kBAAkB,CAAC,CAAC;QAC7D,IAAI,CAAC,IAAI;YAAE,OAAO,CAAC,CAAC,CAAC;QAErB,MAAM,QAAQ,GAAG,IAAI,CAAC;QAEtB,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC;YACtB,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,aAAa,EAAE,MAAM,CAAC,aAAa;YACnC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC;YACvC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC;YACzC,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,IAAI;YAC/B,WAAW,EAAE,MAAM,CAAC,WAAW,IAAI,IAAI;YACvC,SAAS,EAAE,MAAM,CAAC,SAAS,IAAI,IAAI;SACpC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;QACzE,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;QACrD,IAAI,CAAC,OAAO;YAAE,OAAO,GAAG,CAAC;QAEzB,qEAAqE;QACrE,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAC7D,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,IAAI,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;QAChD,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAChD,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,aAAa,EAAE,CAAC"}
@@ -0,0 +1,197 @@
1
+ /**
2
+ * @module memory/types
3
+ * @description Type definitions for the SAP MCP local agent memory subsystem.
4
+ *
5
+ * The memory subsystem uses SQLite FTS5 to store and retrieve:
6
+ * - Tool call history (input, output, outcome, cost, latency)
7
+ * - Agent memories (LLM-compressed summaries of past interactions)
8
+ * - Stream buffer events (premium stream data persisted locally)
9
+ *
10
+ * All types are designed for non-custodial, local-only operation — no data
11
+ * leaves the user's machine. The memory DB is stored at
12
+ * ~/.config/mcp-sap/memory/agent-memory.db.
13
+ */
14
+ /**
15
+ * @name ToolCallRecord
16
+ * @description A single tool call execution record stored in the memory DB.
17
+ */
18
+ export interface ToolCallRecord {
19
+ /** Auto-increment primary key. */
20
+ id?: number;
21
+ /** MCP tool name (e.g. 'jupiter_getQuote', 'sap_build_sol_transfer'). */
22
+ toolName: string;
23
+ /** Session identifier from the MCP transport. */
24
+ sessionId: string | null;
25
+ /** Signer profile used for the call, if any. */
26
+ callerProfile: string | null;
27
+ /** JSON-serialized tool input. Truncated to 8KB. */
28
+ input: string;
29
+ /** JSON-serialized tool output. Truncated to 8KB. */
30
+ output: string;
31
+ /** Execution outcome classification. */
32
+ outcome: ToolCallOutcome;
33
+ /** x402 cost in USD, if the tool was paid. */
34
+ costUsd: number | null;
35
+ /** Solana transaction signature, if the tool produced one. */
36
+ txSignature: string | null;
37
+ /** Execution latency in milliseconds. */
38
+ latencyMs: number | null;
39
+ /** ISO 8601 timestamp of when the record was created. */
40
+ createdAt: string;
41
+ /** ISO 8601 timestamp of when the record was last updated. */
42
+ updatedAt: string;
43
+ }
44
+ /**
45
+ * @name ToolCallOutcome
46
+ * @description Classification of a tool call's execution result.
47
+ */
48
+ export type ToolCallOutcome = 'success' | 'error' | 'partial';
49
+ /**
50
+ * @name AgentMemoryRecord
51
+ * @description An LLM-generated summary of past agent interactions.
52
+ *
53
+ * Memories are compressed representations of tool call patterns, failures,
54
+ * successes, and lessons learned. They decay over time via a relevance
55
+ * score that decreases as memories age, ensuring the agent prioritizes
56
+ * recent, high-signal knowledge.
57
+ */
58
+ export interface AgentMemoryRecord {
59
+ /** Auto-increment primary key. */
60
+ id?: number;
61
+ /** Type of memory — determines how it's used in prompt injection. */
62
+ memoryType: MemoryType;
63
+ /** Tool category this memory relates to (e.g. 'jupiter', 'adrena', 'premium'). */
64
+ category: string;
65
+ /** LLM-compressed summary text. Max 4KB. */
66
+ summary: string;
67
+ /** JSON array of tool_call IDs that were the source of this memory. */
68
+ sourceToolCalls: string | null;
69
+ /** Relevance score 0-1. Decays over time. Higher = more relevant. */
70
+ relevanceScore: number;
71
+ /** ISO 8601 timestamp of when the memory was created. */
72
+ createdAt: string;
73
+ /** ISO 8601 timestamp of when the memory expires. NULL = never expires. */
74
+ expiresAt: string | null;
75
+ /** ISO 8601 timestamp of when the memory was last accessed. */
76
+ lastAccessedAt: string;
77
+ }
78
+ /**
79
+ * @name MemoryType
80
+ * @description Classification of agent memory entries.
81
+ * - 'lesson': A learned pattern or rule (e.g. "Jupiter swaps fail when slippage < 50bps on low-liquidity pairs")
82
+ * - 'pattern': A recurring behavior (e.g. "Agent consistently buys when SOL price drops > 2%")
83
+ * - 'failure': A specific failure with root cause (e.g. "BlockhashNotFound after 90s — retry with fresh blockhash")
84
+ * - 'success': A successful outcome worth remembering (e.g. "Arb opportunity on SOL/USDC at block 123456")
85
+ */
86
+ export type MemoryType = 'lesson' | 'pattern' | 'failure' | 'success';
87
+ /**
88
+ * @name StreamBufferRecord
89
+ * @description A buffered stream event persisted locally for offline analysis.
90
+ */
91
+ export interface StreamBufferRecord {
92
+ /** Auto-increment primary key. */
93
+ id?: number;
94
+ /** Stream type identifier (e.g. 'pyth-price', 'meme-alerts', 'volatility'). */
95
+ streamType: string;
96
+ /** Unique event ID from the provider. */
97
+ eventId: string;
98
+ /** Event type from the provider (e.g. 'price.tick', 'volatility.breakout'). */
99
+ eventType: string;
100
+ /** JSON-serialized event payload. */
101
+ payload: string;
102
+ /** Whether the event has been consumed by the agent. */
103
+ consumed: number;
104
+ /** ISO 8601 timestamp of when the event was buffered. */
105
+ createdAt: string;
106
+ }
107
+ /**
108
+ * @name MemorySearchResult
109
+ * @description A result from a full-text search across tool calls or agent memories.
110
+ */
111
+ export interface MemorySearchResult<T = unknown> {
112
+ /** The matching records. */
113
+ results: T[];
114
+ /** Total number of matching records (before pagination). */
115
+ total: number;
116
+ /** Whether there are more results available. */
117
+ hasMore: boolean;
118
+ }
119
+ /**
120
+ * @name MemoryQueryOptions
121
+ * @description Options for searching the memory database.
122
+ */
123
+ export interface MemoryQueryOptions {
124
+ /** FTS5 search query (e.g. 'swap failure', 'jupiter slippage'). */
125
+ query: string;
126
+ /** Filter by tool name (tool_calls only). */
127
+ toolName?: string;
128
+ /** Filter by outcome (tool_calls only). */
129
+ outcome?: ToolCallOutcome;
130
+ /** Filter by memory type (agent_memory only). */
131
+ memoryType?: MemoryType;
132
+ /** Filter by category. */
133
+ category?: string;
134
+ /** Minimum relevance score (agent_memory only). */
135
+ minRelevance?: number;
136
+ /** Maximum number of results to return. Default 20. */
137
+ limit?: number;
138
+ /** Offset for pagination. Default 0. */
139
+ offset?: number;
140
+ /** Sort order. Default 'relevance' for FTS, 'newest' for time-based. */
141
+ sort?: 'relevance' | 'newest' | 'oldest';
142
+ }
143
+ /**
144
+ * @name MemoryStats
145
+ * @description Aggregate statistics about the memory database.
146
+ */
147
+ export interface MemoryStats {
148
+ /** Total number of tool call records. */
149
+ toolCallCount: number;
150
+ /** Total number of agent memory records. */
151
+ memoryCount: number;
152
+ /** Total number of stream buffer records (unconsumed). */
153
+ pendingStreamEvents: number;
154
+ /** Total database size in bytes. */
155
+ dbSizeBytes: number;
156
+ /** Breakdown of tool calls by outcome. */
157
+ outcomeBreakdown: Record<ToolCallOutcome, number>;
158
+ /** Breakdown of agent memories by type. */
159
+ memoryTypeBreakdown: Record<MemoryType, number>;
160
+ /** Most recent tool call timestamp. */
161
+ lastToolCallAt: string | null;
162
+ /** Most recent memory timestamp. */
163
+ lastMemoryAt: string | null;
164
+ }
165
+ /**
166
+ * @name MemoryPruneResult
167
+ * @description Result of pruning old, low-relevance memories.
168
+ */
169
+ export interface MemoryPruneResult {
170
+ /** Number of memories pruned. */
171
+ pruned: number;
172
+ /** Number of tool calls archived (old records). */
173
+ archived: number;
174
+ /** Database size reduction in bytes. */
175
+ freedBytes: number;
176
+ }
177
+ /**
178
+ * @name MemoryConfig
179
+ * @description Configuration for the memory subsystem.
180
+ */
181
+ export interface MemoryConfig {
182
+ /** Path to the SQLite database file. */
183
+ dbPath: string;
184
+ /** Whether to enable WAL mode (recommended for concurrent access). */
185
+ enableWal: boolean;
186
+ /** Maximum size of tool call input/output stored. Default 8192 bytes. */
187
+ maxPayloadBytes: number;
188
+ /** Relevance decay rate per day. Default 0.01 (1% per day). */
189
+ relevanceDecayPerDay: number;
190
+ /** Minimum relevance score to keep a memory. Default 0.05. */
191
+ minRelevanceThreshold: number;
192
+ /** Number of days to keep tool call records. Default 90. */
193
+ toolCallRetentionDays: number;
194
+ /** Maximum number of stream buffer events per type. Default 10000. */
195
+ maxStreamBufferSize: number;
196
+ }
197
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/memory/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,kCAAkC;IAClC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,yEAAyE;IACzE,QAAQ,EAAE,MAAM,CAAC;IACjB,iDAAiD;IACjD,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,gDAAgD;IAChD,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,oDAAoD;IACpD,KAAK,EAAE,MAAM,CAAC;IACd,qDAAqD;IACrD,MAAM,EAAE,MAAM,CAAC;IACf,wCAAwC;IACxC,OAAO,EAAE,eAAe,CAAC;IACzB,8CAA8C;IAC9C,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,8DAA8D;IAC9D,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,yCAAyC;IACzC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,yDAAyD;IACzD,SAAS,EAAE,MAAM,CAAC;IAClB,8DAA8D;IAC9D,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,CAAC;AAE9D;;;;;;;;GAQG;AACH,MAAM,WAAW,iBAAiB;IAChC,kCAAkC;IAClC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,qEAAqE;IACrE,UAAU,EAAE,UAAU,CAAC;IACvB,kFAAkF;IAClF,QAAQ,EAAE,MAAM,CAAC;IACjB,4CAA4C;IAC5C,OAAO,EAAE,MAAM,CAAC;IAChB,uEAAuE;IACvE,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IA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@@
1
+ /**
2
+ * @module memory/types
3
+ * @description Type definitions for the SAP MCP local agent memory subsystem.
4
+ *
5
+ * The memory subsystem uses SQLite FTS5 to store and retrieve:
6
+ * - Tool call history (input, output, outcome, cost, latency)
7
+ * - Agent memories (LLM-compressed summaries of past interactions)
8
+ * - Stream buffer events (premium stream data persisted locally)
9
+ *
10
+ * All types are designed for non-custodial, local-only operation — no data
11
+ * leaves the user's machine. The memory DB is stored at
12
+ * ~/.config/mcp-sap/memory/agent-memory.db.
13
+ */
14
+ export {};
15
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/memory/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @module memory/utils
3
+ * @description Utility functions for the memory subsystem.
4
+ */
5
+ /**
6
+ * @name truncate
7
+ * @description Truncates a string to the specified byte length, ensuring it
8
+ * doesn't end in the middle of a multi-byte UTF-8 sequence.
9
+ * @param str - The string to truncate.
10
+ * @param maxBytes - Maximum byte length.
11
+ * @returns The truncated string.
12
+ */
13
+ export declare function truncate(str: string, maxBytes: number): string;
14
+ /**
15
+ * @name decayRelevance
16
+ * @description Computes the decayed relevance score based on days since creation.
17
+ * @param initialScore - Initial relevance score (0-1).
18
+ * @param createdAt - ISO 8601 timestamp of creation.
19
+ * @param decayPerDay - Decay rate per day (e.g. 0.01 = 1% per day).
20
+ * @returns Decayed relevance score, clamped to [0, 1].
21
+ */
22
+ export declare function decayRelevance(initialScore: number, createdAt: string, decayPerDay: number): number;
23
+ /**
24
+ * @name isExpired
25
+ * @description Checks if a memory record has expired.
26
+ * @param expiresAt - ISO 8601 timestamp or null (null = never expires).
27
+ * @returns True if the memory has expired.
28
+ */
29
+ export declare function isExpired(expiresAt: string | null): boolean;
30
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/memory/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAK9D;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAC5B,YAAY,EAAE,MAAM,EACpB,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,GAClB,MAAM,CAMR;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAG3D"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * @module memory/utils
3
+ * @description Utility functions for the memory subsystem.
4
+ */
5
+ /**
6
+ * @name truncate
7
+ * @description Truncates a string to the specified byte length, ensuring it
8
+ * doesn't end in the middle of a multi-byte UTF-8 sequence.
9
+ * @param str - The string to truncate.
10
+ * @param maxBytes - Maximum byte length.
11
+ * @returns The truncated string.
12
+ */
13
+ export function truncate(str, maxBytes) {
14
+ if (!str)
15
+ return '';
16
+ const buf = Buffer.from(str, 'utf-8');
17
+ if (buf.length <= maxBytes)
18
+ return str;
19
+ return buf.subarray(0, maxBytes).toString('utf-8');
20
+ }
21
+ /**
22
+ * @name decayRelevance
23
+ * @description Computes the decayed relevance score based on days since creation.
24
+ * @param initialScore - Initial relevance score (0-1).
25
+ * @param createdAt - ISO 8601 timestamp of creation.
26
+ * @param decayPerDay - Decay rate per day (e.g. 0.01 = 1% per day).
27
+ * @returns Decayed relevance score, clamped to [0, 1].
28
+ */
29
+ export function decayRelevance(initialScore, createdAt, decayPerDay) {
30
+ const created = new Date(createdAt).getTime();
31
+ const now = Date.now();
32
+ const daysSince = (now - created) / (1000 * 60 * 60 * 24);
33
+ const decayed = initialScore * Math.pow(1 - decayPerDay, daysSince);
34
+ return Math.max(0, Math.min(1, decayed));
35
+ }
36
+ /**
37
+ * @name isExpired
38
+ * @description Checks if a memory record has expired.
39
+ * @param expiresAt - ISO 8601 timestamp or null (null = never expires).
40
+ * @returns True if the memory has expired.
41
+ */
42
+ export function isExpired(expiresAt) {
43
+ if (!expiresAt)
44
+ return false;
45
+ return new Date(expiresAt).getTime() <= Date.now();
46
+ }
47
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/memory/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;GAOG;AACH,MAAM,UAAU,QAAQ,CAAC,GAAW,EAAE,QAAgB;IACpD,IAAI,CAAC,GAAG;QAAE,OAAO,EAAE,CAAC;IACpB,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IACtC,IAAI,GAAG,CAAC,MAAM,IAAI,QAAQ;QAAE,OAAO,GAAG,CAAC;IACvC,OAAO,GAAG,CAAC,QAAQ,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;AACrD,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,cAAc,CAC5B,YAAoB,EACpB,SAAiB,EACjB,WAAmB;IAEnB,MAAM,OAAO,GAAG,IAAI,IAAI,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,CAAC;IAC9C,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACvB,MAAM,SAAS,GAAG,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC;IAC1D,MAAM,OAAO,GAAG,YAAY,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,WAAW,EAAE,SAAS,CAAC,CAAC;IACpE,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;AAC3C,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAC,SAAwB;IAChD,IAAI,CAAC,SAAS;QAAE,OAAO,KAAK,CAAC;IAC7B,OAAO,IAAI,IAAI,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC;AACrD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"hosted-tool-eligibility.d.ts","sourceRoot":"","sources":["../../src/payments/hosted-tool-eligibility.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEtD,MAAM,WAAW,4BAA4B;IAC3C,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE;QACJ,MAAM,EAAE,MAAM,CAAC;QACf,iBAAiB,EAAE,IAAI,CAAC;QACxB,YAAY,EAAE,MAAM,EAAE,CAAC;QACvB,UAAU,EAAE,2BAA2B,CAAC;QACxC,eAAe,EAAE,MAAM,CAAC;QACxB,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,gBAAgB,EAAE,MAAM,EAAE,CAAC;KAC5B,CAAC;CACH;AAoID,wBAAgB,6BAA6B,CAC3C,aAAa,EAAE,gBAAgB,EAC/B,MAAM,EAAE,IAAI,CAAC,YAAY,EAAE,MAAM,GAAG,YAAY,GAAG,mBAAmB,CAAC,GACtE,4BAA4B,GAAG,SAAS,CAiC1C;AAED,wBAAgB,8BAA8B,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAWxE"}
1
+ {"version":3,"file":"hosted-tool-eligibility.d.ts","sourceRoot":"","sources":["../../src/payments/hosted-tool-eligibility.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEtD,MAAM,WAAW,4BAA4B;IAC3C,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE;QACJ,MAAM,EAAE,MAAM,CAAC;QACf,iBAAiB,EAAE,IAAI,CAAC;QACxB,YAAY,EAAE,MAAM,EAAE,CAAC;QACvB,UAAU,EAAE,2BAA2B,CAAC;QACxC,eAAe,EAAE,MAAM,CAAC;QACxB,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,gBAAgB,EAAE,MAAM,EAAE,CAAC;KAC5B,CAAC;CACH;AAgID,wBAAgB,6BAA6B,CAC3C,aAAa,EAAE,gBAAgB,EAC/B,MAAM,EAAE,IAAI,CAAC,YAAY,EAAE,MAAM,GAAG,YAAY,GAAG,mBAAmB,CAAC,GACtE,4BAA4B,GAAG,SAAS,CAmC1C;AAED,wBAAgB,8BAA8B,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAWxE"}
@@ -17,12 +17,6 @@ const LOCAL_SIGNER_ONLY_EXACT_TOOLS = new Set([
17
17
  'blinks_executeAction',
18
18
  'bridging_bridgeDeBridge',
19
19
  'bridging_bridgeWormhole',
20
- 'drift_borrow',
21
- 'drift_closePerpPosition',
22
- 'drift_deposit',
23
- 'drift_lend',
24
- 'drift_openPerpPosition',
25
- 'drift_withdraw',
26
20
  'gibwork_createBounty',
27
21
  'gibwork_submitWork',
28
22
  'jito_sendBundle',
@@ -115,6 +109,8 @@ const HOSTED_SAFE_PREFIXES = [
115
109
  ];
116
110
  const HOSTED_SAFE_EXACT_TOOLS = new Set([
117
111
  'sap_submit_signed_transaction',
112
+ 'sap_build_sol_transfer',
113
+ 'sap_build_spl_transfer',
118
114
  'sap_sns_check_domain',
119
115
  'sap_sns_batch_check_domains',
120
116
  'sap_sns_validate_records',
@@ -151,6 +147,8 @@ export function evaluateHostedToolEligibility(parsedRequest, config) {
151
147
  'sap_payments_readiness',
152
148
  'sap_payments_call_paid_tool',
153
149
  'sap_payments_finalize_transaction',
150
+ 'sap_build_sol_transfer',
151
+ 'sap_build_spl_transfer',
154
152
  'sap_escrow_build_create_transaction',
155
153
  'sap_escrow_build_settle_transaction',
156
154
  'sap_sns_build_manage_record_transaction',
@@ -1 +1 @@
1
- {"version":3,"file":"hosted-tool-eligibility.js","sourceRoot":"","sources":["../../src/payments/hosted-tool-eligibility.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAmBH,MAAM,6BAA6B,GAAG,IAAI,GAAG,CAAC;IAC5C,cAAc;IACd,qBAAqB;IACrB,wBAAwB;IACxB,mBAAmB;IACnB,mBAAmB;IACnB,sBAAsB;IACtB,sBAAsB;IACtB,qBAAqB;IACrB,yBAAyB;IACzB,2BAA2B;IAC3B,sBAAsB;IACtB,sBAAsB;IACtB,yBAAyB;IACzB,yBAAyB;IACzB,cAAc;IACd,yBAAyB;IACzB,eAAe;IACf,YAAY;IACZ,wBAAwB;IACxB,gBAAgB;IAChB,sBAAsB;IACtB,oBAAoB;IACpB,iBAAiB;IACjB,mBAAmB;IACnB,0BAA0B;IAC1B,2BAA2B;IAC3B,mBAAmB;IACnB,0BAA0B;IAC1B,oBAAoB;IACpB,sBAAsB;IACtB,wBAAwB;IACxB,mBAAmB;IACnB,cAAc;IACd,cAAc;IACd,eAAe;IACf,sBAAsB;IACtB,0BAA0B;IAC1B,oBAAoB;IACpB,kBAAkB;IAClB,mBAAmB;IACnB,WAAW;IACX,kBAAkB;IAClB,YAAY;IACZ,sBAAsB;IACtB,sBAAsB;IACtB,oBAAoB;IACpB,kBAAkB;IAClB,sBAAsB;IACtB,sBAAsB;IACtB,iBAAiB;IACjB,kBAAkB;IAClB,+BAA+B;IAC/B,+BAA+B;IAC/B,gBAAgB;IAChB,wBAAwB;IACxB,uBAAuB;IACvB,yBAAyB;IACzB,kBAAkB;IAClB,uBAAuB;IACvB,oBAAoB;IACpB,uBAAuB;CACxB,CAAC,CAAC;AAEH,MAAM,0CAA0C,GAAG,IAAI,GAAG,CA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rC,qCAAqC;gBACrC,yCAAyC;aAC1C;SACF;KACF,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,8BAA8B,CAAC,QAAgB;IAC7D,IAAI,0CAA0C,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC7D,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,uBAAuB,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,oBAAoB,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,QAAQ,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC;QAC9G,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,6BAA6B,CAAC,GAAG,CAAC,QAAQ,CAAC;WAC7C,0BAA0B,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,QAAQ,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;AAC9E,CAAC"}
@@ -46,6 +46,23 @@ export declare class McpMonetizationGate {
46
46
  private readonly monetization;
47
47
  private readonly httpResourceServer;
48
48
  private readonly usageLedger;
49
+ /**
50
+ * @description x402 idempotency cache — prevents double-charge on retry.
51
+ *
52
+ * Keyed by `requestHash`. When a settlement succeeds, the receipt is cached
53
+ * for 5 minutes. If the same requestHash is retried (e.g. network failure
54
+ * after the tool executed but before the response reached the client), the
55
+ * cached settlement is returned without re-charging the payer's USDC.
56
+ *
57
+ * The cache is bounded to 10,000 entries (evicts oldest on overflow). Each
58
+ * entry has a TTL of 5 minutes — long enough for client retry logic, short
59
+ * enough to avoid stale receipts blocking legitimate re-requests.
60
+ *
61
+ * @internal
62
+ */
63
+ private readonly idempotencyCache;
64
+ private static readonly IDEMPOTENCY_TTL_MS;
65
+ private static readonly IDEMPOTENCY_MAX_ENTRIES;
49
66
  private constructor();
50
67
  /**
51
68
  * @name create
@@ -57,6 +74,28 @@ export declare class McpMonetizationGate {
57
74
  * @description Flushes hosted payment audit state before the remote server exits.
58
75
  */
59
76
  close(): Promise<void>;
77
+ /**
78
+ * @name isJsonRpcError
79
+ * @description Checks if a buffered HTTP response body contains a JSON-RPC error.
80
+ *
81
+ * JSON-RPC errors have the shape `{ "error": { "code": <number>, "message": <string> } }`
82
+ * or MCP tool results with `isError: true`. When detected, settlement is skipped
83
+ * so the user is not charged for failed tool calls.
84
+ *
85
+ * @internal
86
+ */
87
+ private isJsonRpcError;
88
+ /**
89
+ * @name pruneExpiredIdempotencyEntries
90
+ * @description Opportunistically remove expired entries from the idempotency cache.
91
+ *
92
+ * Called after each successful settlement to keep the cache bounded without
93
+ * a separate timer. Scans at most 100 entries per call to avoid O(n) overhead
94
+ * on every settle.
95
+ *
96
+ * @internal
97
+ */
98
+ private pruneExpiredIdempotencyEntries;
60
99
  /**
61
100
  * @name handle
62
101
  * @description Authorizes a request via x402 when required, then forwards it to MCP and settles on success.
@@ -1 +1 @@
1
- {"version":3,"file":"monetization-gate.d.ts","sourceRoot":"","sources":["../../src/payments/monetization-gate.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAiB7B,OAAO,KAAK,EAAE,YAAY,EAA4B,MAAM,kBAAkB,CAAC;AAK/E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAKpD;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAC9B,OAAO,EAAE,IAAI,CAAC,eAAe,EAC7B,QAAQ,EAAE,IAAI,CAAC,cAAc,EAC7B,UAAU,CAAC,EAAE,OAAO,KACjB,OAAO,CAAC,IAAI,CAAC,CAAC;AAEnB;;;GAGG;AACH,MAAM,WAAW,+BAA+B;IAC9C,OAAO,EAAE,IAAI,CAAC,eAAe,CAAC;IAC9B,UAAU,EAAE,OAAO,CAAC;IACpB,QAAQ,EAAE,OAAO,CAAC,eAAe,EAAE;QAAE,QAAQ,EAAE,IAAI,CAAA;KAAE,CAAC,CAAC;CACxD;AAED;;;GAGG;AACH,MAAM,WAAW,+BAA+B;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