@oobe-protocol-labs/sap-mcp-server 0.9.1 → 0.9.3

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 (703) hide show
  1. package/.env.example +8 -7
  2. package/CHANGELOG.md +732 -1
  3. package/README.md +9 -3
  4. package/USER_DOCS/00_START_HERE.md +51 -4
  5. package/USER_DOCS/01_HOSTED_REMOTE_MCP.md +1 -1
  6. package/USER_DOCS/03_PAYMENTS_X402_PAYSH.md +32 -3
  7. package/USER_DOCS/04_CLIENT_CONFIGS.md +14 -7
  8. package/USER_DOCS/05_SKILLS_AND_TOOLS.md +68 -8
  9. package/USER_DOCS/06_DESKTOP_GUI_WIZARD.md +20 -14
  10. package/USER_DOCS/07_SMITHERY_AND_MARKETPLACES.md +7 -0
  11. package/config.example.json +5 -4
  12. package/config.schema.json +9 -4
  13. package/config.secure-example.json +5 -4
  14. package/dist/adapters/index.d.ts +7 -1
  15. package/dist/adapters/index.d.ts.map +1 -1
  16. package/dist/adapters/index.js +7 -1
  17. package/dist/adapters/index.js.map +1 -1
  18. package/dist/adapters/mcp/errors.d.ts +13 -1
  19. package/dist/adapters/mcp/errors.d.ts.map +1 -1
  20. package/dist/adapters/mcp/errors.js +13 -1
  21. package/dist/adapters/mcp/errors.js.map +1 -1
  22. package/dist/adapters/mcp/index.d.ts +7 -1
  23. package/dist/adapters/mcp/index.d.ts.map +1 -1
  24. package/dist/adapters/mcp/index.js +7 -1
  25. package/dist/adapters/mcp/index.js.map +1 -1
  26. package/dist/adapters/mcp/prompt-response.d.ts +13 -1
  27. package/dist/adapters/mcp/prompt-response.d.ts.map +1 -1
  28. package/dist/adapters/mcp/prompt-response.js +13 -1
  29. package/dist/adapters/mcp/prompt-response.js.map +1 -1
  30. package/dist/adapters/mcp/resource-response.d.ts +14 -1
  31. package/dist/adapters/mcp/resource-response.d.ts.map +1 -1
  32. package/dist/adapters/mcp/resource-response.js +14 -1
  33. package/dist/adapters/mcp/resource-response.js.map +1 -1
  34. package/dist/adapters/mcp/sdk-compat.d.ts +11 -3
  35. package/dist/adapters/mcp/sdk-compat.d.ts.map +1 -1
  36. package/dist/adapters/mcp/sdk-compat.js +232 -25
  37. package/dist/adapters/mcp/sdk-compat.js.map +1 -1
  38. package/dist/adapters/mcp/tool-response.d.ts +51 -3
  39. package/dist/adapters/mcp/tool-response.d.ts.map +1 -1
  40. package/dist/adapters/mcp/tool-response.js +48 -3
  41. package/dist/adapters/mcp/tool-response.js.map +1 -1
  42. package/dist/adapters/solana/commitment.d.ts +14 -2
  43. package/dist/adapters/solana/commitment.d.ts.map +1 -1
  44. package/dist/adapters/solana/commitment.js +14 -2
  45. package/dist/adapters/solana/commitment.js.map +1 -1
  46. package/dist/adapters/solana/connection.d.ts +11 -2
  47. package/dist/adapters/solana/connection.d.ts.map +1 -1
  48. package/dist/adapters/solana/connection.js +11 -2
  49. package/dist/adapters/solana/connection.js.map +1 -1
  50. package/dist/adapters/solana/index.d.ts +7 -1
  51. package/dist/adapters/solana/index.d.ts.map +1 -1
  52. package/dist/adapters/solana/index.js +7 -1
  53. package/dist/adapters/solana/index.js.map +1 -1
  54. package/dist/adapters/solana/public-key.d.ts +11 -2
  55. package/dist/adapters/solana/public-key.d.ts.map +1 -1
  56. package/dist/adapters/solana/public-key.js +11 -2
  57. package/dist/adapters/solana/public-key.js.map +1 -1
  58. package/dist/config/defaults.d.ts +5 -0
  59. package/dist/config/defaults.d.ts.map +1 -1
  60. package/dist/config/defaults.js +5 -0
  61. package/dist/config/defaults.js.map +1 -1
  62. package/dist/config/env.d.ts +4 -0
  63. package/dist/config/env.d.ts.map +1 -1
  64. package/dist/config/env.js +15 -10
  65. package/dist/config/env.js.map +1 -1
  66. package/dist/config/index.d.ts +5 -0
  67. package/dist/config/index.d.ts.map +1 -1
  68. package/dist/config/index.js +5 -0
  69. package/dist/config/index.js.map +1 -1
  70. package/dist/config/mcp-client-injection.d.ts.map +1 -1
  71. package/dist/config/mcp-client-injection.js +136 -33
  72. package/dist/config/mcp-client-injection.js.map +1 -1
  73. package/dist/config/paths.d.ts +14 -1
  74. package/dist/config/paths.d.ts.map +1 -1
  75. package/dist/config/paths.js +20 -1
  76. package/dist/config/paths.js.map +1 -1
  77. package/dist/config/profiles.d.ts +3 -10
  78. package/dist/config/profiles.d.ts.map +1 -1
  79. package/dist/config/profiles.js +5 -0
  80. package/dist/config/profiles.js.map +1 -1
  81. package/dist/config/schema.d.ts +5 -0
  82. package/dist/config/schema.d.ts.map +1 -1
  83. package/dist/config/schema.js +5 -0
  84. package/dist/config/schema.js.map +1 -1
  85. package/dist/config/secure-config.d.ts +5 -0
  86. package/dist/config/secure-config.d.ts.map +1 -1
  87. package/dist/config/secure-config.js +5 -0
  88. package/dist/config/secure-config.js.map +1 -1
  89. package/dist/config/setup.d.ts +5 -0
  90. package/dist/config/setup.d.ts.map +1 -1
  91. package/dist/config/setup.js +5 -0
  92. package/dist/config/setup.js.map +1 -1
  93. package/dist/config/wizard.d.ts +6 -0
  94. package/dist/config/wizard.d.ts.map +1 -1
  95. package/dist/config/wizard.js +102 -18
  96. package/dist/config/wizard.js.map +1 -1
  97. package/dist/config-cli.d.ts +3 -13
  98. package/dist/config-cli.d.ts.map +1 -1
  99. package/dist/config-cli.js +14 -1
  100. package/dist/config-cli.js.map +1 -1
  101. package/dist/core/constants.d.ts +38 -6
  102. package/dist/core/constants.d.ts.map +1 -1
  103. package/dist/core/constants.js +49 -6
  104. package/dist/core/constants.js.map +1 -1
  105. package/dist/core/errors.d.ts +5 -0
  106. package/dist/core/errors.d.ts.map +1 -1
  107. package/dist/core/errors.js +5 -0
  108. package/dist/core/errors.js.map +1 -1
  109. package/dist/core/guards.d.ts +5 -0
  110. package/dist/core/guards.d.ts.map +1 -1
  111. package/dist/core/guards.js +3 -1
  112. package/dist/core/guards.js.map +1 -1
  113. package/dist/core/index.d.ts +7 -1
  114. package/dist/core/index.d.ts.map +1 -1
  115. package/dist/core/index.js +7 -1
  116. package/dist/core/index.js.map +1 -1
  117. package/dist/core/logger.js +1 -1
  118. package/dist/core/result.d.ts +77 -9
  119. package/dist/core/result.d.ts.map +1 -1
  120. package/dist/core/result.js +68 -9
  121. package/dist/core/result.js.map +1 -1
  122. package/dist/core/types.d.ts +5 -0
  123. package/dist/core/types.d.ts.map +1 -1
  124. package/dist/core/types.js +3 -4
  125. package/dist/core/types.js.map +1 -1
  126. package/dist/index.d.ts +5 -0
  127. package/dist/index.d.ts.map +1 -1
  128. package/dist/index.js +5 -0
  129. package/dist/index.js.map +1 -1
  130. package/dist/memory/async-processor.d.ts +107 -0
  131. package/dist/memory/async-processor.d.ts.map +1 -0
  132. package/dist/memory/async-processor.js +204 -0
  133. package/dist/memory/async-processor.js.map +1 -0
  134. package/dist/memory/auto-record.d.ts +47 -0
  135. package/dist/memory/auto-record.d.ts.map +1 -0
  136. package/dist/memory/auto-record.js +133 -0
  137. package/dist/memory/auto-record.js.map +1 -0
  138. package/dist/memory/database.d.ts +103 -0
  139. package/dist/memory/database.d.ts.map +1 -0
  140. package/dist/memory/database.js +337 -0
  141. package/dist/memory/database.js.map +1 -0
  142. package/dist/memory/hermes-bridge.d.ts +70 -0
  143. package/dist/memory/hermes-bridge.d.ts.map +1 -0
  144. package/dist/memory/hermes-bridge.js +155 -0
  145. package/dist/memory/hermes-bridge.js.map +1 -0
  146. package/dist/memory/index.d.ts +23 -0
  147. package/dist/memory/index.d.ts.map +1 -0
  148. package/dist/memory/index.js +22 -0
  149. package/dist/memory/index.js.map +1 -0
  150. package/dist/memory/memory-store.d.ts +76 -0
  151. package/dist/memory/memory-store.d.ts.map +1 -0
  152. package/dist/memory/memory-store.js +231 -0
  153. package/dist/memory/memory-store.js.map +1 -0
  154. package/dist/memory/stream-buffer-store.d.ts +69 -0
  155. package/dist/memory/stream-buffer-store.d.ts.map +1 -0
  156. package/dist/memory/stream-buffer-store.js +182 -0
  157. package/dist/memory/stream-buffer-store.js.map +1 -0
  158. package/dist/memory/tool-call-store.d.ts +68 -0
  159. package/dist/memory/tool-call-store.d.ts.map +1 -0
  160. package/dist/memory/tool-call-store.js +189 -0
  161. package/dist/memory/tool-call-store.js.map +1 -0
  162. package/dist/memory/types.d.ts +197 -0
  163. package/dist/memory/types.d.ts.map +1 -0
  164. package/dist/memory/types.js +15 -0
  165. package/dist/memory/types.js.map +1 -0
  166. package/dist/memory/utils.d.ts +30 -0
  167. package/dist/memory/utils.d.ts.map +1 -0
  168. package/dist/memory/utils.js +47 -0
  169. package/dist/memory/utils.js.map +1 -0
  170. package/dist/payments/facilitator-rpc-fallback.d.ts.map +1 -1
  171. package/dist/payments/facilitator-rpc-fallback.js +95 -0
  172. package/dist/payments/facilitator-rpc-fallback.js.map +1 -1
  173. package/dist/payments/hosted-tool-eligibility.d.ts +22 -0
  174. package/dist/payments/hosted-tool-eligibility.d.ts.map +1 -0
  175. package/dist/payments/hosted-tool-eligibility.js +173 -0
  176. package/dist/payments/hosted-tool-eligibility.js.map +1 -0
  177. package/dist/payments/index.d.ts +2 -2
  178. package/dist/payments/index.d.ts.map +1 -1
  179. package/dist/payments/index.js +1 -1
  180. package/dist/payments/index.js.map +1 -1
  181. package/dist/payments/mcp-session-cache.d.ts +35 -0
  182. package/dist/payments/mcp-session-cache.d.ts.map +1 -0
  183. package/dist/payments/mcp-session-cache.js +83 -0
  184. package/dist/payments/mcp-session-cache.js.map +1 -0
  185. package/dist/payments/monetization-gate.d.ts +33 -0
  186. package/dist/payments/monetization-gate.d.ts.map +1 -1
  187. package/dist/payments/monetization-gate.js +124 -12
  188. package/dist/payments/monetization-gate.js.map +1 -1
  189. package/dist/payments/pricing.d.ts +31 -0
  190. package/dist/payments/pricing.d.ts.map +1 -1
  191. package/dist/payments/pricing.js +317 -19
  192. package/dist/payments/pricing.js.map +1 -1
  193. package/dist/payments/usage-ledger.d.ts +36 -2
  194. package/dist/payments/usage-ledger.d.ts.map +1 -1
  195. package/dist/payments/usage-ledger.js +121 -4
  196. package/dist/payments/usage-ledger.js.map +1 -1
  197. package/dist/payments/x402-paid-call.d.ts +121 -0
  198. package/dist/payments/x402-paid-call.d.ts.map +1 -1
  199. package/dist/payments/x402-paid-call.js +428 -1
  200. package/dist/payments/x402-paid-call.js.map +1 -1
  201. package/dist/policy/default-policies.d.ts +18 -2
  202. package/dist/policy/default-policies.d.ts.map +1 -1
  203. package/dist/policy/default-policies.js +18 -2
  204. package/dist/policy/default-policies.js.map +1 -1
  205. package/dist/policy/index.d.ts +6 -3
  206. package/dist/policy/index.d.ts.map +1 -1
  207. package/dist/policy/index.js +6 -3
  208. package/dist/policy/index.js.map +1 -1
  209. package/dist/policy/local-policy-engine.d.ts +71 -13
  210. package/dist/policy/local-policy-engine.d.ts.map +1 -1
  211. package/dist/policy/local-policy-engine.js +33 -11
  212. package/dist/policy/local-policy-engine.js.map +1 -1
  213. package/dist/policy/permission-checks.d.ts +29 -3
  214. package/dist/policy/permission-checks.d.ts.map +1 -1
  215. package/dist/policy/permission-checks.js +29 -3
  216. package/dist/policy/permission-checks.js.map +1 -1
  217. package/dist/policy/policy-engine.d.ts +22 -2
  218. package/dist/policy/policy-engine.d.ts.map +1 -1
  219. package/dist/policy/policy-engine.js +22 -2
  220. package/dist/policy/policy-engine.js.map +1 -1
  221. package/dist/policy/policy-types.d.ts +55 -5
  222. package/dist/policy/policy-types.d.ts.map +1 -1
  223. package/dist/policy/policy-types.js +8 -1
  224. package/dist/policy/policy-types.js.map +1 -1
  225. package/dist/policy/risk-level.d.ts +32 -3
  226. package/dist/policy/risk-level.d.ts.map +1 -1
  227. package/dist/policy/risk-level.js +32 -3
  228. package/dist/policy/risk-level.js.map +1 -1
  229. package/dist/policy/spending-limits.d.ts +29 -3
  230. package/dist/policy/spending-limits.d.ts.map +1 -1
  231. package/dist/policy/spending-limits.js +29 -3
  232. package/dist/policy/spending-limits.js.map +1 -1
  233. package/dist/premium/activation-manager.d.ts +43 -0
  234. package/dist/premium/activation-manager.d.ts.map +1 -0
  235. package/dist/premium/activation-manager.js +131 -0
  236. package/dist/premium/activation-manager.js.map +1 -0
  237. package/dist/premium/builtin-plugins.d.ts +165 -0
  238. package/dist/premium/builtin-plugins.d.ts.map +1 -0
  239. package/dist/premium/builtin-plugins.js +422 -0
  240. package/dist/premium/builtin-plugins.js.map +1 -0
  241. package/dist/premium/event-store.d.ts +61 -0
  242. package/dist/premium/event-store.d.ts.map +1 -0
  243. package/dist/premium/event-store.js +130 -0
  244. package/dist/premium/event-store.js.map +1 -0
  245. package/dist/premium/index.d.ts +54 -0
  246. package/dist/premium/index.d.ts.map +1 -0
  247. package/dist/premium/index.js +54 -0
  248. package/dist/premium/index.js.map +1 -0
  249. package/dist/premium/manifest-builder.d.ts +65 -0
  250. package/dist/premium/manifest-builder.d.ts.map +1 -0
  251. package/dist/premium/manifest-builder.js +182 -0
  252. package/dist/premium/manifest-builder.js.map +1 -0
  253. package/dist/premium/meme-radar-capabilities.d.ts +38 -0
  254. package/dist/premium/meme-radar-capabilities.d.ts.map +1 -0
  255. package/dist/premium/meme-radar-capabilities.js +306 -0
  256. package/dist/premium/meme-radar-capabilities.js.map +1 -0
  257. package/dist/premium/metrics.d.ts +27 -0
  258. package/dist/premium/metrics.d.ts.map +1 -0
  259. package/dist/premium/metrics.js +65 -0
  260. package/dist/premium/metrics.js.map +1 -0
  261. package/dist/premium/plugin-validator.d.ts +39 -0
  262. package/dist/premium/plugin-validator.d.ts.map +1 -0
  263. package/dist/premium/plugin-validator.js +325 -0
  264. package/dist/premium/plugin-validator.js.map +1 -0
  265. package/dist/premium/private-manifest-loader.d.ts +111 -0
  266. package/dist/premium/private-manifest-loader.d.ts.map +1 -0
  267. package/dist/premium/private-manifest-loader.js +285 -0
  268. package/dist/premium/private-manifest-loader.js.map +1 -0
  269. package/dist/premium/provider-bridge.d.ts +133 -0
  270. package/dist/premium/provider-bridge.d.ts.map +1 -0
  271. package/dist/premium/provider-bridge.js +349 -0
  272. package/dist/premium/provider-bridge.js.map +1 -0
  273. package/dist/premium/session-manager.d.ts +125 -0
  274. package/dist/premium/session-manager.d.ts.map +1 -0
  275. package/dist/premium/session-manager.js +337 -0
  276. package/dist/premium/session-manager.js.map +1 -0
  277. package/dist/premium/stream-broker.d.ts +98 -0
  278. package/dist/premium/stream-broker.d.ts.map +1 -0
  279. package/dist/premium/stream-broker.js +199 -0
  280. package/dist/premium/stream-broker.js.map +1 -0
  281. package/dist/premium/tech-fundamentals-capabilities.d.ts +37 -0
  282. package/dist/premium/tech-fundamentals-capabilities.d.ts.map +1 -0
  283. package/dist/premium/tech-fundamentals-capabilities.js +283 -0
  284. package/dist/premium/tech-fundamentals-capabilities.js.map +1 -0
  285. package/dist/premium/trading-capabilities.d.ts +36 -0
  286. package/dist/premium/trading-capabilities.d.ts.map +1 -0
  287. package/dist/premium/trading-capabilities.js +205 -0
  288. package/dist/premium/trading-capabilities.js.map +1 -0
  289. package/dist/premium/types.d.ts +518 -0
  290. package/dist/premium/types.d.ts.map +1 -0
  291. package/dist/premium/types.js +23 -0
  292. package/dist/premium/types.js.map +1 -0
  293. package/dist/premium/webhook-engine.d.ts +138 -0
  294. package/dist/premium/webhook-engine.d.ts.map +1 -0
  295. package/dist/premium/webhook-engine.js +516 -0
  296. package/dist/premium/webhook-engine.js.map +1 -0
  297. package/dist/prompts/context/sap-agent-context.prompt.d.ts +5 -0
  298. package/dist/prompts/context/sap-agent-context.prompt.d.ts.map +1 -1
  299. package/dist/prompts/context/sap-agent-context.prompt.js +20 -16
  300. package/dist/prompts/context/sap-agent-context.prompt.js.map +1 -1
  301. package/dist/prompts/context/sap-agent-intent-router.prompt.d.ts +14 -0
  302. package/dist/prompts/context/sap-agent-intent-router.prompt.d.ts.map +1 -0
  303. package/dist/prompts/context/sap-agent-intent-router.prompt.js +155 -0
  304. package/dist/prompts/context/sap-agent-intent-router.prompt.js.map +1 -0
  305. package/dist/prompts/context/sap-agent-start.prompt.js +7 -0
  306. package/dist/prompts/context/sap-agent-start.prompt.js.map +1 -1
  307. package/dist/prompts/developer/debug-sap-error.prompt.d.ts +5 -0
  308. package/dist/prompts/developer/debug-sap-error.prompt.d.ts.map +1 -1
  309. package/dist/prompts/developer/debug-sap-error.prompt.js +3 -4
  310. package/dist/prompts/developer/debug-sap-error.prompt.js.map +1 -1
  311. package/dist/prompts/developer/generate-sap-integration.prompt.d.ts +5 -0
  312. package/dist/prompts/developer/generate-sap-integration.prompt.d.ts.map +1 -1
  313. package/dist/prompts/developer/generate-sap-integration.prompt.js +3 -4
  314. package/dist/prompts/developer/generate-sap-integration.prompt.js.map +1 -1
  315. package/dist/prompts/developer/index.d.ts +4 -1
  316. package/dist/prompts/developer/index.d.ts.map +1 -1
  317. package/dist/prompts/developer/index.js +4 -1
  318. package/dist/prompts/developer/index.js.map +1 -1
  319. package/dist/prompts/execution-proof/explain-proof-of-execution.prompt.d.ts +5 -0
  320. package/dist/prompts/execution-proof/explain-proof-of-execution.prompt.d.ts.map +1 -1
  321. package/dist/prompts/execution-proof/explain-proof-of-execution.prompt.js +3 -4
  322. package/dist/prompts/execution-proof/explain-proof-of-execution.prompt.js.map +1 -1
  323. package/dist/prompts/execution-proof/index.d.ts +4 -1
  324. package/dist/prompts/execution-proof/index.d.ts.map +1 -1
  325. package/dist/prompts/execution-proof/index.js +4 -1
  326. package/dist/prompts/execution-proof/index.js.map +1 -1
  327. package/dist/prompts/execution-proof/verify-execution-proof.prompt.d.ts +5 -0
  328. package/dist/prompts/execution-proof/verify-execution-proof.prompt.d.ts.map +1 -1
  329. package/dist/prompts/execution-proof/verify-execution-proof.prompt.js +3 -4
  330. package/dist/prompts/execution-proof/verify-execution-proof.prompt.js.map +1 -1
  331. package/dist/prompts/index.d.ts +4 -1
  332. package/dist/prompts/index.d.ts.map +1 -1
  333. package/dist/prompts/index.js +4 -1
  334. package/dist/prompts/index.js.map +1 -1
  335. package/dist/prompts/payments/create-paid-api.prompt.d.ts +5 -0
  336. package/dist/prompts/payments/create-paid-api.prompt.d.ts.map +1 -1
  337. package/dist/prompts/payments/create-paid-api.prompt.js +3 -4
  338. package/dist/prompts/payments/create-paid-api.prompt.js.map +1 -1
  339. package/dist/prompts/payments/explain-x402-settlement.prompt.d.ts +5 -0
  340. package/dist/prompts/payments/explain-x402-settlement.prompt.d.ts.map +1 -1
  341. package/dist/prompts/payments/explain-x402-settlement.prompt.js +16 -14
  342. package/dist/prompts/payments/explain-x402-settlement.prompt.js.map +1 -1
  343. package/dist/prompts/payments/index.d.ts +4 -1
  344. package/dist/prompts/payments/index.d.ts.map +1 -1
  345. package/dist/prompts/payments/index.js +4 -1
  346. package/dist/prompts/payments/index.js.map +1 -1
  347. package/dist/prompts/register-prompts.d.ts +18 -2
  348. package/dist/prompts/register-prompts.d.ts.map +1 -1
  349. package/dist/prompts/register-prompts.js +21 -3
  350. package/dist/prompts/register-prompts.js.map +1 -1
  351. package/dist/prompts/registry/analyze-sap-agent.prompt.d.ts +5 -0
  352. package/dist/prompts/registry/analyze-sap-agent.prompt.d.ts.map +1 -1
  353. package/dist/prompts/registry/analyze-sap-agent.prompt.js +3 -4
  354. package/dist/prompts/registry/analyze-sap-agent.prompt.js.map +1 -1
  355. package/dist/prompts/registry/index.d.ts +4 -1
  356. package/dist/prompts/registry/index.d.ts.map +1 -1
  357. package/dist/prompts/registry/index.js +4 -1
  358. package/dist/prompts/registry/index.js.map +1 -1
  359. package/dist/prompts/registry/register-sap-agent.prompt.d.ts +5 -0
  360. package/dist/prompts/registry/register-sap-agent.prompt.d.ts.map +1 -1
  361. package/dist/prompts/registry/register-sap-agent.prompt.js +22 -23
  362. package/dist/prompts/registry/register-sap-agent.prompt.js.map +1 -1
  363. package/dist/remote/premium-memory.d.ts +90 -0
  364. package/dist/remote/premium-memory.d.ts.map +1 -0
  365. package/dist/remote/premium-memory.js +161 -0
  366. package/dist/remote/premium-memory.js.map +1 -0
  367. package/dist/remote/premium-routes.d.ts +99 -0
  368. package/dist/remote/premium-routes.d.ts.map +1 -0
  369. package/dist/remote/premium-routes.js +347 -0
  370. package/dist/remote/premium-routes.js.map +1 -0
  371. package/dist/remote/public-home/sections.d.ts.map +1 -1
  372. package/dist/remote/public-home/sections.js +23 -4
  373. package/dist/remote/public-home/sections.js.map +1 -1
  374. package/dist/remote/public-home/types.d.ts +9 -0
  375. package/dist/remote/public-home/types.d.ts.map +1 -1
  376. package/dist/remote/server.d.ts +20 -0
  377. package/dist/remote/server.d.ts.map +1 -1
  378. package/dist/remote/server.js +370 -9
  379. package/dist/remote/server.js.map +1 -1
  380. package/dist/remote/tx-relay.d.ts +42 -0
  381. package/dist/remote/tx-relay.d.ts.map +1 -0
  382. package/dist/remote/tx-relay.js +118 -0
  383. package/dist/remote/tx-relay.js.map +1 -0
  384. package/dist/resources/current/sap-current-config.resource.d.ts +5 -0
  385. package/dist/resources/current/sap-current-config.resource.d.ts.map +1 -1
  386. package/dist/resources/current/sap-current-config.resource.js +2 -5
  387. package/dist/resources/current/sap-current-config.resource.js.map +1 -1
  388. package/dist/resources/execution-proof/index.d.ts +5 -0
  389. package/dist/resources/execution-proof/index.d.ts.map +1 -1
  390. package/dist/resources/execution-proof/index.js +5 -0
  391. package/dist/resources/execution-proof/index.js.map +1 -1
  392. package/dist/resources/execution-proof/sap-execution-record.resource.d.ts +5 -0
  393. package/dist/resources/execution-proof/sap-execution-record.resource.d.ts.map +1 -1
  394. package/dist/resources/execution-proof/sap-execution-record.resource.js +3 -4
  395. package/dist/resources/execution-proof/sap-execution-record.resource.js.map +1 -1
  396. package/dist/resources/index.d.ts +5 -0
  397. package/dist/resources/index.d.ts.map +1 -1
  398. package/dist/resources/index.js +5 -0
  399. package/dist/resources/index.js.map +1 -1
  400. package/dist/resources/memory/index.d.ts +5 -0
  401. package/dist/resources/memory/index.d.ts.map +1 -1
  402. package/dist/resources/memory/index.js +5 -0
  403. package/dist/resources/memory/index.js.map +1 -1
  404. package/dist/resources/memory/sap-memory.resource.d.ts +5 -0
  405. package/dist/resources/memory/sap-memory.resource.d.ts.map +1 -1
  406. package/dist/resources/memory/sap-memory.resource.js +3 -4
  407. package/dist/resources/memory/sap-memory.resource.js.map +1 -1
  408. package/dist/resources/profile/sap-active-profile.resource.d.ts +5 -0
  409. package/dist/resources/profile/sap-active-profile.resource.d.ts.map +1 -1
  410. package/dist/resources/profile/sap-active-profile.resource.js +2 -5
  411. package/dist/resources/profile/sap-active-profile.resource.js.map +1 -1
  412. package/dist/resources/register-resources.d.ts +5 -0
  413. package/dist/resources/register-resources.d.ts.map +1 -1
  414. package/dist/resources/register-resources.js +3 -1
  415. package/dist/resources/register-resources.js.map +1 -1
  416. package/dist/resources/registry/index.d.ts +5 -0
  417. package/dist/resources/registry/index.d.ts.map +1 -1
  418. package/dist/resources/registry/index.js +5 -0
  419. package/dist/resources/registry/index.js.map +1 -1
  420. package/dist/resources/registry/sap-agent.resource.d.ts +5 -0
  421. package/dist/resources/registry/sap-agent.resource.d.ts.map +1 -1
  422. package/dist/resources/registry/sap-agent.resource.js +3 -4
  423. package/dist/resources/registry/sap-agent.resource.js.map +1 -1
  424. package/dist/resources/registry/sap-global-registry.resource.d.ts +18 -4
  425. package/dist/resources/registry/sap-global-registry.resource.d.ts.map +1 -1
  426. package/dist/resources/registry/sap-global-registry.resource.js +18 -4
  427. package/dist/resources/registry/sap-global-registry.resource.js.map +1 -1
  428. package/dist/resources/reputation/index.d.ts +4 -1
  429. package/dist/resources/reputation/index.d.ts.map +1 -1
  430. package/dist/resources/reputation/index.js +4 -1
  431. package/dist/resources/reputation/index.js.map +1 -1
  432. package/dist/resources/reputation/sap-reputation.resource.d.ts +18 -4
  433. package/dist/resources/reputation/sap-reputation.resource.d.ts.map +1 -1
  434. package/dist/resources/reputation/sap-reputation.resource.js +18 -4
  435. package/dist/resources/reputation/sap-reputation.resource.js.map +1 -1
  436. package/dist/resources/tool-schema/index.d.ts +4 -1
  437. package/dist/resources/tool-schema/index.d.ts.map +1 -1
  438. package/dist/resources/tool-schema/index.js +4 -1
  439. package/dist/resources/tool-schema/index.js.map +1 -1
  440. package/dist/resources/tool-schema/sap-tool-schema.resource.d.ts +18 -4
  441. package/dist/resources/tool-schema/sap-tool-schema.resource.d.ts.map +1 -1
  442. package/dist/resources/tool-schema/sap-tool-schema.resource.js +18 -4
  443. package/dist/resources/tool-schema/sap-tool-schema.resource.js.map +1 -1
  444. package/dist/sap/index.d.ts +7 -1
  445. package/dist/sap/index.d.ts.map +1 -1
  446. package/dist/sap/index.js +7 -1
  447. package/dist/sap/index.js.map +1 -1
  448. package/dist/sap/sap-client-manager.d.ts +80 -13
  449. package/dist/sap/sap-client-manager.d.ts.map +1 -1
  450. package/dist/sap/sap-client-manager.js +80 -13
  451. package/dist/sap/sap-client-manager.js.map +1 -1
  452. package/dist/sap/sap-errors.d.ts +22 -3
  453. package/dist/sap/sap-errors.d.ts.map +1 -1
  454. package/dist/sap/sap-errors.js +22 -3
  455. package/dist/sap/sap-errors.js.map +1 -1
  456. package/dist/sap/sap-types.d.ts +75 -6
  457. package/dist/sap/sap-types.d.ts.map +1 -1
  458. package/dist/sap/sap-types.js +11 -1
  459. package/dist/sap/sap-types.js.map +1 -1
  460. package/dist/schemas/common.schema.d.ts +45 -8
  461. package/dist/schemas/common.schema.d.ts.map +1 -1
  462. package/dist/schemas/common.schema.js +45 -8
  463. package/dist/schemas/common.schema.js.map +1 -1
  464. package/dist/schemas/developer.schema.d.ts +22 -3
  465. package/dist/schemas/developer.schema.d.ts.map +1 -1
  466. package/dist/schemas/developer.schema.js +22 -3
  467. package/dist/schemas/developer.schema.js.map +1 -1
  468. package/dist/schemas/execution-proof.schema.d.ts +29 -4
  469. package/dist/schemas/execution-proof.schema.d.ts.map +1 -1
  470. package/dist/schemas/execution-proof.schema.js +29 -4
  471. package/dist/schemas/execution-proof.schema.js.map +1 -1
  472. package/dist/schemas/identity.schema.d.ts +23 -3
  473. package/dist/schemas/identity.schema.d.ts.map +1 -1
  474. package/dist/schemas/identity.schema.js +23 -3
  475. package/dist/schemas/identity.schema.js.map +1 -1
  476. package/dist/schemas/index.d.ts +11 -1
  477. package/dist/schemas/index.d.ts.map +1 -1
  478. package/dist/schemas/index.js +11 -1
  479. package/dist/schemas/index.js.map +1 -1
  480. package/dist/schemas/memory.schema.d.ts +23 -3
  481. package/dist/schemas/memory.schema.d.ts.map +1 -1
  482. package/dist/schemas/memory.schema.js +23 -3
  483. package/dist/schemas/memory.schema.js.map +1 -1
  484. package/dist/schemas/payments.schema.d.ts +24 -3
  485. package/dist/schemas/payments.schema.d.ts.map +1 -1
  486. package/dist/schemas/payments.schema.js +24 -3
  487. package/dist/schemas/payments.schema.js.map +1 -1
  488. package/dist/schemas/registry.schema.d.ts +38 -6
  489. package/dist/schemas/registry.schema.d.ts.map +1 -1
  490. package/dist/schemas/registry.schema.js +36 -4
  491. package/dist/schemas/registry.schema.js.map +1 -1
  492. package/dist/schemas/reputation.schema.d.ts +22 -3
  493. package/dist/schemas/reputation.schema.d.ts.map +1 -1
  494. package/dist/schemas/reputation.schema.js +22 -3
  495. package/dist/schemas/reputation.schema.js.map +1 -1
  496. package/dist/schemas/settlement.schema.d.ts +31 -4
  497. package/dist/schemas/settlement.schema.d.ts.map +1 -1
  498. package/dist/schemas/settlement.schema.js +31 -4
  499. package/dist/schemas/settlement.schema.js.map +1 -1
  500. package/dist/schemas/tool-schema.schema.d.ts +29 -3
  501. package/dist/schemas/tool-schema.schema.d.ts.map +1 -1
  502. package/dist/schemas/tool-schema.schema.js +29 -3
  503. package/dist/schemas/tool-schema.schema.js.map +1 -1
  504. package/dist/schemas/transaction.schema.d.ts +23 -3
  505. package/dist/schemas/transaction.schema.d.ts.map +1 -1
  506. package/dist/schemas/transaction.schema.js +23 -3
  507. package/dist/schemas/transaction.schema.js.map +1 -1
  508. package/dist/security/approval-required.d.ts +19 -2
  509. package/dist/security/approval-required.d.ts.map +1 -1
  510. package/dist/security/approval-required.js +19 -2
  511. package/dist/security/approval-required.js.map +1 -1
  512. package/dist/security/index.d.ts +7 -1
  513. package/dist/security/index.d.ts.map +1 -1
  514. package/dist/security/index.js +7 -1
  515. package/dist/security/index.js.map +1 -1
  516. package/dist/security/private-key-guard.d.ts +18 -2
  517. package/dist/security/private-key-guard.d.ts.map +1 -1
  518. package/dist/security/private-key-guard.js +19 -2
  519. package/dist/security/private-key-guard.js.map +1 -1
  520. package/dist/security/prompt-injection-notes.d.ts +10 -1
  521. package/dist/security/prompt-injection-notes.d.ts.map +1 -1
  522. package/dist/security/prompt-injection-notes.js +10 -1
  523. package/dist/security/prompt-injection-notes.js.map +1 -1
  524. package/dist/security/tool-permissions.d.ts.map +1 -1
  525. package/dist/security/tool-permissions.js +12 -0
  526. package/dist/security/tool-permissions.js.map +1 -1
  527. package/dist/security/unsafe-action-guard.d.ts +36 -10
  528. package/dist/security/unsafe-action-guard.d.ts.map +1 -1
  529. package/dist/security/unsafe-action-guard.js +67 -15
  530. package/dist/security/unsafe-action-guard.js.map +1 -1
  531. package/dist/server/create-server.d.ts +18 -3
  532. package/dist/server/create-server.d.ts.map +1 -1
  533. package/dist/server/create-server.js +20 -4
  534. package/dist/server/create-server.js.map +1 -1
  535. package/dist/server/index.d.ts +6 -1
  536. package/dist/server/index.d.ts.map +1 -1
  537. package/dist/server/index.js +6 -1
  538. package/dist/server/index.js.map +1 -1
  539. package/dist/server/register-capabilities.d.ts +17 -2
  540. package/dist/server/register-capabilities.d.ts.map +1 -1
  541. package/dist/server/register-capabilities.js +17 -2
  542. package/dist/server/register-capabilities.js.map +1 -1
  543. package/dist/server/server-metadata.d.ts +35 -1
  544. package/dist/server/server-metadata.d.ts.map +1 -1
  545. package/dist/server/server-metadata.js +36 -2
  546. package/dist/server/server-metadata.js.map +1 -1
  547. package/dist/session/agent-session.d.ts +35 -4
  548. package/dist/session/agent-session.d.ts.map +1 -1
  549. package/dist/session/agent-session.js +35 -4
  550. package/dist/session/agent-session.js.map +1 -1
  551. package/dist/session/delegated-session.d.ts +31 -3
  552. package/dist/session/delegated-session.d.ts.map +1 -1
  553. package/dist/session/delegated-session.js +31 -3
  554. package/dist/session/delegated-session.js.map +1 -1
  555. package/dist/session/index.d.ts +7 -1
  556. package/dist/session/index.d.ts.map +1 -1
  557. package/dist/session/index.js +7 -1
  558. package/dist/session/index.js.map +1 -1
  559. package/dist/session/redis-session-store.d.ts +94 -21
  560. package/dist/session/redis-session-store.d.ts.map +1 -1
  561. package/dist/session/redis-session-store.js +87 -20
  562. package/dist/session/redis-session-store.js.map +1 -1
  563. package/dist/session/session-limits.d.ts +34 -4
  564. package/dist/session/session-limits.d.ts.map +1 -1
  565. package/dist/session/session-limits.js +34 -4
  566. package/dist/session/session-limits.js.map +1 -1
  567. package/dist/session/session-permissions.d.ts +57 -7
  568. package/dist/session/session-permissions.d.ts.map +1 -1
  569. package/dist/session/session-permissions.js +57 -7
  570. package/dist/session/session-permissions.js.map +1 -1
  571. package/dist/session/session-store.d.ts +9 -1
  572. package/dist/session/session-store.d.ts.map +1 -1
  573. package/dist/session/session-store.js +18 -3
  574. package/dist/session/session-store.js.map +1 -1
  575. package/dist/session/session-types.d.ts +33 -4
  576. package/dist/session/session-types.d.ts.map +1 -1
  577. package/dist/session/session-types.js +9 -1
  578. package/dist/session/session-types.js.map +1 -1
  579. package/dist/signer/index.d.ts +7 -1
  580. package/dist/signer/index.d.ts.map +1 -1
  581. package/dist/signer/index.js +7 -1
  582. package/dist/signer/index.js.map +1 -1
  583. package/dist/signer/load-keypair.d.ts +25 -4
  584. package/dist/signer/load-keypair.d.ts.map +1 -1
  585. package/dist/signer/load-keypair.js +25 -4
  586. package/dist/signer/load-keypair.js.map +1 -1
  587. package/dist/signer/local-keypair-signer.d.ts +19 -3
  588. package/dist/signer/local-keypair-signer.d.ts.map +1 -1
  589. package/dist/signer/local-keypair-signer.js +24 -4
  590. package/dist/signer/local-keypair-signer.js.map +1 -1
  591. package/dist/signer/signer-resolver.d.ts +19 -2
  592. package/dist/signer/signer-resolver.d.ts.map +1 -1
  593. package/dist/signer/signer-resolver.js +26 -3
  594. package/dist/signer/signer-resolver.js.map +1 -1
  595. package/dist/signer/signer-types.d.ts +47 -5
  596. package/dist/signer/signer-types.d.ts.map +1 -1
  597. package/dist/signer/signer-types.js +13 -1
  598. package/dist/signer/signer-types.js.map +1 -1
  599. package/dist/strategies/strategy-store.d.ts +82 -0
  600. package/dist/strategies/strategy-store.d.ts.map +1 -0
  601. package/dist/strategies/strategy-store.js +165 -0
  602. package/dist/strategies/strategy-store.js.map +1 -0
  603. package/dist/tools/agent-start-tool.d.ts.map +1 -1
  604. package/dist/tools/agent-start-tool.js +481 -5
  605. package/dist/tools/agent-start-tool.js.map +1 -1
  606. package/dist/tools/client-sdk-tools.d.ts.map +1 -1
  607. package/dist/tools/client-sdk-tools.js +32 -7
  608. package/dist/tools/client-sdk-tools.js.map +1 -1
  609. package/dist/tools/estimate-tool-cost.d.ts +13 -0
  610. package/dist/tools/estimate-tool-cost.d.ts.map +1 -0
  611. package/dist/tools/estimate-tool-cost.js +139 -0
  612. package/dist/tools/estimate-tool-cost.js.map +1 -0
  613. package/dist/tools/index.d.ts +8 -0
  614. package/dist/tools/index.d.ts.map +1 -1
  615. package/dist/tools/index.js +11 -0
  616. package/dist/tools/index.js.map +1 -1
  617. package/dist/tools/magicblock-tools.d.ts +31 -6
  618. package/dist/tools/magicblock-tools.d.ts.map +1 -1
  619. package/dist/tools/magicblock-tools.js +178 -53
  620. package/dist/tools/magicblock-tools.js.map +1 -1
  621. package/dist/tools/memory-tools.d.ts +26 -0
  622. package/dist/tools/memory-tools.d.ts.map +1 -0
  623. package/dist/tools/memory-tools.js +533 -0
  624. package/dist/tools/memory-tools.js.map +1 -0
  625. package/dist/tools/perp-tools.d.ts +39 -0
  626. package/dist/tools/perp-tools.d.ts.map +1 -0
  627. package/dist/tools/perp-tools.js +1110 -0
  628. package/dist/tools/perp-tools.js.map +1 -0
  629. package/dist/tools/premium-tools.d.ts +8 -0
  630. package/dist/tools/premium-tools.d.ts.map +1 -0
  631. package/dist/tools/premium-tools.js +1102 -0
  632. package/dist/tools/premium-tools.js.map +1 -0
  633. package/dist/tools/profile-tools.d.ts.map +1 -1
  634. package/dist/tools/profile-tools.js +18 -1
  635. package/dist/tools/profile-tools.js.map +1 -1
  636. package/dist/tools/quick-context-tool.d.ts +16 -0
  637. package/dist/tools/quick-context-tool.d.ts.map +1 -0
  638. package/dist/tools/quick-context-tool.js +304 -0
  639. package/dist/tools/quick-context-tool.js.map +1 -0
  640. package/dist/tools/register-tools.d.ts.map +1 -1
  641. package/dist/tools/register-tools.js +17 -0
  642. package/dist/tools/register-tools.js.map +1 -1
  643. package/dist/tools/sap-sdk-tools.d.ts +420 -1
  644. package/dist/tools/sap-sdk-tools.d.ts.map +1 -1
  645. package/dist/tools/sap-sdk-tools.js +1548 -127
  646. package/dist/tools/sap-sdk-tools.js.map +1 -1
  647. package/dist/tools/sap-sns-tools.d.ts +2 -2
  648. package/dist/tools/sap-sns-tools.d.ts.map +1 -1
  649. package/dist/tools/sap-sns-tools.js +12 -8
  650. package/dist/tools/sap-sns-tools.js.map +1 -1
  651. package/dist/tools/skills-tools.d.ts +16 -0
  652. package/dist/tools/skills-tools.d.ts.map +1 -1
  653. package/dist/tools/skills-tools.js +282 -5
  654. package/dist/tools/skills-tools.js.map +1 -1
  655. package/dist/tools/tool-aliases.d.ts.map +1 -1
  656. package/dist/tools/tool-aliases.js +7 -0
  657. package/dist/tools/tool-aliases.js.map +1 -1
  658. package/dist/tools/transaction-tools.d.ts +135 -0
  659. package/dist/tools/transaction-tools.d.ts.map +1 -1
  660. package/dist/tools/transaction-tools.js +515 -16
  661. package/dist/tools/transaction-tools.js.map +1 -1
  662. package/dist/tools/x402-paid-call-tool.d.ts.map +1 -1
  663. package/dist/tools/x402-paid-call-tool.js +756 -23
  664. package/dist/tools/x402-paid-call-tool.js.map +1 -1
  665. package/dist/transports/index.d.ts +6 -1
  666. package/dist/transports/index.d.ts.map +1 -1
  667. package/dist/transports/index.js +6 -1
  668. package/dist/transports/index.js.map +1 -1
  669. package/dist/transports/stdio.d.ts +17 -5
  670. package/dist/transports/stdio.d.ts.map +1 -1
  671. package/dist/transports/stdio.js +17 -5
  672. package/dist/transports/stdio.js.map +1 -1
  673. package/dist/tui/wizard-save.d.ts +88 -8
  674. package/dist/tui/wizard-save.d.ts.map +1 -1
  675. package/dist/tui/wizard-save.js +77 -8
  676. package/dist/tui/wizard-save.js.map +1 -1
  677. package/dist/wizard-core/desktop-flow.d.ts.map +1 -1
  678. package/dist/wizard-core/desktop-flow.js +4 -2
  679. package/dist/wizard-core/desktop-flow.js.map +1 -1
  680. package/docs/03_CONFIGURATION_AND_WIZARD.md +5 -3
  681. package/docs/06_PAYMENTS_X402_AND_PAYSH.md +82 -4
  682. package/docs/07_ENDPOINTS_AND_CLIENTS.md +7 -3
  683. package/docs/09_TOOLS_SKILLS_AND_AGENT_GUIDE.md +21 -3
  684. package/docs/14_DESKTOP_WIZARD_RELEASE.md +8 -6
  685. package/docs/16_SAP_AGENT_IDENTITY_PIPELINE.md +304 -0
  686. package/docs/18_PREMIUM_PLUGIN_RUNTIME.md +108 -0
  687. package/docs/BRANCH_AND_CI.md +67 -0
  688. package/docs/README.md +19 -2
  689. package/docs/magicblock-tools.md +70 -29
  690. package/package.json +10 -6
  691. package/server.json +3 -3
  692. package/skills/README.md +12 -2
  693. package/skills/sap-agent-registry/SKILL.md +99 -4
  694. package/skills/sap-defi/SKILL.md +8 -4
  695. package/skills/sap-discovery-indexing/SKILL.md +26 -4
  696. package/skills/sap-escrow-settlement/SKILL.md +22 -4
  697. package/skills/sap-mcp/SKILL.md +140 -22
  698. package/skills/sap-mcp/TOOL_REFERENCE.md +47 -7
  699. package/skills/sap-nft-metaplex/SKILL.md +22 -0
  700. package/skills/sap-operations/SKILL.md +32 -3
  701. package/skills/sap-payments-x402/SKILL.md +85 -8
  702. package/skills/sap-sns/SKILL.md +32 -10
  703. package/smithery.config.schema.json +7 -0
