@talonic/mcp 0.1.76 → 0.1.77

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -53,6 +53,15 @@ interface CreateServerOptions {
53
53
  * re-authorizes every call; this flag controls listing visibility only.
54
54
  */
55
55
  includeAdminAgentTaskTools?: boolean;
56
+ /**
57
+ * Whether the seven decision-task tools are listed as invocable. The hosted
58
+ * entrypoint sets this from `tokenHasDecideScope`: an OAuth token that
59
+ * visibly lacks the `apps:decide` scope gets them listed but marked
60
+ * non-invocable, so the agent explains the missing consent instead of
61
+ * hitting a 403. Listing UX only; the platform decides on every call.
62
+ * Defaults to true.
63
+ */
64
+ decisionTasksInvocable?: boolean;
56
65
  }
57
66
  /**
58
67
  * Build a Talonic MCP server, ready to be connected to a transport
package/dist/index.js CHANGED
@@ -2147,6 +2147,306 @@ function registerAdminAgentTaskTools(server, getToken, baseUrl) {
2147
2147
  async (args) => handleAdminSubmitAgentTask(getToken, baseUrl, args)
2148
2148
  );
2149
2149
  }
2150
+
2151
+ // src/tools/_http.ts
2152
+ var DEFAULT_BASE3 = "https://api.talonic.com";
2153
+ function buildUrl(baseUrl, path, params = {}) {
2154
+ const qs = new URLSearchParams();
2155
+ for (const [k, v] of Object.entries(params)) {
2156
+ if (v === void 0 || v === "") continue;
2157
+ qs.set(k, String(v));
2158
+ }
2159
+ return `${baseUrl ?? DEFAULT_BASE3}${path}${qs.size ? `?${qs}` : ""}`;
2160
+ }
2161
+ async function apiJson(getToken, baseUrl, method, path, opts = {}) {
2162
+ const url = buildUrl(baseUrl, path, opts.params);
2163
+ const res = await fetch(url, {
2164
+ method,
2165
+ headers: {
2166
+ Authorization: `Bearer ${getToken()}`,
2167
+ Accept: "application/json",
2168
+ ...opts.body !== void 0 ? { "Content-Type": "application/json" } : {}
2169
+ },
2170
+ ...opts.body !== void 0 ? { body: JSON.stringify(opts.body) } : {}
2171
+ });
2172
+ if (!res.ok) {
2173
+ const text = await res.text().catch(() => "");
2174
+ throw new Error(`Talonic API error: HTTP ${res.status}${text ? ` \u2014 ${text}` : ""}`);
2175
+ }
2176
+ return await res.json();
2177
+ }
2178
+ async function runTool(fn) {
2179
+ try {
2180
+ return jsonOk(await fn());
2181
+ } catch (err) {
2182
+ return toolError(err);
2183
+ }
2184
+ }
2185
+
2186
+ // src/tools/decision-tasks.ts
2187
+ var DECIDE_SCOPE = "apps:decide";
2188
+ var TASK_STATUSES2 = [
2189
+ "available",
2190
+ "claimed",
2191
+ "submitted",
2192
+ "released",
2193
+ "failed",
2194
+ "timed_out",
2195
+ "cancelled"
2196
+ ];
2197
+ var PACKAGE_PAGE_LIMIT_MAX = 2e3;
2198
+ var appId = z.string().uuid().describe("App UUID whose decision-task inbox to read.");
2199
+ var taskId2 = z.string().uuid().describe("Decision task UUID.");
2200
+ var executionEpoch2 = z.number().int().min(1).max(2147483647).describe("Execution epoch returned by the successful claim. Stale epochs are rejected with 409.");
2201
+ var status2 = z.enum(TASK_STATUSES2).optional().describe("Optional task-status filter.");
2202
+ var listLimit = z.number().int().min(1).max(100).optional().describe("Page size (default 50).");
2203
+ var cursor2 = z.string().min(1).optional().describe("Opaque cursor from pagination.next_cursor.");
2204
+ var packageCursor = z.string().min(1).optional().describe(
2205
+ "Opaque package cursor: package.first_cursor from the claim, then pagination.next_cursor. Omit for the first page."
2206
+ );
2207
+ var packageLimit = z.number().int().min(1).max(PACKAGE_PAGE_LIMIT_MAX).optional().describe(
2208
+ `Records per page, 1 to ${PACKAGE_PAGE_LIMIT_MAX}. Defaults to the platform page size (package.page_size from the claim).`
2209
+ );
2210
+ var outcome = z.record(z.string(), z.json()).describe(
2211
+ "The decision, shaped by output_contract from the claim: for a plain JSON Schema contract the object that schema validates; for a verdict_matrix contract { subjects: [{ subject_key, rule_outcomes, auto?, detail? }] }; for a record_set contract its fields-and-rows envelope."
2212
+ );
2213
+ var evidence = z.array(z.string().min(1).max(512)).max(1e4).describe(
2214
+ "Provenance locators the decision relied on, each copied verbatim from the input package (or a db:/ref: locator the app holds a read grant on). Required; [] is accepted only when the app allows unevidenced decisions."
2215
+ );
2216
+ var rationale = z.string().min(1).max(4e3).describe(
2217
+ "Short decision rationale (a summary, never private chain-of-thought), up to 4,000 characters."
2218
+ );
2219
+ var confidence = z.number().min(0).max(1).optional().describe("Optional confidence from 0 to 1.");
2220
+ var serviceVersion = z.string().min(1).max(64).optional().describe("Optional build identifier of the deciding service; recorded as decided_by.label.");
2221
+ var failReason = z.string().min(1).max(2e3).describe(
2222
+ "Why the task cannot be decided, up to 2,000 characters. Recorded on the Human Review the fail raises."
2223
+ );
2224
+ var listInput2 = { app_id: appId, status: status2, limit: listLimit, cursor: cursor2 };
2225
+ var idInput2 = { task_id: taskId2 };
2226
+ var packageInput = { task_id: taskId2, cursor: packageCursor, limit: packageLimit };
2227
+ var epochInput = { task_id: taskId2, execution_epoch: executionEpoch2 };
2228
+ var submitInput2 = {
2229
+ task_id: taskId2,
2230
+ execution_epoch: executionEpoch2,
2231
+ outcome,
2232
+ evidence,
2233
+ rationale,
2234
+ confidence,
2235
+ service_version: serviceVersion
2236
+ };
2237
+ var failInput = { task_id: taskId2, execution_epoch: executionEpoch2, reason: failReason };
2238
+ function taskPath(taskId3, suffix = "") {
2239
+ return `/v1/decision-tasks/${encodeURIComponent(taskId3)}${suffix}`;
2240
+ }
2241
+ function handleListDecisionTasks(getToken, baseUrl, args) {
2242
+ return runTool(
2243
+ () => apiJson(
2244
+ getToken,
2245
+ baseUrl,
2246
+ "GET",
2247
+ `/v1/apps/${encodeURIComponent(args.app_id)}/decision-tasks`,
2248
+ {
2249
+ params: { status: args.status, limit: args.limit, cursor: args.cursor }
2250
+ }
2251
+ )
2252
+ );
2253
+ }
2254
+ function handleClaimDecisionTask(getToken, baseUrl, args) {
2255
+ return runTool(() => apiJson(getToken, baseUrl, "POST", taskPath(args.task_id, "/claim")));
2256
+ }
2257
+ function handleReadDecisionPackage(getToken, baseUrl, args) {
2258
+ return runTool(
2259
+ () => apiJson(getToken, baseUrl, "GET", taskPath(args.task_id, "/package"), {
2260
+ params: { cursor: args.cursor, limit: args.limit }
2261
+ })
2262
+ );
2263
+ }
2264
+ function handleHeartbeatDecisionTask(getToken, baseUrl, args) {
2265
+ return runTool(
2266
+ () => apiJson(getToken, baseUrl, "POST", taskPath(args.task_id, "/heartbeat"), {
2267
+ body: { execution_epoch: args.execution_epoch }
2268
+ })
2269
+ );
2270
+ }
2271
+ function handleSubmitDecisionTask(getToken, baseUrl, args) {
2272
+ return runTool(
2273
+ () => apiJson(getToken, baseUrl, "POST", taskPath(args.task_id, "/submit"), {
2274
+ body: {
2275
+ execution_epoch: args.execution_epoch,
2276
+ outcome: args.outcome,
2277
+ evidence: args.evidence,
2278
+ rationale: args.rationale,
2279
+ ...args.confidence === void 0 ? {} : { confidence: args.confidence },
2280
+ ...args.service_version === void 0 ? {} : { service_version: args.service_version }
2281
+ }
2282
+ })
2283
+ );
2284
+ }
2285
+ function handleReleaseDecisionTask(getToken, baseUrl, args) {
2286
+ return runTool(
2287
+ () => apiJson(getToken, baseUrl, "POST", taskPath(args.task_id, "/release"), {
2288
+ body: { execution_epoch: args.execution_epoch }
2289
+ })
2290
+ );
2291
+ }
2292
+ function handleFailDecisionTask(getToken, baseUrl, args) {
2293
+ return runTool(
2294
+ () => apiJson(getToken, baseUrl, "POST", taskPath(args.task_id, "/fail"), {
2295
+ body: { execution_epoch: args.execution_epoch, reason: args.reason }
2296
+ })
2297
+ );
2298
+ }
2299
+ var READ_ONLY3 = {
2300
+ readOnlyHint: true,
2301
+ destructiveHint: false,
2302
+ openWorldHint: false
2303
+ };
2304
+ var MUTATING2 = {
2305
+ readOnlyHint: false,
2306
+ destructiveHint: false,
2307
+ openWorldHint: false
2308
+ };
2309
+ var AUTH_NOTE = "AUTH: a tlnc_ key needs a per-app 'decide' grant; an OAuth connector session needs the apps:decide scope (consented at connect) and a live workspace role of senior_member or above. A 403 (decide_grant_required, insufficient_scope, insufficient_tier) names what is missing \u2014 tell the user, do not retry.";
2310
+ var NOT_INVOCABLE_PREFIX = "NOT INVOCABLE IN THIS SESSION: the connector's OAuth token lacks the apps:decide scope. Ask the user to reconnect the Talonic connector and approve 'Claim and decide tasks' before calling this; a call now returns 403 insufficient_scope.\n\n";
2311
+ var DESCRIPTIONS2 = {
2312
+ list: [
2313
+ "List one External-mode app's decision tasks (runs parked for an outside agent to decide), newest first.",
2314
+ "",
2315
+ "USE WHEN: looking for decisions to make for an app; begin with status 'available'. This is the polling alternative to the app.decision_task.offered webhook.",
2316
+ "NOT FOR: Agent-stage document tasks (use talonic_list_agent_tasks), reading a task's input package (claim it, then talonic_read_decision_package), or taking a lease (talonic_claim_decision_task).",
2317
+ "ARGS: app_id, optional status, limit, cursor. RETURNS: task metadata only (id, run_id, status, execution_epoch, lease and sla_deadline_at timing) plus pagination.next_cursor.",
2318
+ AUTH_NOTE
2319
+ ].join("\n"),
2320
+ claim: [
2321
+ "Claim an available decision task (or reclaim one whose lease expired) and receive the decision bundle: task metadata with the new execution_epoch, output_contract, precedents, and a package descriptor { package_kind, record_count, page_size, first_cursor, documents }.",
2322
+ "",
2323
+ "USE WHEN: ready to decide a listed task. There is no separate get: claiming IS the payload fetch. Save execution_epoch and lease_expires_at; then read the records with talonic_read_decision_package starting at first_cursor (null means the package has no records).",
2324
+ "NOT FOR: extending a live lease (talonic_heartbeat_decision_task) or returning a decision (talonic_submit_decision_task). A conflicting live claim returns HTTP 409.",
2325
+ AUTH_NOTE
2326
+ ].join("\n"),
2327
+ package: [
2328
+ "Read one page of a claimed decision task's frozen input package: the records the decision must be made from, with their provenance locators. Only the current claimant may read it; each page read is journaled onto the run.",
2329
+ "",
2330
+ "USE WHEN: after a successful claim, walking pages from package.first_cursor while pagination.has_more is true. The first page also carries the source documents list. A mining_round package is one record { system_prompt, first_turn, tools }.",
2331
+ "NOT FOR: unclaimed tasks (HTTP 409; claim first) or listing tasks (talonic_list_decision_tasks).",
2332
+ "ARGS: task_id, optional cursor and limit (1 to 2000). Copy evidence locators verbatim from these records for the submit.",
2333
+ AUTH_NOTE
2334
+ ].join("\n"),
2335
+ heartbeat: [
2336
+ "Extend the lease on a claimed decision task, never past its sla_deadline_at.",
2337
+ "",
2338
+ "USE WHEN: deciding may run past lease_expires_at; heartbeat before expiry using the epoch from claim.",
2339
+ "NOT FOR: acquiring a task (talonic_claim_decision_task) or finishing one (talonic_submit_decision_task / talonic_release_decision_task / talonic_fail_decision_task).",
2340
+ "ARGS: task_id and execution_epoch. A stale or foreign epoch returns HTTP 409: stop, discard the work, and re-list.",
2341
+ AUTH_NOTE
2342
+ ].join("\n"),
2343
+ submit: [
2344
+ "Submit the decision for a claimed decision task; the platform verifies it transactionally and resumes the run.",
2345
+ "",
2346
+ "USE WHEN: the decision is final. outcome must satisfy output_contract from the claim (plain JSON Schema, or the verdict_matrix / record_set envelope), evidence lists the package locators relied on (verbatim; [] only if the app allows unevidenced decisions), rationale is a short summary. Rejections are HTTP 422 with the reason and change nothing; the task stays claimed under your epoch, so fix and resubmit before the lease ends.",
2347
+ "NOT FOR: giving the task back undecided (talonic_release_decision_task) or declaring it undecidable (talonic_fail_decision_task). Stale epoch is HTTP 409.",
2348
+ "ARGS: task_id, execution_epoch, outcome, evidence, rationale, optional confidence and service_version.",
2349
+ AUTH_NOTE
2350
+ ].join("\n"),
2351
+ release: [
2352
+ "Release a claimed decision task back to 'available' without deciding it; the next claim bumps the epoch.",
2353
+ "",
2354
+ "USE WHEN: you cannot finish within the lease or SLA but another claimant could decide it.",
2355
+ "NOT FOR: declaring the task undecidable (talonic_fail_decision_task, which raises a review and applies the app's fallback) or keeping the lease (talonic_heartbeat_decision_task).",
2356
+ "ARGS: task_id and execution_epoch. Stale epoch is HTTP 409.",
2357
+ AUTH_NOTE
2358
+ ].join("\n"),
2359
+ fail: [
2360
+ "Report that the claimed decision task cannot be decided: raises a Human Review with your reason AND applies the app's declared fallback policy (rules decide, hold for review, or fail the run).",
2361
+ "",
2362
+ "USE WHEN: the package is insufficient or contradictory and no claimant could decide it. This ends the task (status 'failed').",
2363
+ "NOT FOR: temporary give-backs (talonic_release_decision_task) or a decision you can make with low confidence (submit it with confidence set).",
2364
+ "ARGS: task_id, execution_epoch, reason (up to 2,000 characters). Stale epoch is HTTP 409.",
2365
+ AUTH_NOTE
2366
+ ].join("\n")
2367
+ };
2368
+ function registerDecisionTaskTools(server, getToken, baseUrl, options = {}) {
2369
+ const invocable = options.invocable !== false;
2370
+ const describe = (text) => invocable ? text : NOT_INVOCABLE_PREFIX + text;
2371
+ const meta = invocable ? {} : { _meta: { "talonic/can_invoke": false, "talonic/required_scope": DECIDE_SCOPE } };
2372
+ server.registerTool(
2373
+ "talonic_list_decision_tasks",
2374
+ {
2375
+ title: "List Decision Tasks",
2376
+ description: describe(DESCRIPTIONS2.list),
2377
+ inputSchema: listInput2,
2378
+ annotations: { title: "List Decision Tasks", ...READ_ONLY3 },
2379
+ ...meta
2380
+ },
2381
+ async (args) => handleListDecisionTasks(getToken, baseUrl, args)
2382
+ );
2383
+ server.registerTool(
2384
+ "talonic_claim_decision_task",
2385
+ {
2386
+ title: "Claim Decision Task",
2387
+ description: describe(DESCRIPTIONS2.claim),
2388
+ inputSchema: idInput2,
2389
+ annotations: { title: "Claim Decision Task", ...MUTATING2 },
2390
+ ...meta
2391
+ },
2392
+ async (args) => handleClaimDecisionTask(getToken, baseUrl, args)
2393
+ );
2394
+ server.registerTool(
2395
+ "talonic_read_decision_package",
2396
+ {
2397
+ title: "Read Decision Package",
2398
+ description: describe(DESCRIPTIONS2.package),
2399
+ inputSchema: packageInput,
2400
+ annotations: { title: "Read Decision Package", ...READ_ONLY3 },
2401
+ ...meta
2402
+ },
2403
+ async (args) => handleReadDecisionPackage(getToken, baseUrl, args)
2404
+ );
2405
+ server.registerTool(
2406
+ "talonic_heartbeat_decision_task",
2407
+ {
2408
+ title: "Heartbeat Decision Task",
2409
+ description: describe(DESCRIPTIONS2.heartbeat),
2410
+ inputSchema: epochInput,
2411
+ annotations: { title: "Heartbeat Decision Task", ...MUTATING2 },
2412
+ ...meta
2413
+ },
2414
+ async (args) => handleHeartbeatDecisionTask(getToken, baseUrl, args)
2415
+ );
2416
+ server.registerTool(
2417
+ "talonic_submit_decision_task",
2418
+ {
2419
+ title: "Submit Decision Task",
2420
+ description: describe(DESCRIPTIONS2.submit),
2421
+ inputSchema: submitInput2,
2422
+ annotations: { title: "Submit Decision Task", ...MUTATING2 },
2423
+ ...meta
2424
+ },
2425
+ async (args) => handleSubmitDecisionTask(getToken, baseUrl, args)
2426
+ );
2427
+ server.registerTool(
2428
+ "talonic_release_decision_task",
2429
+ {
2430
+ title: "Release Decision Task",
2431
+ description: describe(DESCRIPTIONS2.release),
2432
+ inputSchema: epochInput,
2433
+ annotations: { title: "Release Decision Task", ...MUTATING2 },
2434
+ ...meta
2435
+ },
2436
+ async (args) => handleReleaseDecisionTask(getToken, baseUrl, args)
2437
+ );
2438
+ server.registerTool(
2439
+ "talonic_fail_decision_task",
2440
+ {
2441
+ title: "Fail Decision Task",
2442
+ description: describe(DESCRIPTIONS2.fail),
2443
+ inputSchema: failInput,
2444
+ annotations: { title: "Fail Decision Task", ...MUTATING2 },
2445
+ ...meta
2446
+ },
2447
+ async (args) => handleFailDecisionTask(getToken, baseUrl, args)
2448
+ );
2449
+ }
2150
2450
  var DESCRIPTION11 = [
2151
2451
  "Get the OCR-converted markdown text of a document.",
2152
2452
  "",
@@ -2251,43 +2551,6 @@ function registerToMarkdown(server, getTalonic) {
2251
2551
  async (args) => handleToMarkdown(getTalonic(), args)
2252
2552
  );
2253
2553
  }
2254
-
2255
- // src/tools/_http.ts
2256
- var DEFAULT_BASE3 = "https://api.talonic.com";
2257
- function buildUrl(baseUrl, path, params = {}) {
2258
- const qs = new URLSearchParams();
2259
- for (const [k, v] of Object.entries(params)) {
2260
- if (v === void 0 || v === "") continue;
2261
- qs.set(k, String(v));
2262
- }
2263
- return `${baseUrl ?? DEFAULT_BASE3}${path}${qs.size ? `?${qs}` : ""}`;
2264
- }
2265
- async function apiJson(getToken, baseUrl, method, path, opts = {}) {
2266
- const url = buildUrl(baseUrl, path, opts.params);
2267
- const res = await fetch(url, {
2268
- method,
2269
- headers: {
2270
- Authorization: `Bearer ${getToken()}`,
2271
- Accept: "application/json",
2272
- ...opts.body !== void 0 ? { "Content-Type": "application/json" } : {}
2273
- },
2274
- ...opts.body !== void 0 ? { body: JSON.stringify(opts.body) } : {}
2275
- });
2276
- if (!res.ok) {
2277
- const text = await res.text().catch(() => "");
2278
- throw new Error(`Talonic API error: HTTP ${res.status}${text ? ` \u2014 ${text}` : ""}`);
2279
- }
2280
- return await res.json();
2281
- }
2282
- async function runTool(fn) {
2283
- try {
2284
- return jsonOk(await fn());
2285
- } catch (err) {
2286
- return toolError(err);
2287
- }
2288
- }
2289
-
2290
- // src/tools/fields.ts
2291
2554
  var MATURITIES = ["core", "proven", "candidate"];
2292
2555
  var maturityArg = z.enum(MATURITIES).optional().describe(
2293
2556
  "Filter by maturity: `core` (universal, fully trusted \u2014 safe to build on), `proven` (recurring, stable id), `candidate` (newly discovered, may still be merged or renamed)."
@@ -2629,7 +2892,7 @@ function registerAgentRegistryTools(server, getToken, baseUrl) {
2629
2892
 
2630
2893
  // package.json
2631
2894
  var package_default = {
2632
- version: "0.1.76"};
2895
+ version: "0.1.77"};
2633
2896
 
2634
2897
  // src/version.ts
2635
2898
  var VERSION = package_default.version;
@@ -2730,6 +2993,15 @@ function createServer(options) {
2730
2993
  "For Agent-stage work, follow list -> get -> claim -> heartbeat while needed ->",
2731
2994
  "submit. Preserve the execution_epoch from claim and return only fields declared",
2732
2995
  "in the task output_contract; never continue after a lease or epoch conflict.",
2996
+ "For External-mode app decisions, follow talonic_list_decision_tasks (by app_id) ->",
2997
+ "talonic_claim_decision_task (the claim IS the payload: output_contract, precedents,",
2998
+ "package descriptor) -> talonic_read_decision_package pages from package.first_cursor ->",
2999
+ "talonic_heartbeat_decision_task while needed -> talonic_submit_decision_task with the",
3000
+ "outcome, verbatim evidence locators and a short rationale, or release / fail it. A",
3001
+ "tlnc_ key needs a per-app decide grant; an OAuth connector session needs the",
3002
+ "apps:decide scope and a senior_member role or above. If a decision tool is marked NOT",
3003
+ "INVOCABLE IN THIS SESSION, or a call returns 403, tell the user what consent or role",
3004
+ "is missing instead of retrying.",
2733
3005
  "Prefer acting over explaining."
2734
3006
  ].join(" ")
2735
3007
  }
@@ -2756,6 +3028,9 @@ function createServer(options) {
2756
3028
  registerFieldTools(server, getToken, baseUrl);
2757
3029
  registerAgentRegistryTools(server, getToken, baseUrl);
2758
3030
  registerAgentTaskTools(server, getToken, baseUrl);
3031
+ registerDecisionTaskTools(server, getToken, baseUrl, {
3032
+ invocable: options.decisionTasksInvocable !== false
3033
+ });
2759
3034
  if (options.includeGrowthTools) {
2760
3035
  registerGrowthTools(server, getToken, baseUrl);
2761
3036
  }