@talonic/mcp 0.1.82 → 0.1.84

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.
@@ -3423,6 +3423,247 @@ function registerContractsTools(server, getToken, baseUrl) {
3423
3423
  );
3424
3424
  }
3425
3425
  }
3426
+ var readOnly2 = {
3427
+ readOnlyHint: true,
3428
+ destructiveHint: false,
3429
+ idempotentHint: true,
3430
+ openWorldHint: false
3431
+ };
3432
+ var write2 = (idempotent, destructive = false) => ({
3433
+ readOnlyHint: false,
3434
+ destructiveHint: destructive,
3435
+ idempotentHint: idempotent,
3436
+ openWorldHint: false
3437
+ });
3438
+ var OVERVIEW_DESCRIPTION = [
3439
+ "AP totals for the workspace: invoices ready to post and held (count and dollars), dollars at stake above contract, duplicates, missing PO, per entity with its system of record, and the last simulated NetSuite run.",
3440
+ 'USE WHEN: the headline ("how much is ready to post, how much is held and why").',
3441
+ "NOT FOR: the invoices themselves (talonic_ap_bills); the held worklist (talonic_ap_issues).",
3442
+ "",
3443
+ "ARGS: none.",
3444
+ "RETURNS: { as_of, currency, configured, gaps[], totals { bills, ready, held { at_stake, above_contract, duplicates, missing_po, vendor_unknown } }, entities[], sources[], last_run }."
3445
+ ].join("\n");
3446
+ function handleOverview(getToken, baseUrl) {
3447
+ return runTool(() => apiJson(getToken, baseUrl, "GET", "/v1/ap/overview"));
3448
+ }
3449
+ var BILLS_DESCRIPTION = [
3450
+ "List AP invoices as posting-ready vendor bills, each with vendor, invoice number, dates, amount (as invoiced and in the ledger currency), entity, status, holds with dollars and evidence, NetSuite mapping and lines.",
3451
+ "USE WHEN: looking up invoices by vendor or number, or listing the ready or held ones.",
3452
+ "NOT FOR: totals (talonic_ap_overview).",
3453
+ "",
3454
+ "ARGS: `status` ready|held, `entity` (entity code), `reason` above_contract|duplicate|missing_po|vendor_unknown, `query` (vendor, number, filename or contract contains), `limit` (default 500).",
3455
+ "RETURNS: { currency, total, data[] }."
3456
+ ].join("\n");
3457
+ var billsInputSchema = {
3458
+ status: z.enum(["ready", "held"]).optional().describe("Only ready or only held invoices."),
3459
+ entity: z.string().optional().describe("Entity code, e.g. 'HRL'."),
3460
+ reason: z.enum(["above_contract", "duplicate", "missing_po", "vendor_unknown"]).optional().describe("Only invoices held for this reason."),
3461
+ query: z.string().optional().describe("Vendor, invoice number, filename or contract contains."),
3462
+ limit: z.number().int().min(1).max(5e3).optional().describe("Maximum invoices returned.")
3463
+ };
3464
+ function handleBills(getToken, baseUrl, args) {
3465
+ return runTool(
3466
+ () => apiJson(getToken, baseUrl, "GET", "/v1/ap/bills", {
3467
+ params: {
3468
+ status: args.status,
3469
+ entity: args.entity,
3470
+ reason: args.reason,
3471
+ q: args.query,
3472
+ limit: args.limit
3473
+ }
3474
+ })
3475
+ );
3476
+ }
3477
+ var ISSUES_DESCRIPTION2 = [
3478
+ "The AP worklist: every held invoice, why (each hold with its reason, finding, explanation and dollars), and the dollars at stake.",
3479
+ "USE WHEN: deciding what to dispute or fix before posting.",
3480
+ "NOT FOR: invoices ready to post (talonic_ap_bills with status=ready).",
3481
+ "",
3482
+ "ARGS: none.",
3483
+ "RETURNS: { currency, data[] { key, vendor, invoice_number, entity, document_id, filename, amount, at_stake, holds[] } }."
3484
+ ].join("\n");
3485
+ function handleIssues2(getToken, baseUrl) {
3486
+ return runTool(() => apiJson(getToken, baseUrl, "GET", "/v1/ap/issues"));
3487
+ }
3488
+ var CONFIG_DESCRIPTION = [
3489
+ "Read the AP configuration: which captured document kinds are bills, the contract register used for entity and cost centre, entities with their system and NetSuite subsidiary, the NetSuite mapping (accounts, departments, terms, currencies, vendors).",
3490
+ "USE WHEN: before changing the configuration, or to explain why an invoice maps the way it does.",
3491
+ "NOT FOR: invoices (talonic_ap_bills).",
3492
+ "",
3493
+ "ARGS: none.",
3494
+ "RETURNS: { config, saved, updated_at }."
3495
+ ].join("\n");
3496
+ function handleConfig(getToken, baseUrl) {
3497
+ return runTool(() => apiJson(getToken, baseUrl, "GET", "/v1/ap/config"));
3498
+ }
3499
+ var SAVE_CONFIG_DESCRIPTION = [
3500
+ "Replace the AP configuration with a complete new one (validated by the platform). Run with dry_run first.",
3501
+ "USE WHEN: setting up AP for a workspace or changing the NetSuite mapping.",
3502
+ "NOT FOR: partial edits; read talonic_ap_config, change it, and send the whole object.",
3503
+ "",
3504
+ "ARGS: `config` (the whole configuration object), `dry_run` (validate only).",
3505
+ "RETURNS: { config, saved }. A broken config returns the list of problems."
3506
+ ].join("\n");
3507
+ var saveConfigInputSchema = {
3508
+ config: z.record(z.string(), z.unknown()).describe("The whole AP configuration object (see talonic_ap_config)."),
3509
+ dry_run: z.boolean().optional().describe("Validate only; nothing is saved.")
3510
+ };
3511
+ function handleSaveConfig(getToken, baseUrl, args) {
3512
+ return runTool(
3513
+ () => apiJson(getToken, baseUrl, "PUT", "/v1/ap/config", {
3514
+ body: { config: args.config, dry_run: args.dry_run ?? false }
3515
+ })
3516
+ );
3517
+ }
3518
+ var PREVIEW_DESCRIPTION = [
3519
+ "The exact NetSuite vendor bill records a posting would send (REST Record API `vendorBill` bodies: entity, subsidiary, tranId, tranDate, dueDate, terms, currency, expense / item sublists, memo naming the source document and page), and the invoices left out with the reason. The NetSuite target is a simulated sandbox.",
3520
+ "USE WHEN: showing or checking what would be exported to NetSuite.",
3521
+ "NOT FOR: posting (talonic_ap_netsuite_post).",
3522
+ "",
3523
+ "ARGS: `include_held` (also send held invoices, on payment hold; duplicates are never sent).",
3524
+ "RETURNS: { adapter { mode: 'simulated_sandbox' }, records[] { bill_key, method, path, body }, skipped[], totals }."
3525
+ ].join("\n");
3526
+ var previewInputSchema = {
3527
+ include_held: z.boolean().optional().describe("Send held invoices too, with paymentHold true.")
3528
+ };
3529
+ function handlePreview(getToken, baseUrl, args) {
3530
+ return runTool(
3531
+ () => apiJson(getToken, baseUrl, "GET", "/v1/ap/netsuite/preview", {
3532
+ params: { include_held: args.include_held ? 1 : 0 }
3533
+ })
3534
+ );
3535
+ }
3536
+ var POST_DESCRIPTION = [
3537
+ "Post the vendor bills to the SIMULATED NetSuite sandbox: each record is answered as NetSuite's REST API answers a created record (204 with the new internal id), and the run's posting log is kept. Nothing is sent to any NetSuite account; say so when reporting the result.",
3538
+ "USE WHEN: the user asks to run the NetSuite export or a shadow posting.",
3539
+ "NOT FOR: looking at the payload (talonic_ap_netsuite_preview).",
3540
+ "",
3541
+ "ARGS: `include_held` (held invoices on payment hold), `dry_run` (answer without keeping the run), `limit`.",
3542
+ "RETURNS: { id, records, amount, results[] { bill_key, external_id, internal_id, status, location, payment_hold }, skipped[], log[] }."
3543
+ ].join("\n");
3544
+ var postInputSchema = {
3545
+ include_held: z.boolean().optional().describe("Send held invoices too, with paymentHold true."),
3546
+ dry_run: z.boolean().optional().describe("Do not keep the run."),
3547
+ limit: z.number().int().min(1).max(5e3).optional().describe("At most this many records.")
3548
+ };
3549
+ function handlePost(getToken, baseUrl, args) {
3550
+ return runTool(
3551
+ () => apiJson(getToken, baseUrl, "POST", "/v1/ap/netsuite/post", {
3552
+ body: {
3553
+ include_held: args.include_held ?? false,
3554
+ dry_run: args.dry_run ?? false,
3555
+ ...args.limit ? { limit: args.limit } : {}
3556
+ }
3557
+ })
3558
+ );
3559
+ }
3560
+ var RUNS_DESCRIPTION = [
3561
+ "Simulated NetSuite posting runs: the list, or one run with its internal ids and posting log.",
3562
+ "USE WHEN: checking what an earlier export posted.",
3563
+ "NOT FOR: posting (talonic_ap_netsuite_post).",
3564
+ "",
3565
+ "ARGS: `run_id` (one run; omit for the list).",
3566
+ "RETURNS: { data[] } or one run { results[], skipped[], log[] }."
3567
+ ].join("\n");
3568
+ var runsInputSchema = {
3569
+ run_id: z.string().uuid().optional().describe("One run (from the list).")
3570
+ };
3571
+ function handleRuns(getToken, baseUrl, args) {
3572
+ return runTool(
3573
+ () => apiJson(
3574
+ getToken,
3575
+ baseUrl,
3576
+ "GET",
3577
+ args.run_id ? `/v1/ap/netsuite/runs/${args.run_id}` : "/v1/ap/netsuite/runs"
3578
+ )
3579
+ );
3580
+ }
3581
+ async function probeApAccess(token, baseUrl) {
3582
+ try {
3583
+ const res = await fetch(buildUrl(baseUrl, "/v1/ap/config"), {
3584
+ headers: { Authorization: `Bearer ${token}`, Accept: "application/json" },
3585
+ signal: AbortSignal.timeout(5e3)
3586
+ });
3587
+ return res.ok;
3588
+ } catch {
3589
+ return false;
3590
+ }
3591
+ }
3592
+ function registerApTools(server, getToken, baseUrl) {
3593
+ const tools = [
3594
+ [
3595
+ "talonic_ap_overview",
3596
+ "AP totals",
3597
+ OVERVIEW_DESCRIPTION,
3598
+ {},
3599
+ readOnly2,
3600
+ () => handleOverview(getToken, baseUrl)
3601
+ ],
3602
+ [
3603
+ "talonic_ap_bills",
3604
+ "List AP invoices",
3605
+ BILLS_DESCRIPTION,
3606
+ billsInputSchema,
3607
+ readOnly2,
3608
+ (a) => handleBills(getToken, baseUrl, a)
3609
+ ],
3610
+ [
3611
+ "talonic_ap_issues",
3612
+ "Held AP invoices",
3613
+ ISSUES_DESCRIPTION2,
3614
+ {},
3615
+ readOnly2,
3616
+ () => handleIssues2(getToken, baseUrl)
3617
+ ],
3618
+ [
3619
+ "talonic_ap_config",
3620
+ "Read the AP configuration",
3621
+ CONFIG_DESCRIPTION,
3622
+ {},
3623
+ readOnly2,
3624
+ () => handleConfig(getToken, baseUrl)
3625
+ ],
3626
+ [
3627
+ "talonic_ap_save_config",
3628
+ "Save the AP configuration",
3629
+ SAVE_CONFIG_DESCRIPTION,
3630
+ saveConfigInputSchema,
3631
+ write2(true, true),
3632
+ (a) => handleSaveConfig(getToken, baseUrl, a)
3633
+ ],
3634
+ [
3635
+ "talonic_ap_netsuite_preview",
3636
+ "NetSuite vendor bill payload",
3637
+ PREVIEW_DESCRIPTION,
3638
+ previewInputSchema,
3639
+ readOnly2,
3640
+ (a) => handlePreview(getToken, baseUrl, a)
3641
+ ],
3642
+ [
3643
+ "talonic_ap_netsuite_post",
3644
+ "Post to the simulated NetSuite sandbox",
3645
+ POST_DESCRIPTION,
3646
+ postInputSchema,
3647
+ write2(true),
3648
+ (a) => handlePost(getToken, baseUrl, a)
3649
+ ],
3650
+ [
3651
+ "talonic_ap_netsuite_runs",
3652
+ "NetSuite posting runs",
3653
+ RUNS_DESCRIPTION,
3654
+ runsInputSchema,
3655
+ readOnly2,
3656
+ (a) => handleRuns(getToken, baseUrl, a)
3657
+ ]
3658
+ ];
3659
+ for (const [name, title, description, inputSchema11, annotations, handler] of tools) {
3660
+ server.registerTool(
3661
+ name,
3662
+ { title, description, inputSchema: inputSchema11, annotations: { title, ...annotations } },
3663
+ async (args) => handler(args)
3664
+ );
3665
+ }
3666
+ }
3426
3667
  var DEFAULT_BASE3 = "https://api.talonic.com";