@@ -2,12 +2,15 @@
2
2
  * @module transaction-tools
3
3
  * @description MCP tools for decoding, previewing, signing, and submitting Solana transactions.
4
4
  */
5
- import { LAMPORTS_PER_SOL, SystemProgram, Transaction, VersionedTransaction } from '@solana/web3.js';
5
+ import { LAMPORTS_PER_SOL, PublicKey, SystemProgram, Transaction, TransactionInstruction, VersionedTransaction } from '@solana/web3.js';
6
6
  import bs58 from 'bs58';
7
7
  import { registerTool } from '../adapters/mcp/sdk-compat.js';
8
8
  import { createTextResponse } from '../adapters/mcp/tool-response.js';
9
9
  const SYSTEM_TRANSFER_INSTRUCTION_INDEX = 2;
10
10
  const SYSTEM_TRANSFER_LAYOUT_BYTES = 12;
11
+ const DEFAULT_CONFIRMATION_TIMEOUT_MS = 90_000;
12
+ const MAX_CONFIRMATION_TIMEOUT_MS = 180_000;
13
+ const DEFAULT_TX_SUBMIT_RELAY_URL = 'https://mcp.sap.oobeprotocol.ai/tx/submit';
11
14
  /**
12
15
  * @name decodeInputBytes
13
16
  * @description Decodes base64/base58 transaction text into raw bytes.
@@ -15,7 +18,7 @@ const SYSTEM_TRANSFER_LAYOUT_BYTES = 12;
15
18
  * @param encoding - Encoding used by the incoming transaction.
16
19
  * @returns Raw serialized transaction bytes.
17
20
  */
