@taxdao/fintax-mcp 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (341) hide show
  1. package/README.md +220 -0
  2. package/dist/app/create-server.d.ts +18 -0
  3. package/dist/app/create-server.js +80 -0
  4. package/dist/app/create-server.js.map +1 -0
  5. package/dist/app/register-tools.d.ts +4 -0
  6. package/dist/app/register-tools.js +18 -0
  7. package/dist/app/register-tools.js.map +1 -0
  8. package/dist/audit/audit-context.d.ts +38 -0
  9. package/dist/audit/audit-context.js +167 -0
  10. package/dist/audit/audit-context.js.map +1 -0
  11. package/dist/audit/audit-sink.d.ts +20 -0
  12. package/dist/audit/audit-sink.js +6 -0
  13. package/dist/audit/audit-sink.js.map +1 -0
  14. package/dist/audit/file-audit-sink.d.ts +6 -0
  15. package/dist/audit/file-audit-sink.js +18 -0
  16. package/dist/audit/file-audit-sink.js.map +1 -0
  17. package/dist/auth/auth-session.d.ts +63 -0
  18. package/dist/auth/auth-session.js +226 -0
  19. package/dist/auth/auth-session.js.map +1 -0
  20. package/dist/auth/credentials.d.ts +6 -0
  21. package/dist/auth/credentials.js +12 -0
  22. package/dist/auth/credentials.js.map +1 -0
  23. package/dist/auth/org-token-provider.d.ts +15 -0
  24. package/dist/auth/org-token-provider.js +62 -0
  25. package/dist/auth/org-token-provider.js.map +1 -0
  26. package/dist/capabilities/capability.d.ts +100 -0
  27. package/dist/capabilities/capability.js +26 -0
  28. package/dist/capabilities/capability.js.map +1 -0
  29. package/dist/capabilities/create-capabilities.d.ts +2 -0
  30. package/dist/capabilities/create-capabilities.js +37 -0
  31. package/dist/capabilities/create-capabilities.js.map +1 -0
  32. package/dist/capabilities/define-capability.d.ts +39 -0
  33. package/dist/capabilities/define-capability.js +64 -0
  34. package/dist/capabilities/define-capability.js.map +1 -0
  35. package/dist/capabilities/definitions/accounting-balances.d.ts +4 -0
  36. package/dist/capabilities/definitions/accounting-balances.js +98 -0
  37. package/dist/capabilities/definitions/accounting-balances.js.map +1 -0
  38. package/dist/capabilities/definitions/accounting-context.d.ts +2 -0
  39. package/dist/capabilities/definitions/accounting-context.js +17 -0
  40. package/dist/capabilities/definitions/accounting-context.js.map +1 -0
  41. package/dist/capabilities/definitions/assets.d.ts +2 -0
  42. package/dist/capabilities/definitions/assets.js +367 -0
  43. package/dist/capabilities/definitions/assets.js.map +1 -0
  44. package/dist/capabilities/definitions/business-documents.d.ts +9 -0
  45. package/dist/capabilities/definitions/business-documents.js +386 -0
  46. package/dist/capabilities/definitions/business-documents.js.map +1 -0
  47. package/dist/capabilities/definitions/dashboard.d.ts +2 -0
  48. package/dist/capabilities/definitions/dashboard.js +153 -0
  49. package/dist/capabilities/definitions/dashboard.js.map +1 -0
  50. package/dist/capabilities/definitions/extended-operation-contracts.d.ts +597 -0
  51. package/dist/capabilities/definitions/extended-operation-contracts.js +1180 -0
  52. package/dist/capabilities/definitions/extended-operation-contracts.js.map +1 -0
  53. package/dist/capabilities/definitions/extended-operations.d.ts +2 -0
  54. package/dist/capabilities/definitions/extended-operations.js +699 -0
  55. package/dist/capabilities/definitions/extended-operations.js.map +1 -0
  56. package/dist/capabilities/definitions/financial-reports.d.ts +2 -0
  57. package/dist/capabilities/definitions/financial-reports.js +100 -0
  58. package/dist/capabilities/definitions/financial-reports.js.map +1 -0
  59. package/dist/capabilities/definitions/fnd-import.d.ts +34 -0
  60. package/dist/capabilities/definitions/fnd-import.js +282 -0
  61. package/dist/capabilities/definitions/fnd-import.js.map +1 -0
  62. package/dist/capabilities/definitions/fund-accounts.d.ts +2 -0
  63. package/dist/capabilities/definitions/fund-accounts.js +188 -0
  64. package/dist/capabilities/definitions/fund-accounts.js.map +1 -0
  65. package/dist/capabilities/definitions/fund-balances.d.ts +2 -0
  66. package/dist/capabilities/definitions/fund-balances.js +84 -0
  67. package/dist/capabilities/definitions/fund-balances.js.map +1 -0
  68. package/dist/capabilities/definitions/journals.d.ts +10 -0
  69. package/dist/capabilities/definitions/journals.js +224 -0
  70. package/dist/capabilities/definitions/journals.js.map +1 -0
  71. package/dist/capabilities/definitions/master-data.d.ts +2 -0
  72. package/dist/capabilities/definitions/master-data.js +451 -0
  73. package/dist/capabilities/definitions/master-data.js.map +1 -0
  74. package/dist/capabilities/definitions/pnl.d.ts +2 -0
  75. package/dist/capabilities/definitions/pnl.js +139 -0
  76. package/dist/capabilities/definitions/pnl.js.map +1 -0
  77. package/dist/capabilities/definitions/reference-data.d.ts +2 -0
  78. package/dist/capabilities/definitions/reference-data.js +169 -0
  79. package/dist/capabilities/definitions/reference-data.js.map +1 -0
  80. package/dist/capabilities/definitions/transaction-drafts.d.ts +2 -0
  81. package/dist/capabilities/definitions/transaction-drafts.js +157 -0
  82. package/dist/capabilities/definitions/transaction-drafts.js.map +1 -0
  83. package/dist/capabilities/definitions/transactions.d.ts +168 -0
  84. package/dist/capabilities/definitions/transactions.js +79 -0
  85. package/dist/capabilities/definitions/transactions.js.map +1 -0
  86. package/dist/capabilities/executor.d.ts +19 -0
  87. package/dist/capabilities/executor.js +134 -0
  88. package/dist/capabilities/executor.js.map +1 -0
  89. package/dist/capabilities/registry.d.ts +7 -0
  90. package/dist/capabilities/registry.js +51 -0
  91. package/dist/capabilities/registry.js.map +1 -0
  92. package/dist/clients/base-client.d.ts +5 -0
  93. package/dist/clients/base-client.js +13 -0
  94. package/dist/clients/base-client.js.map +1 -0
  95. package/dist/clients/http-client.d.ts +29 -0
  96. package/dist/clients/http-client.js +167 -0
  97. package/dist/clients/http-client.js.map +1 -0
  98. package/dist/clients/suite-client.d.ts +5 -0
  99. package/dist/clients/suite-client.js +5 -0
  100. package/dist/clients/suite-client.js.map +1 -0
  101. package/dist/concurrency/lock-manager.d.ts +4 -0
  102. package/dist/concurrency/lock-manager.js +23 -0
  103. package/dist/concurrency/lock-manager.js.map +1 -0
  104. package/dist/config/load-config.d.ts +2 -0
  105. package/dist/config/load-config.js +18 -0
  106. package/dist/config/load-config.js.map +1 -0
  107. package/dist/config/schema.d.ts +24 -0
  108. package/dist/config/schema.js +85 -0
  109. package/dist/config/schema.js.map +1 -0
  110. package/dist/errors/fintax-error.d.ts +24 -0
  111. package/dist/errors/fintax-error.js +21 -0
  112. package/dist/errors/fintax-error.js.map +1 -0
  113. package/dist/errors/normalize-error.d.ts +3 -0
  114. package/dist/errors/normalize-error.js +67 -0
  115. package/dist/errors/normalize-error.js.map +1 -0
  116. package/dist/files/artifact-store.d.ts +17 -0
  117. package/dist/files/artifact-store.js +74 -0
  118. package/dist/files/artifact-store.js.map +1 -0
  119. package/dist/files/input-policy.d.ts +28 -0
  120. package/dist/files/input-policy.js +109 -0
  121. package/dist/files/input-policy.js.map +1 -0
  122. package/dist/files/roots-provider.d.ts +14 -0
  123. package/dist/files/roots-provider.js +47 -0
  124. package/dist/files/roots-provider.js.map +1 -0
  125. package/dist/index.d.ts +2 -0
  126. package/dist/index.js +49 -0
  127. package/dist/index.js.map +1 -0
  128. package/dist/logging/logger.d.ts +3 -0
  129. package/dist/logging/logger.js +13 -0
  130. package/dist/logging/logger.js.map +1 -0
  131. package/dist/policies/idempotency.d.ts +32 -0
  132. package/dist/policies/idempotency.js +155 -0
  133. package/dist/policies/idempotency.js.map +1 -0
  134. package/dist/policies/job-reference.d.ts +16 -0
  135. package/dist/policies/job-reference.js +62 -0
  136. package/dist/policies/job-reference.js.map +1 -0
  137. package/dist/policies/operation-plan.d.ts +27 -0
  138. package/dist/policies/operation-plan.js +99 -0
  139. package/dist/policies/operation-plan.js.map +1 -0
  140. package/dist/policies/redaction.d.ts +2 -0
  141. package/dist/policies/redaction.js +29 -0
  142. package/dist/policies/redaction.js.map +1 -0
  143. package/dist/policies/retry.d.ts +8 -0
  144. package/dist/policies/retry.js +19 -0
  145. package/dist/policies/retry.js.map +1 -0
  146. package/dist/responses/tool-response.d.ts +4 -0
  147. package/dist/responses/tool-response.js +24 -0
  148. package/dist/responses/tool-response.js.map +1 -0
  149. package/dist/schemas/common.d.ts +226 -0
  150. package/dist/schemas/common.js +133 -0
  151. package/dist/schemas/common.js.map +1 -0
  152. package/dist/schemas/domains/accounting-balances.d.ts +497 -0
  153. package/dist/schemas/domains/accounting-balances.js +226 -0
  154. package/dist/schemas/domains/accounting-balances.js.map +1 -0
  155. package/dist/schemas/domains/accounting-context.d.ts +118 -0
  156. package/dist/schemas/domains/accounting-context.js +54 -0
  157. package/dist/schemas/domains/accounting-context.js.map +1 -0
  158. package/dist/schemas/domains/assets.d.ts +2508 -0
  159. package/dist/schemas/domains/assets.js +960 -0
  160. package/dist/schemas/domains/assets.js.map +1 -0
  161. package/dist/schemas/domains/business-documents.d.ts +4406 -0
  162. package/dist/schemas/domains/business-documents.js +1153 -0
  163. package/dist/schemas/domains/business-documents.js.map +1 -0
  164. package/dist/schemas/domains/configuration.d.ts +518 -0
  165. package/dist/schemas/domains/configuration.js +504 -0
  166. package/dist/schemas/domains/configuration.js.map +1 -0
  167. package/dist/schemas/domains/dashboard.d.ts +339 -0
  168. package/dist/schemas/domains/dashboard.js +211 -0
  169. package/dist/schemas/domains/dashboard.js.map +1 -0
  170. package/dist/schemas/domains/extended-operation-results.d.ts +1588 -0
  171. package/dist/schemas/domains/extended-operation-results.js +275 -0
  172. package/dist/schemas/domains/extended-operation-results.js.map +1 -0
  173. package/dist/schemas/domains/extended-operations.d.ts +1061 -0
  174. package/dist/schemas/domains/extended-operations.js +567 -0
  175. package/dist/schemas/domains/extended-operations.js.map +1 -0
  176. package/dist/schemas/domains/extended-query-results.d.ts +1688 -0
  177. package/dist/schemas/domains/extended-query-results.js +337 -0
  178. package/dist/schemas/domains/extended-query-results.js.map +1 -0
  179. package/dist/schemas/domains/financial-reports.d.ts +540 -0
  180. package/dist/schemas/domains/financial-reports.js +206 -0
  181. package/dist/schemas/domains/financial-reports.js.map +1 -0
  182. package/dist/schemas/domains/fnd-import.d.ts +912 -0
  183. package/dist/schemas/domains/fnd-import.js +396 -0
  184. package/dist/schemas/domains/fnd-import.js.map +1 -0
  185. package/dist/schemas/domains/fund-accounts.d.ts +1092 -0
  186. package/dist/schemas/domains/fund-accounts.js +410 -0
  187. package/dist/schemas/domains/fund-accounts.js.map +1 -0
  188. package/dist/schemas/domains/fund-balances.d.ts +476 -0
  189. package/dist/schemas/domains/fund-balances.js +233 -0
  190. package/dist/schemas/domains/fund-balances.js.map +1 -0
  191. package/dist/schemas/domains/journals.d.ts +1619 -0
  192. package/dist/schemas/domains/journals.js +615 -0
  193. package/dist/schemas/domains/journals.js.map +1 -0
  194. package/dist/schemas/domains/master-data.d.ts +2010 -0
  195. package/dist/schemas/domains/master-data.js +799 -0
  196. package/dist/schemas/domains/master-data.js.map +1 -0
  197. package/dist/schemas/domains/pnl.d.ts +837 -0
  198. package/dist/schemas/domains/pnl.js +469 -0
  199. package/dist/schemas/domains/pnl.js.map +1 -0
  200. package/dist/schemas/domains/reference-data.d.ts +227 -0
  201. package/dist/schemas/domains/reference-data.js +144 -0
  202. package/dist/schemas/domains/reference-data.js.map +1 -0
  203. package/dist/schemas/domains/transaction-drafts.d.ts +903 -0
  204. package/dist/schemas/domains/transaction-drafts.js +242 -0
  205. package/dist/schemas/domains/transaction-drafts.js.map +1 -0
  206. package/dist/schemas/domains/transactions.d.ts +910 -0
  207. package/dist/schemas/domains/transactions.js +266 -0
  208. package/dist/schemas/domains/transactions.js.map +1 -0
  209. package/dist/schemas/primitives.d.ts +6 -0
  210. package/dist/schemas/primitives.js +11 -0
  211. package/dist/schemas/primitives.js.map +1 -0
  212. package/dist/schemas/public-input.d.ts +3 -0
  213. package/dist/schemas/public-input.js +524 -0
  214. package/dist/schemas/public-input.js.map +1 -0
  215. package/dist/tools/core-edit/idempotent-write.d.ts +23 -0
  216. package/dist/tools/core-edit/idempotent-write.js +58 -0
  217. package/dist/tools/core-edit/idempotent-write.js.map +1 -0
  218. package/dist/tools/core-edit/save-asset.d.ts +5 -0
  219. package/dist/tools/core-edit/save-asset.js +334 -0
  220. package/dist/tools/core-edit/save-asset.js.map +1 -0
  221. package/dist/tools/core-edit/save-business-document-draft.d.ts +2 -0
  222. package/dist/tools/core-edit/save-business-document-draft.js +128 -0
  223. package/dist/tools/core-edit/save-business-document-draft.js.map +1 -0
  224. package/dist/tools/core-edit/save-fund-account.d.ts +2 -0
  225. package/dist/tools/core-edit/save-fund-account.js +138 -0
  226. package/dist/tools/core-edit/save-fund-account.js.map +1 -0
  227. package/dist/tools/core-edit/save-journal-draft.d.ts +2 -0
  228. package/dist/tools/core-edit/save-journal-draft.js +122 -0
  229. package/dist/tools/core-edit/save-journal-draft.js.map +1 -0
  230. package/dist/tools/core-edit/save-master-data.d.ts +2 -0
  231. package/dist/tools/core-edit/save-master-data.js +153 -0
  232. package/dist/tools/core-edit/save-master-data.js.map +1 -0
  233. package/dist/tools/core-edit/save-transaction-draft.d.ts +2 -0
  234. package/dist/tools/core-edit/save-transaction-draft.js +128 -0
  235. package/dist/tools/core-edit/save-transaction-draft.js.map +1 -0
  236. package/dist/tools/core-read/export-business-documents.d.ts +2 -0
  237. package/dist/tools/core-read/export-business-documents.js +67 -0
  238. package/dist/tools/core-read/export-business-documents.js.map +1 -0
  239. package/dist/tools/core-read/export-journals.d.ts +2 -0
  240. package/dist/tools/core-read/export-journals.js +56 -0
  241. package/dist/tools/core-read/export-journals.js.map +1 -0
  242. package/dist/tools/core-read/export-transactions.d.ts +2 -0
  243. package/dist/tools/core-read/export-transactions.js +67 -0
  244. package/dist/tools/core-read/export-transactions.js.map +1 -0
  245. package/dist/tools/core-read/query-accounting-balances.d.ts +2 -0
  246. package/dist/tools/core-read/query-accounting-balances.js +135 -0
  247. package/dist/tools/core-read/query-accounting-balances.js.map +1 -0
  248. package/dist/tools/core-read/query-accounting-context.d.ts +2 -0
  249. package/dist/tools/core-read/query-accounting-context.js +76 -0
  250. package/dist/tools/core-read/query-accounting-context.js.map +1 -0
  251. package/dist/tools/core-read/query-assets.d.ts +2 -0
  252. package/dist/tools/core-read/query-assets.js +425 -0
  253. package/dist/tools/core-read/query-assets.js.map +1 -0
  254. package/dist/tools/core-read/query-business-documents.d.ts +9 -0
  255. package/dist/tools/core-read/query-business-documents.js +620 -0
  256. package/dist/tools/core-read/query-business-documents.js.map +1 -0
  257. package/dist/tools/core-read/query-dashboard.d.ts +2 -0
  258. package/dist/tools/core-read/query-dashboard.js +144 -0
  259. package/dist/tools/core-read/query-dashboard.js.map +1 -0
  260. package/dist/tools/core-read/query-financial-reports.d.ts +2 -0
  261. package/dist/tools/core-read/query-financial-reports.js +171 -0
  262. package/dist/tools/core-read/query-financial-reports.js.map +1 -0
  263. package/dist/tools/core-read/query-fund-accounts.d.ts +2 -0
  264. package/dist/tools/core-read/query-fund-accounts.js +140 -0
  265. package/dist/tools/core-read/query-fund-accounts.js.map +1 -0
  266. package/dist/tools/core-read/query-fund-balances.d.ts +2 -0
  267. package/dist/tools/core-read/query-fund-balances.js +150 -0
  268. package/dist/tools/core-read/query-fund-balances.js.map +1 -0
  269. package/dist/tools/core-read/query-journals.d.ts +2 -0
  270. package/dist/tools/core-read/query-journals.js +277 -0
  271. package/dist/tools/core-read/query-journals.js.map +1 -0
  272. package/dist/tools/core-read/query-master-data.d.ts +2 -0
  273. package/dist/tools/core-read/query-master-data.js +363 -0
  274. package/dist/tools/core-read/query-master-data.js.map +1 -0
  275. package/dist/tools/core-read/query-pnl.d.ts +2 -0
  276. package/dist/tools/core-read/query-pnl.js +244 -0
  277. package/dist/tools/core-read/query-pnl.js.map +1 -0
  278. package/dist/tools/core-read/query-reference-data.d.ts +2 -0
  279. package/dist/tools/core-read/query-reference-data.js +293 -0
  280. package/dist/tools/core-read/query-reference-data.js.map +1 -0
  281. package/dist/tools/core-read/query-transactions.d.ts +2 -0
  282. package/dist/tools/core-read/query-transactions.js +58 -0
  283. package/dist/tools/core-read/query-transactions.js.map +1 -0
  284. package/dist/tools/create-tools.d.ts +3 -0
  285. package/dist/tools/create-tools.js +88 -0
  286. package/dist/tools/create-tools.js.map +1 -0
  287. package/dist/tools/extended/asset-operation-tools.d.ts +9 -0
  288. package/dist/tools/extended/asset-operation-tools.js +419 -0
  289. package/dist/tools/extended/asset-operation-tools.js.map +1 -0
  290. package/dist/tools/extended/automation-tools.d.ts +7 -0
  291. package/dist/tools/extended/automation-tools.js +333 -0
  292. package/dist/tools/extended/automation-tools.js.map +1 -0
  293. package/dist/tools/extended/configuration-tools.d.ts +14 -0
  294. package/dist/tools/extended/configuration-tools.js +871 -0
  295. package/dist/tools/extended/configuration-tools.js.map +1 -0
  296. package/dist/tools/extended/period-end-tools.d.ts +11 -0
  297. package/dist/tools/extended/period-end-tools.js +480 -0
  298. package/dist/tools/extended/period-end-tools.js.map +1 -0
  299. package/dist/tools/extended/query-output.d.ts +2589 -0
  300. package/dist/tools/extended/query-output.js +610 -0
  301. package/dist/tools/extended/query-output.js.map +1 -0
  302. package/dist/tools/extended/tool-support.d.ts +56 -0
  303. package/dist/tools/extended/tool-support.js +198 -0
  304. package/dist/tools/extended/tool-support.js.map +1 -0
  305. package/dist/tools/extended/workflow-tools.d.ts +10 -0
  306. package/dist/tools/extended/workflow-tools.js +678 -0
  307. package/dist/tools/extended/workflow-tools.js.map +1 -0
  308. package/dist/tools/fnd-import/execute-import.d.ts +2 -0
  309. package/dist/tools/fnd-import/execute-import.js +201 -0
  310. package/dist/tools/fnd-import/execute-import.js.map +1 -0
  311. package/dist/tools/fnd-import/get-import-template.d.ts +2 -0
  312. package/dist/tools/fnd-import/get-import-template.js +66 -0
  313. package/dist/tools/fnd-import/get-import-template.js.map +1 -0
  314. package/dist/tools/fnd-import/get-job-status.d.ts +8 -0
  315. package/dist/tools/fnd-import/get-job-status.js +201 -0
  316. package/dist/tools/fnd-import/get-job-status.js.map +1 -0
  317. package/dist/tools/fnd-import/prepare-import.d.ts +31 -0
  318. package/dist/tools/fnd-import/prepare-import.js +214 -0
  319. package/dist/tools/fnd-import/prepare-import.js.map +1 -0
  320. package/dist/tools/fnd-import/public-import-result.d.ts +18 -0
  321. package/dist/tools/fnd-import/public-import-result.js +35 -0
  322. package/dist/tools/fnd-import/public-import-result.js.map +1 -0
  323. package/dist/tools/tool-definition.d.ts +45 -0
  324. package/dist/tools/tool-definition.js +11 -0
  325. package/dist/tools/tool-definition.js.map +1 -0
  326. package/dist/tools/tool-handler.d.ts +27 -0
  327. package/dist/tools/tool-handler.js +196 -0
  328. package/dist/tools/tool-handler.js.map +1 -0
  329. package/dist/tools/transaction-item.d.ts +225 -0
  330. package/dist/tools/transaction-item.js +109 -0
  331. package/dist/tools/transaction-item.js.map +1 -0
  332. package/dist/transport/draining-transport.d.ts +14 -0
  333. package/dist/transport/draining-transport.js +36 -0
  334. package/dist/transport/draining-transport.js.map +1 -0
  335. package/dist/transport/stdio.d.ts +2 -0
  336. package/dist/transport/stdio.js +5 -0
  337. package/dist/transport/stdio.js.map +1 -0
  338. package/dist/version.d.ts +2 -0
  339. package/dist/version.js +3 -0
  340. package/dist/version.js.map +1 -0
  341. package/package.json +49 -0