3427
3668
  var TASK_STATUSES = ["available", "claimed", "submitted", "timed_out", "cancelled"];
3428
3669
  var taskId = z.string().uuid().describe("Agent task UUID.");
@@ -4960,7 +5201,7 @@ function registerAskTools(server, getToken, baseUrl) {
4960
5201
 
4961
5202
  // package.json
4962
5203
  var package_default = {
4963
- version: "0.1.82"};
5204
+ version: "0.1.84"};
4964
5205
 
4965
5206
  // src/version.ts
4966
5207
  var VERSION = package_default.version;
@@ -5116,6 +5357,9 @@ function createServer(options) {
5116
5357
  if (options.includeContractsTools) {
5117
5358
  registerContractsTools(server, rawToken, baseUrl);
5118
5359
  }
5360
+ if (options.includeApTools) {
5361
+ registerApTools(server, rawToken, baseUrl);
5362
+ }
5119
5363
  registerSchemasResource(server, getTalonic);
5120
5364
  registerWebhooksResource(server, rawToken, baseUrl);
5121
5365
  registerWidgets(server);
@@ -5158,6 +5402,15 @@ async function contractsAccessCached(token, probe = (t) => probeContractsAccess(
5158
5402
  contractsProbeCache.set(token, { ok, expiresAt: now() + GROWTH_PROBE_TTL_MS });
5159
5403
  return ok;
5160
5404
  }
5405
+ var apProbeCache = /* @__PURE__ */ new Map();
5406
+ async function apAccessCached(token, probe = (t) => probeApAccess(t, process.env["TALONIC_BASE_URL"]), now = Date.now) {
5407
+ const hit = apProbeCache.get(token);
5408
+ if (hit && hit.expiresAt > now()) return hit.ok;
5409
+ const ok = await probe(token);
5410
+ if (apProbeCache.size >= 1e3) apProbeCache.clear();
5411
+ apProbeCache.set(token, { ok, expiresAt: now() + GROWTH_PROBE_TTL_MS });
5412
+ return ok;
5413
+ }
5161
5414
  var GROWTH_PROBE_TTL_MS = 5 * 60 * 1e3;
5162
5415
  var growthProbeCache = /* @__PURE__ */ new Map();
5163
5416
  async function growthAccessCached(token, probe = probeGrowthAccess, now = Date.now) {
@@ -5401,7 +5654,7 @@ function createRequestHandler(options = {}) {
5401
5654
  return;
5402
5655
  }
5403
5656
  const transport = new StreamableHTTPServerTransport({ sessionIdGenerator: void 0 });
5404
- const [includeGrowthTools, includeAdminAgentTaskTools, includeContractsTools] = await Promise.all([
5657
+ const [includeGrowthTools, includeAdminAgentTaskTools, includeContractsTools, includeApTools] = await Promise.all([
5405
5658
  (options.growthAccess ?? ((currentToken) => growthAccessCached(
5406
5659
  currentToken,
5407
5660
  (candidate) => probeGrowthAccess(candidate, process.env["TALONIC_BASE_URL"])
@@ -5410,13 +5663,15 @@ function createRequestHandler(options = {}) {
5410
5663
  currentToken,
5411
5664
  (candidate) => probeAgentTaskAdminAccess(candidate, process.env["TALONIC_BASE_URL"])
5412
5665
  )))(token),
5413
- (options.contractsAccess ?? ((currentToken) => contractsAccessCached(currentToken)))(token)
5666
+ (options.contractsAccess ?? ((currentToken) => contractsAccessCached(currentToken)))(token),
5667
+ (options.apAccess ?? ((currentToken) => apAccessCached(currentToken)))(token)
5414
5668
  ]);
5415
5669
  const mcpServer = createServer({
5416
5670
  tokenProvider: () => token,
5417
5671
  includeGrowthTools,
5418
5672
  includeAdminAgentTaskTools,
5419
5673
  includeContractsTools,
5674
+ includeApTools,
5420
5675
  ...process.env["TALONIC_BASE_URL"] ? { baseUrl: process.env["TALONIC_BASE_URL"] } : {},
5421
5676
  // Listing UX only: an OAuth token that visibly lacks apps:decide gets
5422
5677
  // the decision-task tools marked non-invocable. The platform decides.
@@ -5448,6 +5703,6 @@ if (isDirectInvocation()) {
5448
5703
  });
5449
5704
  }
5450
5705
 
5451
- export { adminAgentTaskAccessCached, contractsAccessCached, createRequestHandler, growthAccessCached };
5706
+ export { adminAgentTaskAccessCached, apAccessCached, contractsAccessCached, createRequestHandler, growthAccessCached };
5452
5707
  //# sourceMappingURL=http-server.js.map
5453
5708
  //# sourceMappingURL=http-server.js.map