18
- function decodeInputBytes(value, encoding = 'base64') {
21
+ export function decodeInputBytes(value, encoding = 'base64') {
19
22
  if (encoding === 'base64') {
20
23
  return Buffer.from(value, 'base64');
21
24
  }
@@ -31,7 +34,7 @@ function decodeInputBytes(value, encoding = 'base64') {
31
34
  * @param encoding - Encoding used by the incoming transaction.
32
35
  * @returns Deserialized Solana transaction.
33
36
  */
34
- function deserializeTransaction(value, encoding) {
37
+ export function deserializeTransaction(value, encoding) {
35
38
  const bytes = decodeInputBytes(value, encoding);
36
39
  try {
37
40
  return VersionedTransaction.deserialize(bytes);
@@ -105,7 +108,7 @@ function estimateNativeTransfer(transaction, signer) {
105
108
  * @param transaction - Deserialized transaction to check.
106
109
  * @param signer - Optional signer filter for signing checks.
107
110
  */
108
- async function assertTransactionPolicy(context, transaction, signer) {
111
+ export async function assertTransactionPolicy(context, transaction, signer) {
109
112
  const nativeTransfer = estimateNativeTransfer(transaction, signer);
110
113
  if (nativeTransfer.sol <= 0) {
111
114
  return nativeTransfer;
@@ -125,7 +128,7 @@ async function assertTransactionPolicy(context, transaction, signer) {
125
128
  * @param transaction - Transaction to serialize.
126
129
  * @returns Base64 encoded transaction bytes.
127
130
  */
128
- function serializeTransaction(transaction) {
131
+ export function serializeTransaction(transaction) {
129
132
  if (transaction instanceof VersionedTransaction) {
130
133
  return Buffer.from(transaction.serialize()).toString('base64');
131
134
  }
@@ -134,13 +137,169 @@ function serializeTransaction(transaction) {
134
137
  verifySignatures: false,
135
138
  }).toString('base64');
136
139
  }
140
+ /**
141
+ * @name submitSignedTransactionWithLifecycle
142
+ * @description Submits a signed transaction through the configured local RPC and waits for a bounded confirmation result.
143
+ * @param context - Shared MCP runtime context.
144
+ * @param input - Signed transaction plus send/confirmation options.
145
+ * @returns Submission lifecycle result with retry guidance.
146
+ */
147
+ export async function submitSignedTransactionWithLifecycle(context, input) {
148
+ const signedTransaction = input.signedTransaction;
149
+ const encoding = input.encoding ?? 'base64';
150
+ const rawTransaction = decodeInputBytes(signedTransaction, encoding);
151
+ await assertTransactionPolicy(context, deserializeTransaction(signedTransaction, encoding));
152
+ const signature = await context.connection.sendRawTransaction(rawTransaction, {
153
+ skipPreflight: input.skipPreflight,
154
+ maxRetries: input.maxRetries ?? context.config.maxRetries,
155
+ });
156
+ const confirmationTimeoutMs = boundConfirmationTimeout(input.confirmationTimeoutMs);
157
+ const desiredCommitment = input.commitment ?? 'confirmed';
158
+ const confirmation = await waitForSignatureStatus(context, signature, confirmationTimeoutMs, desiredCommitment);
159
+ return {
160
+ success: confirmation.success,
161
+ submitted: true,
162
+ signature,
163
+ confirmationStatus: confirmation.status,
164
+ retrySafe: confirmation.retrySafe,
165
+ ...(confirmation.slot === undefined ? {} : { slot: confirmation.slot }),
166
+ explorerUrl: `https://solscan.io/tx/${signature}`,
167
+ audit: {
168
+ intentId: input.intentId ?? `sap-tx-${Date.now()}`,
169
+ submittedVia: 'local-rpc',
170
+ confirmationTimeoutMs,
171
+ desiredCommitment,
172
+ retrySafe: confirmation.retrySafe,
173
+ rule: confirmation.success
174
+ ? 'The signed transaction was submitted and observed on-chain before returning success.'
175
+ : 'The signed transaction was submitted but did not reach the requested confirmation state before timeout; retry only when retrySafe is true and the user confirms.',
176
+ },
177
+ };
178
+ }
179
+ /**
180
+ * @name submitSignedTransactionViaRelay
181
+ * @description Submits a signed transaction to the hosted OOBE submit relay. The relay never signs; it only broadcasts and confirms already-signed bytes.
182
+ * @param input - Signed transaction plus send/confirmation options.
183
+ * @returns Relay lifecycle result with retry guidance.
184
+ */
185
+ export async function submitSignedTransactionViaRelay(input) {
186
+ const relayUrl = input.submitRelayUrl ?? process.env.SAP_MCP_TX_SUBMIT_RELAY_URL ?? DEFAULT_TX_SUBMIT_RELAY_URL;
187
+ validateRelayUrl(relayUrl);
188
+ const response = await fetch(relayUrl, {
189
+ method: 'POST',
190
+ headers: {
191
+ 'Content-Type': 'application/json',
192
+ Accept: 'application/json',
193
+ },
194
+ body: JSON.stringify({
195
+ signedTransaction: input.signedTransaction,
196
+ encoding: input.encoding ?? 'base64',
197
+ skipPreflight: input.skipPreflight,
198
+ maxRetries: input.maxRetries,
199
+ confirmationTimeoutMs: input.confirmationTimeoutMs,
200
+ commitment: input.commitment,
201
+ intentId: input.intentId,
202
+ }),
203
+ });
204
+ const body = await response.json().catch(() => undefined);
205
+ if (!response.ok) {
206
+ const message = typeof body === 'object' && body && 'error' in body
207
+ ? String(body.error)
208
+ : `submit relay returned HTTP ${response.status}`;
209
+ throw new Error(message);
210
+ }
211
+ if (!isRelaySubmitResult(body)) {
212
+ throw new Error('submit relay returned an invalid transaction lifecycle response.');
213
+ }
214
+ return {
215
+ ...body,
216
+ audit: {
217
+ ...body.audit,
218
+ submittedVia: 'hosted-submit-relay',
219
+ relayUrl,
220
+ signerBoundary: 'local-signer-remote-submit-only',
221
+ },
222
+ };
223
+ }
224
+ async function waitForSignatureStatus(context, signature, timeoutMs, desiredCommitment) {
225
+ const startedAt = Date.now();
226
+ let lastStatus = 'missing';
227
+ let lastSlot;
228
+ while (Date.now() - startedAt < timeoutMs) {
229
+ const statuses = await context.connection.getSignatureStatuses([signature], { searchTransactionHistory: true });
230
+ const status = statuses.value[0];
231
+ if (status?.err) {
232
+ return {
233
+ success: false,
234
+ retrySafe: true,
235
+ status: 'failed',
236
+ ...(status.slot === undefined ? {} : { slot: status.slot }),
237
+ };
238
+ }
239
+ if (status) {
240
+ lastStatus = status.confirmationStatus ?? 'processed';
241
+ lastSlot = status.slot;
242
+ if (commitmentReached(lastStatus, desiredCommitment)) {
243
+ return {
244
+ success: true,
245
+ retrySafe: false,
246
+ status: lastStatus,
247
+ ...(lastSlot === undefined ? {} : { slot: lastSlot }),
248
+ };
249
+ }
250
+ }
251
+ await sleep(2_000);
252
+ }
253
+ return {
254
+ success: false,
255
+ retrySafe: lastStatus === 'missing',
256
+ status: lastStatus === 'missing' ? 'expired_or_not_landed' : lastStatus,
257
+ ...(lastSlot === undefined ? {} : { slot: lastSlot }),
258
+ };
259
+ }
260
+ function commitmentReached(current, desired) {
261
+ const rank = {
262
+ processed: 1,
263
+ confirmed: 2,
264
+ finalized: 3,
265
+ };
266
+ return (rank[current] ?? 0) >= rank[desired];
267
+ }
268
+ function boundConfirmationTimeout(value) {
269
+ if (!Number.isFinite(value)) {
270
+ return DEFAULT_CONFIRMATION_TIMEOUT_MS;
271
+ }
272
+ return Math.max(15_000, Math.min(Number(value), MAX_CONFIRMATION_TIMEOUT_MS));
273
+ }
274
+ function validateRelayUrl(value) {
275
+ const url = new URL(value);
276
+ if (url.protocol !== 'https:' && url.hostname !== '127.0.0.1' && url.hostname !== 'localhost') {
277
+ throw new Error('submitRelayUrl must use https, localhost, or 127.0.0.1.');
278
+ }
279
+ }
280
+ function isRelaySubmitResult(value) {
281
+ if (!value || typeof value !== 'object') {
282
+ return false;
283
+ }
284
+ const record = value;
285
+ return typeof record.success === 'boolean'
286
+ && record.submitted === true
287
+ && typeof record.signature === 'string'
288
+ && typeof record.confirmationStatus === 'string'
289
+ && typeof record.retrySafe === 'boolean'
290
+ && typeof record.explorerUrl === 'string'
291
+ && typeof record.audit === 'object';
292
+ }
293
+ async function sleep(ms) {
294
+ await new Promise(resolve => setTimeout(resolve, ms));
295
+ }
137
296
  /**
138
297
  * @name describeTransaction
139
298
  * @description Builds a stable JSON preview from a Solana transaction.
140
299
  * @param transaction - Deserialized transaction.
141
300
  * @returns Transaction metadata safe to expose to MCP clients.
142
301
  */
143
- function describeTransaction(transaction, context) {
302
+ export function describeTransaction(transaction, context) {
144
303
  const nativeTransfer = estimateNativeTransfer(transaction);
145
304
  const maxTxValueSol = context?.config.maxTxValueSol;
146
305
  const policyAllowed = context
@@ -185,6 +344,120 @@ function describeTransaction(transaction, context) {
185
344
  policyReason,
186
345
  };
187
346
  }
347
+ /**
348
+ * @name finalizeTransactionWithLocalSigner
349
+ * @description Preview, sign, and optionally submit a transaction with the local SAP MCP signer.
350
+ * @param context - Shared MCP runtime context containing signer, policy, and RPC connection.
351
+ * @param input - Transaction finalization request.
352
+ * @returns Agent-readable finalization result without secret material.
353
+ */
354
+ export async function finalizeTransactionWithLocalSigner(context, input) {
355
+ if (input.confirm !== true) {
356
+ throw new Error('confirm: true is required before the local SAP MCP signer can finalize a transaction.');
357
+ }
358
+ const transactionText = input.transaction ?? input.transactionBase64;
359
+ if (!transactionText) {
360
+ throw new Error('transaction or transactionBase64 is required.');
361
+ }
362
+ // Resolve signer: use signerProfile if provided, otherwise fall back to the
363
+ // active context signer. This eliminates the need to switch .active-profile
364
+ // manually — multiple profiles can coexist in the same session.
365
+ let signer = context.signer;
366
+ let signerProfileName;
367
+ if (input.signerProfile) {
368
+ const { loadProfileConfig } = await import('../config/profiles.js');
369
+ const { resolveSigner } = await import('../signer/signer-resolver.js');
370
+ const profileConfig = loadProfileConfig(input.signerProfile);
371
+ if (!profileConfig) {
372
+ throw new Error(`signerProfile "${input.signerProfile}" not found. ` +
373
+ `Available profiles can be listed with sap_profile_list (local mode) or by checking ~/.config/mcp-sap/config-*.json files. ` +
374
+ `If the hosted server is accountless, use the local sap_payments bridge to inspect profiles.`);
375
+ }
376
+ // FullConfig does not include monetization — merge with the active context
377
+ // config to provide the required SapMcpConfig shape for resolveSigner.
378
+ const mergedConfig = { ...context.config, ...profileConfig };
379
+ const signerResult = await resolveSigner(mergedConfig);
380
+ if (!signerResult.signer) {
381
+ throw new Error(`signerProfile "${input.signerProfile}" has no signer configured. ` +
382
+ `Ensure the profile config has a walletPath or externalSignerUrl set. ` +
383
+ `Run: sap-mcp-config wizard --profile ${input.signerProfile} to configure.`);
384
+ }
385
+ signer = signerResult.signer;
386
+ signerProfileName = input.signerProfile;
387
+ }
388
+ if (!signer) {
389
+ throw new Error('No local signer configured. Run the SAP MCP wizard full setup or repair the local sap_payments bridge, then restart the agent runtime.');
390
+ }
391
+ const encoding = input.encoding ?? 'base64';
392
+ const transaction = deserializeTransaction(transactionText, encoding);
393
+ const preview = describeTransaction(transaction, context);
394
+ const nativeTransfer = await assertTransactionPolicy(context, transaction, signer.publicKey);
395
+ const signedTransaction = await signer.signTransaction(transaction);
396
+ const signedTransactionBase64 = serializeTransaction(signedTransaction);
397
+ const result = {
398
+ success: true,
399
+ action: input.submit === true ? 'preview-sign-submit' : 'preview-sign',
400
+ submitted: false,
401
+ signerPublicKey: signer.publicKey.toBase58(),
402
+ signerProfile: signerProfileName ?? null,
403
+ nativeTransferSol: nativeTransfer.sol,
404
+ preview: {
405
+ ...preview,
406
+ canSign: true,
407
+ signer: signer.publicKey.toBase58(),
408
+ signerProfile: signerProfileName ?? null,
409
+ },
410
+ signedTransaction: signedTransactionBase64,
411
+ encoding: 'base64',
412
+ audit: {
413
+ intentId: input.intentId ?? `sap-tx-${Date.now()}`,
414
+ profileMode: context.config.mode,
415
+ signerProfile: signerProfileName ?? null,
416
+ signerPublicKey: signer.publicKey.toBase58(),
417
+ previewed: true,
418
+ signedLocally: true,
419
+ submitted: false,
420
+ secretMaterial: 'keypair-bytes-never-returned',
421
+ rule: 'Finalized by SAP MCP local signer. No temporary scripts, raw keypair reads, or exported secret bytes were used.',
422
+ },
423
+ };
424
+ if (input.submit === true) {
425
+ const submitResult = input.submitViaRelay === false
426
+ ? await submitSignedTransactionWithLifecycle(context, {
427
+ signedTransaction: signedTransactionBase64,
428
+ encoding: 'base64',
429
+ skipPreflight: input.skipPreflight,
430
+ maxRetries: input.maxRetries,
431
+ confirmationTimeoutMs: input.confirmationTimeoutMs,
432
+ commitment: input.commitment,
433
+ intentId: input.intentId,
434
+ })
435
+ : await submitSignedTransactionViaRelay({
436
+ signedTransaction: signedTransactionBase64,
437
+ encoding: 'base64',
438
+ skipPreflight: input.skipPreflight,
439
+ maxRetries: input.maxRetries,
440
+ confirmationTimeoutMs: input.confirmationTimeoutMs,
441
+ commitment: input.commitment,
442
+ submitRelayUrl: input.submitRelayUrl,
443
+ intentId: input.intentId,
444
+ });
445
+ result.success = submitResult.success;
446
+ result.submitted = submitResult.submitted;
447
+ result.signature = submitResult.signature;
448
+ result.confirmationStatus = submitResult.confirmationStatus;
449
+ result.retrySafe = submitResult.retrySafe;
450
+ result.explorerUrl = submitResult.explorerUrl;
451
+ result.audit = {
452
+ ...result.audit,
453
+ ...submitResult.audit,
454
+ submitted: submitResult.submitted,
455
+ signature: submitResult.signature,
456
+ transactionLanded: submitResult.success,
457
+ };
458
+ }
459
+ return result;
460
+ }
188
461
  /**
189
462
  * @name registerTransactionTools
190
463
  * @description Registers real transaction decode, preview, signing, and submission tools.
@@ -194,7 +467,7 @@ function describeTransaction(transaction, context) {
194
467
  export function registerTransactionTools(server, context) {
195
468
  registerTool(server, 'sap_decode_transaction', {
196
469
  title: 'Decode Transaction',
197
- description: 'Decode a serialized Solana transaction and return stable transaction metadata.',
470
+ description: 'Decode a serialized Solana transaction and return stable transaction metadata. Use this before signing when a SAP MCP, Jupiter, MagicBlock, SNS, Metaplex, or DeFi tool returns transactionBase64 or an unsigned transaction.',
198
471
  inputSchema: {
199
472
  transaction: { type: 'string', description: 'Serialized transaction' },
200
473
  encoding: { type: 'string', enum: ['base64', 'base58'], description: 'Input encoding' },
@@ -212,7 +485,7 @@ export function registerTransactionTools(server, context) {
212
485
  });
213
486
  registerTool(server, 'sap_preview_transaction', {
214
487
  title: 'Preview Transaction',
215
- description: 'Preview a Solana transaction before signing or submission.',
488
+ description: 'Preview a Solana transaction before signing or submission. This is the required preflight step for agent workflows; do not create local signing scripts or read keypair files.',
216
489
  inputSchema: {
217
490
  transaction: { type: 'string', description: 'Serialized transaction' },
218
491
  encoding: { type: 'string', enum: ['base64', 'base58'], description: 'Input encoding' },
@@ -236,7 +509,7 @@ export function registerTransactionTools(server, context) {
236
509
  });
237
510
  registerTool(server, 'sap_sign_transaction', {
238
511
  title: 'Sign Transaction',
239
- description: 'Sign a serialized Solana transaction with the configured SAP MCP signer.',
512
+ description: 'Sign a serialized Solana transaction with the configured SAP MCP signer after sap_preview_transaction. This is the supported non-custodial signing path for agents; never read keypair JSON or sign raw message bytes in temporary scripts.',
240
513
  inputSchema: {
241
514
  transaction: { type: 'string', description: 'Unsigned or partially signed transaction' },
242
515
  encoding: { type: 'string', enum: ['base64', 'base58'], description: 'Input encoding' },
@@ -266,27 +539,253 @@ export function registerTransactionTools(server, context) {
266
539
  });
267
540
  registerTool(server, 'sap_submit_signed_transaction', {
268
541
  title: 'Submit Signed Transaction',
269
- description: 'Submit a signed Solana transaction through the configured RPC endpoint.',
542
+ description: 'Submit a signed Solana transaction produced by sap_sign_transaction through the configured RPC endpoint. Use this instead of custom sendRawTransaction scripts so policy, retries, and audit stay inside SAP MCP.',
270
543
  inputSchema: {
271
544
  signedTransaction: { type: 'string', description: 'Signed serialized transaction' },
272
545
  encoding: { type: 'string', enum: ['base64', 'base58'], description: 'Input encoding' },
273
546
  skipPreflight: { type: 'boolean', description: 'Skip RPC preflight checks' },
274
547
  maxRetries: { type: 'number', description: 'Maximum RPC send retries' },
548
+ confirmationTimeoutMs: { type: 'number', description: 'Bounded confirmation wait in milliseconds. Defaults to 90000; maximum 180000.' },
549
+ commitment: { type: 'string', enum: ['processed', 'confirmed', 'finalized'], description: 'Desired confirmation status before returning success. Defaults to confirmed.' },
550
+ submitViaRelay: { type: 'boolean', description: 'When true, submit through the hosted OOBE relay. The relay only broadcasts already-signed bytes and never signs. Defaults to false for this local tool.' },
551
+ submitRelayUrl: { type: 'string', description: 'Optional submit relay URL. Must be HTTPS, localhost, or 127.0.0.1.' },
552
+ intentId: { type: 'string', description: 'Optional caller-provided id binding submission, confirmation, and audit output.' },
275
553
  },
276
554
  }, async (input) => {
277
555
  try {
278
556
  if (!input.signedTransaction) {
279
557
  throw new Error('signedTransaction is required');
280
558
  }
281
- const rawTransaction = decodeInputBytes(input.signedTransaction, input.encoding);
282
- await assertTransactionPolicy(context, deserializeTransaction(input.signedTransaction, input.encoding));
283
- const signature = await context.connection.sendRawTransaction(rawTransaction, {
284
- skipPreflight: input.skipPreflight,
285
- maxRetries: input.maxRetries,
559
+ const result = input.submitViaRelay === true
560
+ ? await submitSignedTransactionViaRelay({
561
+ signedTransaction: input.signedTransaction,
562
+ encoding: input.encoding,
563
+ skipPreflight: input.skipPreflight,
564
+ maxRetries: input.maxRetries,
565
+ confirmationTimeoutMs: input.confirmationTimeoutMs,
566
+ commitment: input.commitment,
567
+ submitRelayUrl: input.submitRelayUrl,
568
+ intentId: input.intentId,
569
+ })
570
+ : await submitSignedTransactionWithLifecycle(context, {
571
+ signedTransaction: input.signedTransaction,
572
+ encoding: input.encoding,
573
+ skipPreflight: input.skipPreflight,
574
+ maxRetries: input.maxRetries,
575
+ confirmationTimeoutMs: input.confirmationTimeoutMs,
576
+ commitment: input.commitment,
577
+ intentId: input.intentId,
578
+ });
579
+ return createTextResponse(JSON.stringify(result, null, 2), { isError: !result.success });
580
+ }
581
+ catch (error) {
582
+ return createTextResponse(`Error: ${error instanceof Error ? error.message : 'Unknown error'}`, { isError: true });
583
+ }
584
+ });
585
+ // ── Native SOL Transfer Builder ───────────────────────────────────────────
586
+ //
587
+ // There is no hosted builder for native SOL transfers — `spl-token_transferSol`
588
+ // is local-signer-only and cannot run on the hosted accountless server. This
589
+ // builder creates an unsigned SystemProgram.transfer transaction that the
590
+ // agent signs locally via sap_payments_finalize_transaction or
591
+ // sap_sign_transaction → sap_submit_signed_transaction.
592
+ //
593
+ registerTool(server, 'sap_build_sol_transfer', {
594
+ title: 'Build Native SOL Transfer Transaction',
595
+ description: 'Build an unsigned native SOL transfer transaction using SystemProgram.transfer. Returns serialized base64 transaction for the agent to sign locally with sap_payments_finalize_transaction or sap_sign_transaction → sap_submit_signed_transaction. This is the hosted-safe equivalent of spl-token_transferSol (which is local-signer-only and cannot run on the hosted accountless server). Builder fee applies.',
596
+ inputSchema: {
597
+ fromPubkey: {
598
+ type: 'string',
599
+ description: 'Sender public key in base58. This is the fee payer and must sign the transaction locally.',
600
+ },
601
+ toPubkey: {
602
+ type: 'string',
603
+ description: 'Recipient public key in base58.',
604
+ },
605
+ lamports: {
606
+ type: 'number',
607
+ description: 'Amount in lamports (1 SOL = 1,000,000,000 lamports). Use sap_estimate_tool_cost to check the builder fee before calling.',
608
+ },
609
+ },
610
+ }, async (input) => {
611
+ try {
612
+ const raw = input;
613
+ const fromPubkey = typeof raw['fromPubkey'] === 'string' ? raw['fromPubkey'] : undefined;
614
+ const toPubkey = typeof raw['toPubkey'] === 'string' ? raw['toPubkey'] : undefined;
615
+ const lamports = typeof raw['lamports'] === 'number' ? raw['lamports'] : undefined;
616
+ if (!fromPubkey || !toPubkey || lamports === undefined) {
617
+ throw new Error('fromPubkey, toPubkey, and lamports are required.');
618
+ }
619
+ // Validate public keys.
620
+ const fromKey = new PublicKey(fromPubkey);
621
+ const toKey = new PublicKey(toPubkey);
622
+ if (lamports <= 0) {
623
+ throw new Error('lamports must be a positive number.');
624
+ }
625
+ // Build the SystemProgram.transfer instruction.
626
+ const instruction = SystemProgram.transfer({
627
+ fromPubkey: fromKey,
628
+ toPubkey: toKey,
629
+ lamports,
286
630
  });
631
+ // Create a legacy transaction with the transfer instruction.
632
+ // The latest blockhash is fetched from the configured RPC.
633
+ const connection = context.connection;
634
+ const blockhash = await connection.getLatestBlockhash();
635
+ const transaction = new Transaction({
636
+ recentBlockhash: blockhash.blockhash,
637
+ feePayer: fromKey,
638
+ });
639
+ transaction.add(instruction);
640
+ // Serialize as base64 for the agent to sign locally.
641
+ const serialized = transaction.serialize({
642
+ requireAllSignatures: false,
643
+ verifySignatures: false,
644
+ });
645
+ const transactionBase64 = serialized.toString('base64');
646
+ return createTextResponse(JSON.stringify({
647
+ success: true,
648
+ transactionBase64,
649
+ encoding: 'base64',
650
+ instructions: [
651
+ {
652
+ program: 'SystemProgram',
653
+ type: 'Transfer',
654
+ from: fromPubkey,
655
+ to: toPubkey,
656
+ lamports,
657
+ solAmount: (lamports / LAMPORTS_PER_SOL).toFixed(9),
658
+ },
659
+ ],
660
+ feePayer: fromPubkey,
661
+ unsigned: true,
662
+ nextSteps: 'Sign locally with sap_payments_finalize_transaction (hosted mode) or sap_sign_transaction → sap_submit_signed_transaction (local mode). Do not create temporary signing scripts or read keypair JSON.',
663
+ }, null, 2));
664
+ }
665
+ catch (error) {
666
+ return createTextResponse(`Error: ${error instanceof Error ? error.message : 'Unknown error'}`, { isError: true });
667
+ }
668
+ });
669
+ // ── SPL Token Transfer Builder ─────────────────────────────────────────────
670
+ //
671
+ // `spl-token_transfer` is local-signer-only and cannot run on the hosted
672
+ // accountless server. This builder creates an unsigned SPL token transfer
673
+ // transaction that the agent signs locally via sap_payments_finalize_transaction.
674
+ //
675
+ registerTool(server, 'sap_build_spl_transfer', {
676
+ title: 'Build SPL Token Transfer Transaction',
677
+ description: 'Build an unsigned SPL token transfer transaction. Returns serialized base64 transaction for the agent to sign locally with sap_payments_finalize_transaction or sap_sign_transaction → sap_submit_signed_transaction. This is the hosted-safe equivalent of spl-token_transfer (which is local-signer-only and cannot run on the hosted accountless server). Builder fee applies.',
678
+ inputSchema: {
679
+ sourceOwner: {
680
+ type: 'string',
681
+ description: 'Source token account owner public key in base58. This is the fee payer and must sign the transaction locally.',
682
+ },
683
+ destinationOwner: {
684
+ type: 'string',
685
+ description: 'Destination wallet public key in base58. The destination ATA will be created if it does not exist.',
686
+ },
687
+ mint: {
688
+ type: 'string',
689
+ description: 'SPL token mint address in base58.',
690
+ },
691
+ amount: {
692
+ type: 'number',
693
+ description: 'Amount of tokens to transfer in base units (respect the mint decimals).',
694
+ },
695
+ decimals: {
696
+ type: 'number',
697
+ description: 'Token decimals for the mint. Used for display purposes only — the on-chain amount is in base units.',
698
+ },
699
+ },
700
+ }, async (input) => {
701
+ try {
702
+ const raw = input;
703
+ const sourceOwner = typeof raw['sourceOwner'] === 'string' ? raw['sourceOwner'] : undefined;
704
+ const destinationOwner = typeof raw['destinationOwner'] === 'string' ? raw['destinationOwner'] : undefined;
705
+ const mint = typeof raw['mint'] === 'string' ? raw['mint'] : undefined;
706
+ const amount = typeof raw['amount'] === 'number' ? raw['amount'] : undefined;
707
+ const decimals = typeof raw['decimals'] === 'number' ? raw['decimals'] : undefined;
708
+ if (!sourceOwner || !destinationOwner || !mint || amount === undefined) {
709
+ throw new Error('sourceOwner, destinationOwner, mint, and amount are required.');
710
+ }
711
+ if (amount <= 0) {
712
+ throw new Error('amount must be a positive number.');
713
+ }
714
+ // Build SPL token transfer instructions using @solana/web3.js only.
715
+ // We construct the raw instruction data manually to avoid depending on
716
+ // @solana/spl-token (not in package.json).
717
+ const sourceOwnerKey = new PublicKey(sourceOwner);
718
+ const destOwnerKey = new PublicKey(destinationOwner);
719
+ const mintKey = new PublicKey(mint);
720
+ // Derive Associated Token Account addresses using findProgramAddress.
721
+ const ASSOCIATED_TOKEN_PROGRAM_ID = new PublicKey('ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL');
722
+ const TOKEN_PROGRAM_ID = new PublicKey('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA');
723
+ // ATA = PDA(['AssociatedTokenAddress', owner, tokenProgram, mint])
724
+ const [sourceAta] = PublicKey.findProgramAddressSync([Buffer.from('AssociatedTokenAddress'), sourceOwnerKey.toBuffer(), TOKEN_PROGRAM_ID.toBuffer(), mintKey.toBuffer()], ASSOCIATED_TOKEN_PROGRAM_ID);
725
+ const [destAta] = PublicKey.findProgramAddressSync([Buffer.from('AssociatedTokenAddress'), destOwnerKey.toBuffer(), TOKEN_PROGRAM_ID.toBuffer(), mintKey.toBuffer()], ASSOCIATED_TOKEN_PROGRAM_ID);
726
+ // CreateAssociatedTokenAccountIdempotent instruction (0x1e data).
727
+ const createAtaInstruction = new TransactionInstruction({
728
+ programId: ASSOCIATED_TOKEN_PROGRAM_ID,
729
+ keys: [
730
+ { pubkey: sourceOwnerKey, isSigner: true, isWritable: true },
731
+ { pubkey: destAta, isSigner: false, isWritable: true },
732
+ { pubkey: destOwnerKey, isSigner: false, isWritable: false },
733
+ { pubkey: mintKey, isSigner: false, isWritable: false },
734
+ { pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
735
+ { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
736
+ ],
737
+ data: Buffer.from([0x1e]),
738
+ });
739
+ // Token Transfer instruction (0x03 + 64-bit amount in little-endian).
740
+ const transferData = Buffer.alloc(9);
741
+ transferData.writeUInt8(3, 0); // Transfer instruction discriminator
742
+ transferData.writeBigUInt64LE(BigInt(amount), 1);
743
+ const transferInstruction = new TransactionInstruction({
744
+ programId: TOKEN_PROGRAM_ID,
745
+ keys: [
746
+ { pubkey: sourceAta, isSigner: false, isWritable: true },
747
+ { pubkey: destAta, isSigner: false, isWritable: true },
748
+ { pubkey: sourceOwnerKey, isSigner: true, isWritable: false },
749
+ ],
750
+ data: transferData,
751
+ });
752
+ // Fetch latest blockhash and build transaction.
753
+ const connection = context.connection;
754
+ const blockhash = await connection.getLatestBlockhash();
755
+ const transaction = new Transaction({
756
+ recentBlockhash: blockhash.blockhash,
757
+ feePayer: sourceOwnerKey,
758
+ });
759
+ transaction.add(createAtaInstruction);
760
+ transaction.add(transferInstruction);
761
+ const serialized = transaction.serialize({
762
+ requireAllSignatures: false,
763
+ verifySignatures: false,
764
+ });
765
+ const transactionBase64 = serialized.toString('base64');
287
766
  return createTextResponse(JSON.stringify({
288
767
  success: true,
289
- signature,
768
+ transactionBase64,
769
+ encoding: 'base64',
770
+ instructions: [
771
+ {
772
+ program: 'SPL Token',
773
+ type: 'CreateAssociatedTokenAccountIdempotent',
774
+ destinationAta: destAta.toBase58(),
775
+ },
776
+ {
777
+ program: 'SPL Token',
778
+ type: 'Transfer',
779
+ sourceAta: sourceAta.toBase58(),
780
+ destinationAta: destAta.toBase58(),
781
+ mint,
782
+ amount,
783
+ decimals: decimals ?? undefined,
784
+ },
785
+ ],
786
+ feePayer: sourceOwner,
787
+ unsigned: true,
788
+ nextSteps: 'Sign locally with sap_payments_finalize_transaction (hosted mode) or sap_sign_transaction → sap_submit_signed_transaction (local mode). Do not create temporary signing scripts or read keypair JSON.',
290
789
  }, null, 2));
291
790
  }
292
791
  catch (error) {