package/README.md ADDED
@@ -0,0 +1,220 @@
1
+ # FinTax MCP
2
+
3
+ FinTax MCP is a local Model Context Protocol server for FinTax accounting and finance workflows. It uses the official TypeScript MCP SDK and exposes a stdio transport: the MCP host starts the process, sends JSON-RPC on stdin, and reads JSON-RPC from stdout.
4
+
5
+ ## Install for an MCP client
6
+
7
+ FinTax MCP is installed as a local stdio process. The published npm package is
8
+ the standard installation method; the MCP client starts its `fintax-mcp`
9
+ command through `npx`.
10
+
11
+ ### npm or npx package
12
+
13
+ Run the published package without cloning the source repository:
14
+
15
+ ```bash
16
+ npx --yes --package @taxdao/fintax-mcp@0.2.0 fintax-mcp
17
+ ```
18
+
19
+ Use `@taxdao/fintax-mcp` without a version when the client should follow the
20
+ latest published release. For a private registry, configure npm authentication
21
+ and the registry in the client environment before starting the command.
22
+
23
+ ### Prebuilt TGZ package
24
+
25
+ For a fixed local archive, place the `.tgz` file on the client machine and
26
+ pass its absolute path to `npx`. The package does not need to be unpacked or
27
+ compiled:
28
+
29
+ ```bash
30
+ npx --yes --package /path/to/fintax-mcp-0.2.0.tgz fintax-mcp
31
+ ```
32
+
33
+ Inject the gateway URL and dedicated MCP credentials through the client's
34
+ protected environment configuration. The project does not load `.env` files
35
+ automatically:
36
+
37
+ ```text
38
+ FINTAX_API_URL=https://your-fintax-gateway.example
39
+ FINTAX_USERNAME=your-mcp-service-account
40
+ FINTAX_PASSWORD=your-secret
41
+ ```
42
+
43
+ For Codex, add this to `~/.codex/config.toml`:
44
+
45
+ ```toml
46
+ [mcp_servers.fintax]
47
+ command = "npx"
48
+ args = ["--yes", "--package", "@taxdao/fintax-mcp@0.2.0", "fintax-mcp"]
49
+ env_vars = ["FINTAX_API_URL", "FINTAX_USERNAME", "FINTAX_PASSWORD", "FINTAX_TOOL_PACKS"]
50
+ startup_timeout_sec = 10
51
+ tool_timeout_sec = 60
52
+ default_tools_approval_mode = "writes"
53
+ ```
54
+
55
+ For MCP clients that use the JSON `mcpServers` format, the environment can be
56
+ declared directly in the client configuration:
57
+
58
+ ```json
59
+ {
60
+ "mcpServers": {
61
+ "fintax": {
62
+ "command": "npx",
63
+ "args": ["--yes", "--package", "@taxdao/fintax-mcp@0.2.0", "fintax-mcp"],
64
+ "env": {
65
+ "FINTAX_API_URL": "https://your-fintax-gateway.example",
66
+ "FINTAX_USERNAME": "your-mcp-service-account",
67
+ "FINTAX_PASSWORD": "your-secret",
68
+ "FINTAX_TOOL_PACKS": "core-read,fnd-import,core-edit,workflow,period-end,asset-ops,automation,configuration"
69
+ }
70
+ }
71
+ }
72
+ }
73
+ ```
74
+
75
+ To use a TGZ in either configuration, replace the package specifier with the
76
+ absolute archive path, for example
77
+ `/path/to/fintax-mcp-0.2.0.tgz`. Keep configuration files containing
78
+ credentials protected by the host account.
79
+
80
+ Any MCP client that launches stdio commands can use the same `npx` command.
81
+ Restart the client, then verify the server with `codex mcp list` or the
82
+ client's MCP tools view. The default directory exposes 77 Tools; login is
83
+ deferred until the first protected business call.
84
+
85
+ ## Features
86
+
87
+ - Read-only queries and exports for accounting, transactions, journals, documents, assets, balances, reports, master data, and profit and loss.
88
+ - FND account-transaction import with template, validation, confirmation, and job-status steps. The initial import type is `fund.account`.
89
+ - Draft writes for transactions, fund accounts, master data, journals, business documents, and assets.
90
+ - Explicit prepare/preview and execute pairs for state-changing workflows.
91
+ - Structured success results with `trace_id`, `warnings`, and `source_refs`.
92
+ - Normalized public errors without credentials, stack traces, or raw upstream error text.
93
+ - Static Tool registration at startup. `tools/list` does not require login; authentication starts only for a protected business call.
94
+
95
+ ## Architecture
96
+
97
+ ```text
98
+ MCP host
99
+ | JSON-RPC over stdin/stdout
100
+ v
101
+ MCP SDK registration
102
+ v
103
+ ToolDefinition and public Schema
104
+ v
105
+ FinTaxToolHandler
106
+ | validation, auth, organization scope, files, plans,
107
+ | idempotency, output validation, errors, and audit
108
+ v
109
+ Capability registry and operation adapter
110
+ v
111
+ Base/Suite HTTP client
112
+ ```
113
+
114
+ ## Tool directory
115
+
116
+ The default startup directory contains 77 Tools across eight fixed packs:
117
+
118
+ | Pack | Count | Scope |
119
+ | --------------- | ----: | ---------------------------------------------------------------------- |
120
+ | `core-read` | 24 | Queries, exports, reference data, and `get_job_status` |
121
+ | `fnd-import` | 3 | Account-import template, validation, and execution |
122
+ | `core-edit` | 9 | Transaction, account, master-data, journal, document, and asset drafts |
123
+ | `workflow` | 8 | Submission, posting, offset candidates, preview, and execution |
124
+ | `period-end` | 9 | Period status, revaluation, close, reconciliation, and reverse close |
125
+ | `asset-ops` | 7 | Depreciation, cost adjustment, impairment, and retirement |
126
+ | `automation` | 5 | Accounting events and accounting-flow execution |
127
+ | `configuration` | 12 | Mapping, rules, allocations, P&L, and generator configuration |
128
+
129
+ Enabled Tools are listed by `tools/list`. The following operations are not exposed: generic `call_api`, dynamic OpenAPI Tools, database access, arbitrary code execution, unsupported import types, hard delete, reversal, unplanned depreciation, `collectAndPost`, and `sync_fund_account`.
130
+
131
+ ## Requirements
132
+
133
+ - Node.js 24 LTS (`>=24 <27`)
134
+ - npm and npx supplied with Node.js
135
+ - pnpm 11 or newer for source builds and tests
136
+ - A FinTax gateway that routes authentication, system, and business APIs
137
+ - A FinTax MCP service account with the required capabilities
138
+
139
+ ## Configuration
140
+
141
+ Copy `.env.example` as a variable reference only. The service does not read it
142
+ by itself. MCP hosts can pass variables directly through their configuration:
143
+ use `env` in JSON-based clients and `env_vars` in Codex to forward values from
144
+ the host environment.
145
+
146
+ | Variable | Default | Purpose |
147
+ | ---------------------------- | --------------------------- | --------------------------------------------------------------- |
148
+ | `FINTAX_API_URL` | required | Unified FinTax gateway URL |
149
+ | `FINTAX_USERNAME` | required for business calls | Dedicated MCP account |
150
+ | `FINTAX_PASSWORD` | required for business calls | MCP account secret |
151
+ | `FINTAX_DEFAULT_ORG_ID` | empty | Reserved; never replaces explicit write context |
152
+ | `FINTAX_TOOL_PACKS` | all eight packs | Comma-separated fixed startup directory |
153
+ | `FINTAX_ALLOWED_IMPORT_DIRS` | empty | Absolute directories allowed for `local_path` imports |
154
+ | `FINTAX_ARTIFACT_DIR` | `./var/artifacts` | Temporary templates and export artifacts |
155
+ | `FINTAX_AUDIT_DIR` | `./var/audit` | Structured JSONL audit records |
156
+ | `FINTAX_LOG_LEVEL` | `info` | `fatal`, `error`, `warn`, `info`, `debug`, `trace`, or `silent` |
157
+ | `FINTAX_REQUEST_TIMEOUT_MS` | `10000` | Per-request upstream timeout |
158
+ | `FINTAX_SHUTDOWN_TIMEOUT_MS` | `5000` | Bounded shutdown timeout |
159
+ | `FINTAX_MAX_FILE_BYTES` | `26214400` | Maximum import file size |
160
+
161
+ `FINTAX_TOOL_PACKS` is parsed once at startup. Unknown packs, an empty list, or unmet dependencies make startup fail. Tool discovery remains stable for the process lifetime. Missing API credentials do not prevent `initialize` or `tools/list`; a protected call returns structured `AUTH_REQUIRED`.
162
+
163
+ `FINTAX_ARTIFACT_DIR` and `FINTAX_AUDIT_DIR` use paths relative to the MCP
164
+ process working directory unless absolute paths are configured. Set absolute
165
+ paths when artifacts or audit records must remain in stable locations. A
166
+ `cwd` setting is not required for `.tgz` installation.
167
+
168
+ Declare MCP roots when sending a local import path; without roots, arbitrary
169
+ `local_path` inputs are rejected.
170
+
171
+ ## Safe call patterns
172
+
173
+ 1. Call `query_accounting_context` first when a Tool needs an organization or ledger. Use only IDs returned by that Tool.
174
+ 2. Every multi-organization write must include `context.org_id`. Every draft write requires a caller-generated UUID `idempotency_key`.
175
+ 3. Read the current object and `version` before an update.
176
+ 4. For prepare/preview and execute pairs, show the impact summary and obtain explicit confirmation before execution.
177
+ 5. Never retry POST, import confirmation, posting, close, or other state-changing calls automatically. On timeout, follow the read-only recovery Tool.
178
+ 6. Amounts are decimal strings. Do not send JSON floating-point values for financial amounts.
179
+
180
+ ## Import flow
181
+
182
+ The initial import flow supports only `import_type=fund.account`:
183
+
184
+ ```text
185
+ get_import_template
186
+ |
187
+ prepare_import -> validation, operation plan, confirmation token
188
+ |
189
+ explicit user confirmation
190
+ |
191
+ execute_import -> job_id
192
+ |
193
+ get_job_status -> progress and terminal result
194
+ ```
195
+
196
+ `prepare_import` creates an upstream validation batch but does not import business data. A confirmation token is short-lived and single-use. If execution times out, query the job reference and do not retry with a new idempotency key.
197
+
198
+ ## Runtime behavior
199
+
200
+ - stdout contains only MCP JSON-RPC; logs go to stderr and audit records go to the configured audit directory.
201
+ - Local files must pass realpath, server allowlist, regular-file, type, size, and MCP-root checks.
202
+ - POST operations are not automatically retried; read-only GET retries are bounded.
203
+ - Confirmation tokens and operation plans are opaque, short-lived, single-use handles and are excluded from logs, audit, errors, and execution results.
204
+ - Public errors never include passwords, cookies, access tokens, stack traces, raw upstream responses, or complete financial line items.
205
+
206
+ ## Diagnostics
207
+
208
+ ```bash
209
+ pnpm build
210
+ pnpm dlx @modelcontextprotocol/inspector@2.2.0 \
211
+ --cli node dist/index.js \
212
+ --method tools/list \
213
+ --format json
214
+ ```
215
+
216
+ ```bash
217
+ FINTAX_RUN_INTEGRATION=1 pnpm test:integration
218
+ ```
219
+
220
+ The integration suite discovers organization and ledger IDs through `query_accounting_context`, runs read-only checks and exports, and does not execute imports.
@@ -0,0 +1,18 @@
1
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ import type { Logger } from 'pino';
3
+ import type { AuditSink } from '../audit/audit-sink.js';
4
+ import type { CapabilityDefinition } from '../capabilities/capability.js';
5
+ import type { RuntimeConfig } from '../config/schema.js';
6
+ export interface Application {
7
+ readonly server: McpServer;
8
+ close(): Promise<void>;
9
+ }
10
+ export interface ApplicationOptions {
11
+ readonly config?: RuntimeConfig;
12
+ readonly fetch?: typeof fetch;
13
+ readonly auditSink?: AuditSink;
14
+ readonly logger?: Logger;
15
+ readonly capabilities?: readonly CapabilityDefinition[];
16
+ }
17
+ export declare function createApplication(options?: ApplicationOptions): Application;
18
+ export declare function createServer(options?: ApplicationOptions): McpServer;
@@ -0,0 +1,80 @@
1
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ import { FileAuditSink } from '../audit/file-audit-sink.js';
3
+ import { CapabilityExecutor } from '../capabilities/executor.js';
4
+ import { createCapabilities } from '../capabilities/create-capabilities.js';
5
+ import { CapabilityRegistry } from '../capabilities/registry.js';
6
+ import { loadConfig } from '../config/load-config.js';
7
+ import { LockManager } from '../concurrency/lock-manager.js';
8
+ import { ArtifactStore } from '../files/artifact-store.js';
9
+ import { InputFilePolicy } from '../files/input-policy.js';
10
+ import { McpRootsProvider } from '../files/roots-provider.js';
11
+ import { createLogger } from '../logging/logger.js';
12
+ import { OperationPlanManager } from '../policies/operation-plan.js';
13
+ import { IdempotencyManager } from '../policies/idempotency.js';
14
+ import { createTools } from '../tools/create-tools.js';
15
+ import { FinTaxToolHandler } from '../tools/tool-handler.js';
16
+ import { DrainingTransport } from '../transport/draining-transport.js';
17
+ import { SERVER_NAME, SERVER_VERSION } from '../version.js';
18
+ import { registerTools } from './register-tools.js';
19
+ class ApplicationMcpServer extends McpServer {
20
+ #transport;
21
+ async connect(transport) {
22
+ const drainingTransport = new DrainingTransport(transport);
23
+ this.#transport = drainingTransport;
24
+ try {
25
+ await super.connect(drainingTransport);
26
+ }
27
+ catch (error) {
28
+ this.#transport = undefined;
29
+ throw error;
30
+ }
31
+ }
32
+ drainTransport() {
33
+ return this.#transport?.drain() ?? Promise.resolve();
34
+ }
35
+ }
36
+ export function createApplication(options = {}) {
37
+ const config = options.config ?? loadConfig();
38
+ const server = new ApplicationMcpServer({
39
+ name: SERVER_NAME,
40
+ version: SERVER_VERSION,
41
+ });
42
+ const locks = new LockManager();
43
+ const artifacts = new ArtifactStore(config.FINTAX_ARTIFACT_DIR);
44
+ const capabilities = new CapabilityExecutor({
45
+ config,
46
+ registry: new CapabilityRegistry(options.capabilities ?? createCapabilities()),
47
+ locks,
48
+ ...(options.fetch === undefined ? {} : { fetch: options.fetch }),
49
+ });
50
+ const handler = new FinTaxToolHandler({
51
+ capabilities,
52
+ files: new InputFilePolicy({
53
+ allowedDirectories: config.FINTAX_ALLOWED_IMPORT_DIRS,
54
+ maxBytes: config.FINTAX_MAX_FILE_BYTES,
55
+ roots: new McpRootsProvider(server),
56
+ artifacts,
57
+ }),
58
+ artifacts,
59
+ plans: new OperationPlanManager(locks),
60
+ idempotency: new IdempotencyManager(locks),
61
+ locks,
62
+ audit: options.auditSink ?? new FileAuditSink(config.FINTAX_AUDIT_DIR),
63
+ logger: options.logger ?? createLogger(config),
64
+ });
65
+ registerTools(server, createTools(config.FINTAX_TOOL_PACKS), handler);
66
+ return {
67
+ server,
68
+ async close() {
69
+ handler.stopAccepting();
70
+ await handler.drain();
71
+ await server.drainTransport();
72
+ await server.close();
73
+ await handler.close();
74
+ },
75
+ };
76
+ }
77
+ export function createServer(options = {}) {
78
+ return createApplication(options).server;
79
+ }
80
+ //# sourceMappingURL=create-server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-server.js","sourceRoot":"","sources":["../../src/app/create-server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAIpE,O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AC,SAAS,IAAI,IAAI,aAAa,CAAC,MAAM,CAAC,gBAAgB,CAAC;QACtE,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,YAAY,CAAC,MAAM,CAAC;KAC/C,CAAC,CAAC;IAEH,aAAa,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,iBAAiB,CAAC,EAAE,OAAO,CAAC,CAAC;IACtE,OAAO;QACL,MAAM;QACN,KAAK,CAAC,KAAK;YACT,OAAO,CAAC,aAAa,EAAE,CAAC;YACxB,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC;YACtB,MAAM,MAAM,CAAC,cAAc,EAAE,CAAC;YAC9B,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;YACrB,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC;QACxB,CAAC;KACF,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,UAA8B,EAAE;IAC3D,OAAO,iBAAiB,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC;AAC3C,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ import type { ToolDefinition } from '../tools/tool-definition.js';
3
+ import type { FinTaxToolHandler } from '../tools/tool-handler.js';
4
+ export declare function registerTools(server: McpServer, definitions: readonly ToolDefinition[], handler: FinTaxToolHandler): void;
@@ -0,0 +1,18 @@
1
+ import { createSdkInputSchema } from '../schemas/public-input.js';
2
+ export function registerTools(server, definitions, handler) {
3
+ const names = new Set();
4
+ for (const definition of definitions) {
5
+ if (names.has(definition.name)) {
6
+ throw new Error(`Duplicate MCP tool name: ${definition.name}`);
7
+ }
8
+ names.add(definition.name);
9
+ server.registerTool(definition.name, {
10
+ title: definition.title,
11
+ description: `${definition.description} Risk level: ${definition.risk}. Deployment pack: ${definition.exposurePack}.`,
12
+ inputSchema: createSdkInputSchema(definition.inputSchema, definition.publicInputSchema),
13
+ outputSchema: definition.outputSchema,
14
+ annotations: definition.annotations,
15
+ }, (params) => handler.invoke(definition, params));
16
+ }
17
+ }
18
+ //# sourceMappingURL=register-tools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register-tools.js","sourceRoot":"","sources":["../../src/app/register-tools.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAIlE,MAAM,UAAU,aAAa,CAC3B,MAAiB,EACjB,WAAsC,EACtC,OAA0B;IAE1B,MAAM,KAAK,GAAG,IAAI,GAAG,EAAU,CAAC;IAEhC,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE,CAAC;QACrC,IAAI,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;YAC/B,MAAM,IAAI,KAAK,CAAC,4BAA4B,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC;QACjE,CAAC;QACD,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QAE3B,MAAM,CAAC,YAAY,CACjB,UAAU,CAAC,IAAI,EACf;YACE,KAAK,EAAE,UAAU,CAAC,KAAK;YACvB,WAAW,EAAE,GAAG,UAAU,CAAC,WAAW,gBAAgB,UAAU,CAAC,IAAI,sBAAsB,UAAU,CAAC,YAAY,GAAG;YACrH,WAAW,EAAE,oBAAoB,CAC/B,UAAU,CAAC,WAAW,EACtB,UAAU,CAAC,iBAAiB,CAC7B;YACD,YAAY,EAAE,UAAU,CAAC,YAAY;YACrC,WAAW,EAAE,UAAU,CAAC,WAAW;SACpC,EACD,CAAC,MAAM,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,CAC/C,CAAC;IACJ,CAAC;AACH,CAAC"}
@@ -0,0 +1,38 @@
1
+ import type { AuthIdentity } from '../auth/auth-session.js';
2
+ import type { HttpMethod, ServiceName } from '../capabilities/capability.js';
3
+ export interface AuditSummary {
4
+ readonly digest: string;
5
+ readonly fields: readonly string[];
6
+ }
7
+ export interface AuditActor {
8
+ readonly userId?: string;
9
+ readonly tenantId?: string;
10
+ readonly orgId?: string;
11
+ }
12
+ export interface UpstreamAuditCall {
13
+ readonly service: ServiceName;
14
+ readonly operation: string;
15
+ readonly method: HttpMethod;
16
+ readonly outcome: 'succeeded' | 'failed';
17
+ readonly statusCodes: readonly number[];
18
+ }
19
+ export interface AuditSnapshot {
20
+ readonly actor?: AuditActor;
21
+ readonly targetObjectIds?: Readonly<Record<string, readonly string[]>>;
22
+ readonly filterSummary?: AuditSummary;
23
+ readonly fileChecksums?: readonly string[];
24
+ readonly operationPlanSummary?: string;
25
+ readonly idempotencyKeySummary?: string;
26
+ readonly idempotencyOutcome?: 'started' | 'replayed' | 'failed';
27
+ readonly upstreamCalls?: readonly UpstreamAuditCall[];
28
+ }
29
+ export declare class AuditContext {
30
+ #private;
31
+ captureInput(input: unknown): void;
32
+ captureIdentity(identity: AuthIdentity): void;
33
+ captureTargetObjectId(field: string, value: string): void;
34
+ captureFileChecksum(checksum: string): void;
35
+ captureIdempotencyOutcome(outcome: NonNullable<AuditSnapshot['idempotencyOutcome']>): void;
36
+ recordUpstreamCall(call: UpstreamAuditCall): void;
37
+ snapshot(): AuditSnapshot;
38
+ }
@@ -0,0 +1,167 @@
1
+ import { hashOperationValue } from '../policies/operation-plan.js';
2
+ const SECRET_FIELDS = new Set([
3
+ 'confirmation_token',
4
+ 'idempotency_key',
5
+ 'operation_plan_id',
6
+ ]);
7
+ const REFERENCE_FIELDS = new Set(['file_ref']);
8
+ const OMITTED_FIELDS = new Set(['file_content', 'lines', 'raw_file']);
9
+ const NON_TARGET_IDS = new Set(['org_id', 'tenant_id', 'user_id']);
10
+ function digest(namespace, value) {
11
+ return hashOperationValue({ namespace, value });
12
+ }
13
+ function isTargetIdField(key) {
14
+ return (!NON_TARGET_IDS.has(key) &&
15
+ (key === 'id' || key.endsWith('_id') || key.endsWith('_ids')));
16
+ }
17
+ function summarizeInput(input) {
18
+ const fields = new Set();
19
+ const targetObjectIds = new Map();
20
+ const visit = (value, path) => {
21
+ if (Array.isArray(value)) {
22
+ return value.map((entry, index) => visit(entry, [...path, String(index)]));
23
+ }
24
+ if (value === null || typeof value !== 'object') {
25
+ if (path.length > 0)
26
+ fields.add(path.join('.'));
27
+ return value;
28
+ }
29
+ return Object.fromEntries(Object.entries(value).map(([key, entry]) => {
30
+ const nextPath = [...path, key];
31
+ if (SECRET_FIELDS.has(key)) {
32
+ fields.add(nextPath.join('.'));
33
+ return [key, '[REDACTED]'];
34
+ }
35
+ if (REFERENCE_FIELDS.has(key)) {
36
+ fields.add(nextPath.join('.'));
37
+ const kind = entry !== null &&
38
+ typeof entry === 'object' &&
39
+ 'kind' in entry &&
40
+ typeof entry.kind === 'string'
41
+ ? entry.kind
42
+ : 'unknown';
43
+ return [key, { kind, value: '[REFERENCE]' }];
44
+ }
45
+ if (OMITTED_FIELDS.has(key)) {
46
+ fields.add(nextPath.join('.'));
47
+ return [key, '[OMITTED]'];
48
+ }
49
+ if (isTargetIdField(key)) {
50
+ const values = Array.isArray(entry) ? entry : [entry];
51
+ const ids = targetObjectIds.get(key) ?? new Set();
52
+ for (const candidate of values) {
53
+ if (typeof candidate === 'string')
54
+ ids.add(candidate);
55
+ }
56
+ if (ids.size > 0)
57
+ targetObjectIds.set(key, ids);
58
+ }
59
+ return [key, visit(entry, nextPath)];
60
+ }));
61
+ };
62
+ const summarized = visit(input, []);
63
+ return {
64
+ value: summarized,
65
+ fields: [...fields].sort(),
66
+ targetObjectIds: new Map([...targetObjectIds].map(([key, values]) => [key, [...values].sort()])),
67
+ };
68
+ }
69
+ export class AuditContext {
70
+ #actor;
71
+ #filterSummary;
72
+ #operationPlanSummary;
73
+ #idempotencyKeySummary;
74
+ #idempotencyOutcome;
75
+ #targetObjectIds = new Map();
76
+ #fileChecksums = new Set();
77
+ #upstreamCalls = [];
78
+ captureInput(input) {
79
+ const summarized = summarizeInput(input);
80
+ this.#filterSummary = {
81
+ digest: digest('tool-input', summarized.value),
82
+ fields: summarized.fields,
83
+ };
84
+ for (const [field, values] of summarized.targetObjectIds) {
85
+ for (const value of values)
86
+ this.captureTargetObjectId(field, value);
87
+ }
88
+ if (input === null || typeof input !== 'object')
89
+ return;
90
+ if ('operation_plan_id' in input &&
91
+ typeof input.operation_plan_id === 'string') {
92
+ this.#operationPlanSummary = digest('operation-plan', input.operation_plan_id);
93
+ }
94
+ if ('idempotency_key' in input &&
95
+ typeof input.idempotency_key === 'string') {
96
+ this.#idempotencyKeySummary = digest('idempotency-key', input.idempotency_key);
97
+ }
98
+ if ('context' in input &&
99
+ input.context !== null &&
100
+ typeof input.context === 'object' &&
101
+ 'org_id' in input.context &&
102
+ typeof input.context.org_id === 'string') {
103
+ this.#actor = {
104
+ ...(this.#actor?.userId === undefined
105
+ ? {}
106
+ : { userId: this.#actor.userId }),
107
+ ...(this.#actor?.tenantId === undefined
108
+ ? {}
109
+ : { tenantId: this.#actor.tenantId }),
110
+ orgId: digest('actor-org', input.context.org_id),
111
+ };
112
+ }
113
+ }
114
+ captureIdentity(identity) {
115
+ this.#actor = {
116
+ userId: digest('actor-user', identity.userId),
117
+ tenantId: digest('actor-tenant', identity.tenantId),
118
+ ...(identity.orgId === undefined
119
+ ? this.#actor?.orgId === undefined
120
+ ? {}
121
+ : { orgId: this.#actor.orgId }
122
+ : { orgId: digest('actor-org', identity.orgId) }),
123
+ };
124
+ }
125
+ captureTargetObjectId(field, value) {
126
+ const values = this.#targetObjectIds.get(field) ?? new Set();
127
+ values.add(value);
128
+ this.#targetObjectIds.set(field, values);
129
+ }
130
+ captureFileChecksum(checksum) {
131
+ this.#fileChecksums.add(checksum);
132
+ }
133
+ captureIdempotencyOutcome(outcome) {
134
+ this.#idempotencyOutcome = outcome;
135
+ }
136
+ recordUpstreamCall(call) {
137
+ this.#upstreamCalls.push(call);
138
+ }
139
+ snapshot() {
140
+ const targetObjectIds = Object.fromEntries([...this.#targetObjectIds]
141
+ .sort(([left], [right]) => left.localeCompare(right))
142
+ .map(([field, values]) => [field, [...values].sort()]));
143
+ return {
144
+ ...(this.#actor === undefined ? {} : { actor: this.#actor }),
145
+ ...(Object.keys(targetObjectIds).length === 0 ? {} : { targetObjectIds }),
146
+ ...(this.#filterSummary === undefined
147
+ ? {}
148
+ : { filterSummary: this.#filterSummary }),
149
+ ...(this.#fileChecksums.size === 0
150
+ ? {}
151
+ : { fileChecksums: [...this.#fileChecksums].sort() }),
152
+ ...(this.#operationPlanSummary === undefined
153
+ ? {}
154
+ : { operationPlanSummary: this.#operationPlanSummary }),
155
+ ...(this.#idempotencyKeySummary === undefined
156
+ ? {}
157
+ : { idempotencyKeySummary: this.#idempotencyKeySummary }),
158
+ ...(this.#idempotencyOutcome === undefined
159
+ ? {}
160
+ : { idempotencyOutcome: this.#idempotencyOutcome }),
161
+ ...(this.#upstreamCalls.length === 0
162
+ ? {}
163
+ : { upstreamCalls: [...this.#upstreamCalls] }),
164
+ };
165
+ }
166
+ }
167
+ //# sourceMappingURL=audit-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit-context.js","sourceRoot":"","sources":["../../src/audit/audit-context.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAgCnE,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC;IAC5B,oBAAoB;IACpB,iBAAiB;IACjB,mBAAmB;CACpB,CAAC,CAAC;AAEH,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC;AAC/C,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,CAAC,cAAc,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC;AACtE,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,WAAW,EAAE,SAAS,CAAC,CAAC,CAAC;AAEnE,SAAS,MAAM,CAAC,SAAiB,EAAE,KAAc;IAC/C,OAAO,kBAAkB,CAAC,EAAE,SAAS,EAAE,KAAK,E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B,EAAE,CAAC;YACrD,GAAG,CAAC,IAAI,CAAC,cAAc,CAAC,MAAM,KAAK,CAAC;gBAClC,CAAC,CAAC,EAAE;gBACJ,CAAC,CAAC,EAAE,aAAa,EAAE,CAAC,GAAG,IAAI,CAAC,cAAc,CAAC,EAAE,CAAC;SACjD,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,20 @@
1
+ import type { RiskLevel } from '../tools/tool-definition.js';
2
+ import type { AuditSnapshot } from './audit-context.js';
3
+ export interface AuditRecord extends AuditSnapshot {
4
+ readonly traceId: string;
5
+ readonly tool: string;
6
+ readonly version: string;
7
+ readonly risk: RiskLevel;
8
+ readonly capabilityIds: readonly string[];
9
+ readonly startedAt: string;
10
+ readonly finishedAt: string;
11
+ readonly durationMs: number;
12
+ readonly status: 'succeeded' | 'failed';
13
+ readonly errorCode?: string;
14
+ }
15
+ export interface AuditSink {
16
+ write(record: AuditRecord): Promise<void>;
17
+ }
18
+ export declare class NullAuditSink implements AuditSink {
19
+ write(): Promise<void>;
20
+ }
@@ -0,0 +1,6 @@
1
+ export class NullAuditSink {
2
+ write() {
3
+ return Promise.resolve();
4
+ }
5
+ }
6
+ //# sourceMappingURL=audit-sink.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit-sink.js","sourceRoot":"","sources":["../../src/audit/audit-sink.ts"],"names":[],"mappings":"AAoBA,MAAM,OAAO,aAAa;IACxB,KAAK;QACH,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;CACF"}
@@ -0,0 +1,6 @@
1
+ import type { AuditRecord, AuditSink } from './audit-sink.js';
2
+ export declare class FileAuditSink implements AuditSink {
3
+ #private;
4
+ constructor(directory: string);
5
+ write(record: AuditRecord): Promise<void>;
6
+ }
@@ -0,0 +1,18 @@
1
+ import { appendFile, mkdir } from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ export class FileAuditSink {
4
+ #directory;
5
+ constructor(directory) {
6
+ this.#directory = path.resolve(directory);
7
+ }
8
+ async write(record) {
9
+ await mkdir(this.#directory, { recursive: true, mode: 0o700 });
10
+ const date = record.startedAt.slice(0, 10);
11
+ const file = path.join(this.#directory, `${date}.jsonl`);
12
+ await appendFile(file, `${JSON.stringify(record)}\n`, {
13
+ encoding: 'utf8',
14
+ mode: 0o600,
15
+ });
16
+ }
17
+ }
18
+ //# sourceMappingURL=file-audit-sink.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-audit-sink.js","sourceRoot":"","sources":["../../src/audit/file-audit-sink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,IAAI,MAAM,WAAW,CAAC;AAI7B,MAAM,OAAO,aAAa;IACf,UAAU,CAAS;IAE5B,YAAY,SAAiB;QAC3B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAC5C,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,MAAmB;QAC7B,MAAM,KAAK,CAAC,IAAI,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;QAC/D,MAAM,IAAI,GAAG,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAC3C,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,GAAG,IAAI,QAAQ,CAAC,CAAC;QACzD,MAAM,UAAU,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,EAAE;YACpD,QAAQ,EAAE,MAAM;YAChB,IAAI,EAAE,KAAK;SACZ,CAAC,CAAC;IACL,CAAC;CACF"}