loopctl-mcp-server 3.45.0 → 3.46.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.
package/README.md CHANGED
@@ -301,7 +301,31 @@ Epic 39 Repo Coordination Bus — a lightweight, tenant-isolated channel for age
301
301
  | `get_story_token_usage` | orch | Get all token usage records for a single story. |
302
302
  | `get_cost_anomalies` | orch | Get cost anomaly alerts — stories or agents exceeding expected budgets. Optionally filter by project. |
303
303
  | `get_ingestion_anomalies` | orch | Get ingestion-health anomalies — capture_silence (a source_type stopped producing articles), high_reject_rate (writes rejected at high rate, persisting no article row), and sweep_stalled (the channel-post retention sweep is no longer enforcing retention, under the reserved source_type `channel_post_sweep`). Check whether knowledge capture is still landing AND being accepted, and whether coordination-bus retention is still enforced. |
304
- | `set_token_budget` | orch | Set a token budget (in millicents) for a project, epic, story, or agent scope. Requires orchestrator role. |
304
+ | `set_token_budget` | orch | Set a token budget (in millicents) for a project, epic or story scope. Requires orchestrator role. `409` when the scope already has one (`token_budget_update` changes it), `404` for a scope entity that is not this tenant's, `422` for a malformed scope id or an out-of-range value. |
305
+ | `token_budget_list` | agent | **List the tenant's token budgets** (`GET /api/v1/token-budgets`) with live spend, remaining and utilization; filters `scope_type` (project, epic, story) and `scope_id`, paged by `page`/`page_size` (1..100). Any key (`role: :agent`), sent as the session's own. Refused locally: an unknown `scope_type` (loopctl would answer an empty list), a non-UUID `scope_id`, a bad page. |
306
+ | `token_budget_get` | agent | **Read one token budget** (`GET /api/v1/token-budgets/:id`) with live spend and the `effective_budget_millicents` / `budget_source` that govern its scope after inheritance. Any key, sent as the session's own. `404` for another tenant's budget; a non-UUID `budget_id` is refused locally. |
307
+ | `token_budget_update` | orch | **Change a token budget** (`PATCH /api/v1/token-budgets/:id`): `budget_millicents`, `budget_input_tokens`, `budget_output_tokens` (null clears), `alert_threshold_pct` (1..100), `metadata`. Orchestrator role or higher: `LOOPCTL_ORCH_KEY` verbatim, else `LOOPCTL_USER_KEY`, else the default key (`403 insufficient_role` for an agent key, `403 custody_tier_required` on an agent-rooted tenant). `404` for another tenant's budget, `422` out of range. Refused locally: a non-UUID id, no field, or `scope_type`/`scope_id` (loopctl would ignore them with a 200), non-object `metadata`. |
308
+ | `token_budget_delete` | user | **Delete a token budget** (`DELETE /api/v1/token-budgets/:id`); its usage reports stay. User role: `LOOPCTL_USER_KEY` verbatim when set, else the default key (`403 insufficient_role` below user, `403 custody_tier_required` on an agent-rooted tenant). `404` for another tenant's budget; a non-UUID `budget_id` is refused locally. |
309
+ | `token_usage_delete` | user | **Soft-delete a token usage report** (`DELETE /api/v1/token-usage/:id`): it leaves every total and analytics read; budget flags reset when spend drops back. User role on a human-anchored tenant, keyed as `token_budget_delete`. `404` for a missing, foreign or already deleted report; a non-UUID `report_id` is refused locally. |
310
+ | `token_usage_correct` | user | **Correct a token usage report** (`POST /api/v1/token-usage/:id/correction`): a new report carrying signed deltas `input_tokens`, `output_tokens`, `cost_millicents` (all required, negative subtracts), optional `model_name`, `phase`, `session_id`, `skill_version_id`, `metadata`. User role on a human-anchored tenant, keyed as `token_budget_delete`. `404` for a missing, foreign or deleted original; `422` when a total would go below 0, the original is a correction, or the phase or skill version is invalid. Refused locally: non-UUID ids, a missing or non-integer delta, non-object `metadata`. |
311
+ | `cost_anomaly_resolve` | user | **Resolve a cost anomaly** (`PATCH /api/v1/cost-anomalies/:id`); audited. User role on a human-anchored tenant: `LOOPCTL_USER_KEY` verbatim when set, else the default key (`403 insufficient_role` below user, `403 custody_tier_required` on an agent-rooted tenant). `404` for another tenant's anomaly; a non-UUID `anomaly_id` is refused locally. |
312
+ | `ingestion_anomaly_update` | user | **Resolve, archive or un-archive an ingestion anomaly** (`PATCH /api/v1/ingestion-anomalies/:id`, `action` resolve by default, archive → `?archived=true`, unarchive → `?archived=false`). Archive suppresses re-detection for a retired source_type. Keyed and gated as `cost_anomaly_resolve`. `404` for another tenant's anomaly; a non-UUID id or unknown `action` is refused locally. |
313
+ | `cost_trends` | orch | **Read the daily or weekly cost trend** (`GET /api/v1/analytics/trends`), filtered by `project_id` (UUID, slug or repo name), `since`/`until` (YYYY-MM-DD), paged by `page`/`page_size`. Orchestrator role or higher, keyed as `token_budget_update` (`403 insufficient_role` for an agent key). `422` for a project naming none. Refused locally: an unknown `granularity` (loopctl would answer daily), a date that is not real (loopctl would drop it and answer for all time), a bad page. |
314
+ | `model_mix` | orch | **Read the model-mix matrix** (`GET /api/v1/analytics/model-mix`): totals and verification outcomes per (model, phase), and mixed-model against single-model agents. Filters `project_id`, `agent_id`, `since`, `until`. Keyed as `cost_trends`. Refused locally: a non-UUID `agent_id`, a date that is not real. |
315
+ | `agent_model_profile` | orch | **Read one agent's model profile** (`GET /api/v1/analytics/agents/:id/model-profile`): models per phase, `model_count`, `is_model_blender`. Filters `project_id`, `since`, `until`. Keyed as `cost_trends`. `404` for another tenant's agent; a non-UUID `agent_id` or unreal date is refused locally. |
316
+
317
+ ### Webhook Tools (user key)
318
+
319
+ Every webhook action is `role: :user` with the hierarchy: `LOOPCTL_USER_KEY` verbatim when set, else the default key (`403 insufficient_role` for an agent or orchestrator key).
320
+
321
+ | Tool | Auth Key | Description |
322
+ |---|---|---|
323
+ | `webhook_create` | user | **Subscribe a URL to loopctl events** (`POST /api/v1/webhooks`): `url`, `events`, optional `project_id`. The signing secret loopctl returns once is written to `secret_file` (absolute, must not exist, created 0600 before the request) and never returned. `422` for an unknown event type, a malformed URL, a destination the egress guard refuses, or the tenant's webhook limit. Refused locally: a blank url, empty or non-string events, a bad `secret_file`. |
324
+ | `webhook_list` | user | **List webhook subscriptions** (`GET /api/v1/webhooks`), never with a secret; `page`/`page_size` (1..100). A bad page is refused locally (loopctl would clamp it). |
325
+ | `webhook_update` | user | **Edit a subscription** (`PATCH /api/v1/webhooks/:id`): `url`, `events`, `project_id`, `active` (true re-activates and resets failures). A url, project or re-activation change is re-vetted by the egress guard. `404` for another tenant's subscription, `422` as on create. Refused locally: a non-UUID id, no field (loopctl would answer 200 unchanged), a null `project_id` (it cannot be cleared), bad `events` or `active`. The `PUT` twin is served and unused. |
326
+ | `webhook_delete` | user | **Delete a subscription** (`DELETE /api/v1/webhooks/:id`) and its pending deliveries; `204`. `404` for another tenant's; a non-UUID id is refused locally. |
327
+ | `webhook_test` | user | **Send a test event** (`POST /api/v1/webhooks/:id/test`): one `webhook.test` delivery, even to an inactive subscription. `404` for another tenant's; a non-UUID id is refused locally. |
328
+ | `webhook_deliveries` | user | **List a subscription's recent delivery attempts** (`GET /api/v1/webhooks/:id/deliveries`): status, attempts, error (HTTP status and content-type, never the response body); `page`/`page_size` (1..100, default 25). `404` for another tenant's; a non-UUID id or bad page is refused locally. |
305
329
 
306
330
  ### Knowledge Wiki Tools (agent key)
307
331
 
package/index.js CHANGED
@@ -75,6 +75,23 @@ import {
75
75
  import { readFactoryPolicy } from "./lib/factory-policy.js";
76
76
  import { snapshotUrls } from "./lib/snapshots.js";
77
77
  import { apiKeyCreate, apiKeyList, apiKeyRotate } from "./lib/api-keys.js";
78
+ import {
79
+ webhookCreate,
80
+ webhookDeliveries,
81
+ webhookDelete,
82
+ webhookList,
83
+ webhookTest,
84
+ webhookUpdate,
85
+ } from "./lib/webhooks.js";
86
+ import {
87
+ tokenBudgetDelete,
88
+ tokenBudgetGet,
89
+ tokenBudgetList,
90
+ tokenBudgetUpdate,
91
+ } from "./lib/token-budgets.js";
92
+ import { tokenUsageCorrect, tokenUsageDelete } from "./lib/token-usage-admin.js";
93
+ import { costAnomalyResolve, ingestionAnomalyUpdate } from "./lib/anomaly-resolution.js";
94
+ import { agentModelProfile, costTrends, modelMix } from "./lib/cost-analytics.js";
78
95
  import {
79
96
  openReviewRound,
80
97
  readReviewRoundStatus,
@@ -427,9 +444,12 @@ async function sendRequest(
427
444
  const key = exactKey ? keyOverride : resolveKey(keyOverride);
428
445
 
429
446
  if (!key) {
447
+ // `not_sent` tells a caller that reads status 0 as "the request may have landed" (a create
448
+ // that holds a secret, e.g. lib/webhooks.js) that nothing reached loopctl.
430
449
  return {
431
450
  error: true,
432
451
  status: 0,
452
+ not_sent: true,
433
453
  body: exactKey
434
454
  ? // `keyHint` names the env var THIS site is pinned to. Without it the message
435
455
  // below talks about LLM configuration, which is right for set_llm_config and
@@ -1380,6 +1400,81 @@ async function updateTenantTool(args) {
1380
1400
  return toContent(await updateTenant(args, { apiCall: userKeyApiCall }));
1381
1401
  }
1382
1402
 
1403
+ // loopctl #872, batch 3. Every webhook action is `role: :user` (`userKeyApiCall`); create's
1404
+ // signing secret goes to `secret_file`, never the result. The token-budget reads are
1405
+ // `role: :agent` (the session's own key), the budget update `role: :orchestrator`
1406
+ // (`orchestratorPinnedApiCall`) and the budget delete `role: :user`. The token-usage delete and
1407
+ // correction and both anomaly resolutions are `role: :user` (`userKeyApiCall`). The three
1408
+ // analytics reads are `role: :orchestrator` (`orchestratorPinnedApiCall`).
1409
+
1410
+ async function webhookCreateTool(args) {
1411
+ return toContent(await webhookCreate(args, { apiCall: userKeyApiCall }));
1412
+ }
1413
+
1414
+ async function webhookListTool(args) {
1415
+ return toContent(await webhookList(args, { apiCall: userKeyApiCall }));
1416
+ }
1417
+
1418
+ async function webhookUpdateTool(args) {
1419
+ return toContent(await webhookUpdate(args, { apiCall: userKeyApiCall }));
1420
+ }
1421
+
1422
+ async function webhookDeleteTool(args) {
1423
+ return toContent(await webhookDelete(args, { apiCall: userKeyApiCall }));
1424
+ }
1425
+
1426
+ async function webhookTestTool(args) {
1427
+ return toContent(await webhookTest(args, { apiCall: userKeyApiCall }));
1428
+ }
1429
+
1430
+ async function webhookDeliveriesTool(args) {
1431
+ return toContent(await webhookDeliveries(args, { apiCall: userKeyApiCall }));
1432
+ }
1433
+
1434
+ async function tokenBudgetListTool(args) {
1435
+ return toContent(await tokenBudgetList(args, { apiCall: ownKeyApiCall }));
1436
+ }
1437
+
1438
+ async function tokenBudgetGetTool(args) {
1439
+ return toContent(await tokenBudgetGet(args, { apiCall: ownKeyApiCall }));
1440
+ }
1441
+
1442
+ async function tokenBudgetUpdateTool(args) {
1443
+ return toContent(await tokenBudgetUpdate(args, { apiCall: orchestratorPinnedApiCall }));
1444
+ }
1445
+
1446
+ async function tokenBudgetDeleteTool(args) {
1447
+ return toContent(await tokenBudgetDelete(args, { apiCall: userKeyApiCall }));
1448
+ }
1449
+
1450
+ async function tokenUsageDeleteTool(args) {
1451
+ return toContent(await tokenUsageDelete(args, { apiCall: userKeyApiCall }));
1452
+ }
1453
+
1454
+ async function tokenUsageCorrectTool(args) {
1455
+ return toContent(await tokenUsageCorrect(args, { apiCall: userKeyApiCall }));
1456
+ }
1457
+
1458
+ async function costAnomalyResolveTool(args) {
1459
+ return toContent(await costAnomalyResolve(args, { apiCall: userKeyApiCall }));
1460
+ }
1461
+
1462
+ async function ingestionAnomalyUpdateTool(args) {
1463
+ return toContent(await ingestionAnomalyUpdate(args, { apiCall: userKeyApiCall }));
1464
+ }
1465
+
1466
+ async function costTrendsTool(args) {
1467
+ return toContent(await costTrends(args, { apiCall: orchestratorPinnedApiCall }));
1468
+ }
1469
+
1470
+ async function modelMixTool(args) {
1471
+ return toContent(await modelMix(args, { apiCall: orchestratorPinnedApiCall }));
1472
+ }
1473
+
1474
+ async function agentModelProfileTool(args) {
1475
+ return toContent(await agentModelProfile(args, { apiCall: orchestratorPinnedApiCall }));
1476
+ }
1477
+
1383
1478
  // --- Workflow Tools (agent key) ---
1384
1479
 
1385
1480
  async function contractStory({ story_id, story_title, ac_count }) {
@@ -5776,28 +5871,30 @@ const TOOLS = [
5776
5871
  {
5777
5872
  name: "set_token_budget",
5778
5873
  description:
5779
- "Set a token budget for a scope (project, epic, story, or agent). " +
5780
- "Requires orchestrator or user role. Uses the ORCH key.",
5874
+ "Set a token budget for a scope (project, epic or story). " +
5875
+ "Requires orchestrator or user role. Uses the ORCH key. 409 when the scope already " +
5876
+ "has a budget (change it with token_budget_update), 404 for a scope entity that is " +
5877
+ "not this tenant's, 422 for a malformed scope_id or a value out of range.",
5781
5878
  inputSchema: {
5782
5879
  type: "object",
5783
5880
  properties: {
5784
5881
  scope_type: {
5785
5882
  type: "string",
5786
- enum: ["project", "epic", "story", "agent"],
5883
+ enum: ["project", "epic", "story"],
5787
5884
  description: "The type of scope to apply the budget to.",
5788
5885
  },
5789
5886
  scope_id: {
5790
5887
  type: "string",
5791
- description: "The UUID of the scoped resource (project_id, epic_id, story_id, or agent_id).",
5888
+ description: "The UUID of the scoped resource (project_id, epic_id or story_id).",
5792
5889
  },
5793
5890
  budget_millicents: {
5794
5891
  type: "integer",
5795
5892
  description: "Maximum allowed cost in millicents (1/1000 of a cent).",
5796
5893
  },
5797
5894
  alert_threshold_pct: {
5798
- type: "number",
5799
- description: "Optional: percentage of budget at which to trigger an alert (0–100).",
5800
- minimum: 0,
5895
+ type: "integer",
5896
+ description: "Optional: percentage of budget at which to trigger an alert (1–100).",
5897
+ minimum: 1,
5801
5898
  maximum: 100,
5802
5899
  },
5803
5900
  },
@@ -10315,6 +10412,429 @@ const TOOLS = [
10315
10412
  required: [],
10316
10413
  },
10317
10414
  },
10415
+ {
10416
+ name: "webhook_create",
10417
+ description:
10418
+ "SUBSCRIBE A URL TO LOOPCTL EVENTS (POST /api/v1/webhooks): `url` (https or http), " +
10419
+ "`events` (a non-empty list such as story.verified, story.status_changed, " +
10420
+ "token.budget_exceeded, webhook.test) and optional `project_id` (UUID, slug or repo " +
10421
+ "name; omitted = every project). Deliveries are signed `X-Webhook-Signature: " +
10422
+ "t=<unix>,v1=<hmac_sha256>` over `<t>.<raw_body>` with the subscription's signing " +
10423
+ "secret, which loopctl returns ONCE. THIS TOOL NEVER RETURNS IT: it is written to " +
10424
+ "`secret_file` (an absolute path that must not exist yet, created 0600 before the " +
10425
+ "request) and the result carries the subscription without it. Needs a USER-role key " +
10426
+ "(`role: :user` with the hierarchy), sent on LOOPCTL_USER_KEY verbatim when set, else " +
10427
+ "the default key; an agent or orchestrator key is 403 insufficient_role. 422 for an " +
10428
+ "unknown event type, a malformed URL, a destination the egress guard refuses (private, " +
10429
+ "loopback, link-local and similar addresses unless the operator allowlist carves them " +
10430
+ "out for webhook delivery; the message names which), or the tenant's webhook limit; " +
10431
+ "429 past the rate limit. Refused by the tool, sending nothing: a blank url, empty or " +
10432
+ "non-string events, a blank project_id, and a secret_file that is not absolute, exists " +
10433
+ "already or sits in a missing directory.",
10434
+ inputSchema: {
10435
+ type: "object",
10436
+ properties: {
10437
+ url: { type: "string", description: "The URL deliveries are POSTed to." },
10438
+ events: {
10439
+ type: "array",
10440
+ items: { type: "string" },
10441
+ description: "The event types to deliver, e.g. [\"story.verified\"].",
10442
+ },
10443
+ project_id: {
10444
+ type: "string",
10445
+ description: "Optional: limit deliveries to one project (UUID, slug or repo name).",
10446
+ },
10447
+ secret_file: {
10448
+ type: "string",
10449
+ description:
10450
+ "REQUIRED. Absolute path, which must not exist yet, the signing secret is written " +
10451
+ "to (mode 0600). Move it where the receiver reads it, then delete the file.",
10452
+ },
10453
+ },
10454
+ required: ["url", "events", "secret_file"],
10455
+ },
10456
+ },
10457
+ {
10458
+ name: "webhook_list",
10459
+ description:
10460
+ "LIST THE TENANT'S WEBHOOK SUBSCRIPTIONS (GET /api/v1/webhooks), newest first: each " +
10461
+ "with `id`, `url`, `events`, `project_id`, `active`, `consecutive_failures` and " +
10462
+ "`last_delivery_at` (never the signing secret), plus `meta` paging. `page` and " +
10463
+ "`page_size` (1..100, default 20). Needs a USER-role key, keyed as webhook_create; an " +
10464
+ "agent or orchestrator key is 403 insufficient_role. A bad page or page_size is " +
10465
+ "refused by the tool, sending nothing: loopctl would clamp or drop it.",
10466
+ inputSchema: {
10467
+ type: "object",
10468
+ properties: {
10469
+ page: { type: "integer", description: "Optional page number (default 1)." },
10470
+ page_size: { type: "integer", description: "Optional page size, 1..100 (default 20)." },
10471
+ },
10472
+ required: [],
10473
+ },
10474
+ },
10475
+ {
10476
+ name: "webhook_update",
10477
+ description:
10478
+ "EDIT A WEBHOOK SUBSCRIPTION (PATCH /api/v1/webhooks/:id): any of `url`, `events`, " +
10479
+ "`project_id` and `active` (false pauses it; true re-activates it and resets " +
10480
+ "`consecutive_failures`). A change of url or project, or a re-activation, is vetted " +
10481
+ "against the egress guard as webhook_create is. Needs a USER-role key, keyed as " +
10482
+ "webhook_create; an agent or orchestrator key is 403 insufficient_role. 404 for a " +
10483
+ "subscription that is not this tenant's; 422 for an unknown event type, a malformed " +
10484
+ "URL or a refused destination. A subscription's project cannot be cleared. Refused by " +
10485
+ "the tool, sending nothing: a non-UUID `webhook_id`, a call naming no field (loopctl " +
10486
+ "would answer 200 unchanged), a null or blank project_id, empty or non-string events, " +
10487
+ "and a non-boolean active.",
10488
+ inputSchema: {
10489
+ type: "object",
10490
+ properties: {
10491
+ webhook_id: { type: "string", description: "The UUID of the subscription." },
10492
+ url: { type: "string", description: "Optional: the new delivery URL." },
10493
+ events: {
10494
+ type: "array",
10495
+ items: { type: "string" },
10496
+ description: "Optional: the full new list of event types (replaces the old list).",
10497
+ },
10498
+ project_id: {
10499
+ type: "string",
10500
+ description: "Optional: the project to deliver for (UUID, slug or repo name).",
10501
+ },
10502
+ active: { type: "boolean", description: "Optional: false pauses, true re-activates." },
10503
+ },
10504
+ required: ["webhook_id"],
10505
+ },
10506
+ },
10507
+ {
10508
+ name: "webhook_delete",
10509
+ description:
10510
+ "DELETE A WEBHOOK SUBSCRIPTION (DELETE /api/v1/webhooks/:id) and every delivery still " +
10511
+ "pending for it; audited; answers 204. Needs a USER-role key, keyed as webhook_create; " +
10512
+ "an agent or orchestrator key is 403 insufficient_role. 404 for a subscription that is " +
10513
+ "not this tenant's. A non-UUID `webhook_id` is refused by the tool, sending nothing.",
10514
+ inputSchema: {
10515
+ type: "object",
10516
+ properties: {
10517
+ webhook_id: { type: "string", description: "The UUID of the subscription." },
10518
+ },
10519
+ required: ["webhook_id"],
10520
+ },
10521
+ },
10522
+ {
10523
+ name: "webhook_test",
10524
+ description:
10525
+ "SEND A TEST EVENT TO A WEBHOOK (POST /api/v1/webhooks/:id/test): enqueues one " +
10526
+ "`webhook.test` delivery, even to an inactive subscription, and answers its " +
10527
+ "`webhook_event_id` with status pending. Read the outcome with webhook_deliveries. " +
10528
+ "Needs a USER-role key, keyed as webhook_create; an agent or orchestrator key is 403 " +
10529
+ "insufficient_role. 404 for a subscription that is not this tenant's. A non-UUID " +
10530
+ "`webhook_id` is refused by the tool, sending nothing.",
10531
+ inputSchema: {
10532
+ type: "object",
10533
+ properties: {
10534
+ webhook_id: { type: "string", description: "The UUID of the subscription." },
10535
+ },
10536
+ required: ["webhook_id"],
10537
+ },
10538
+ },
10539
+ {
10540
+ name: "webhook_deliveries",
10541
+ description:
10542
+ "LIST A WEBHOOK'S RECENT DELIVERY ATTEMPTS (GET /api/v1/webhooks/:id/deliveries), " +
10543
+ "newest first: each with `event_type`, `status`, `attempts`, `delivered_at` and " +
10544
+ "`error`. A failed attempt's error carries the HTTP status and response content-type, " +
10545
+ "never the receiver's response body. `page` and `page_size` (1..100, default 25). " +
10546
+ "Needs a USER-role key, keyed as webhook_create; an agent or orchestrator key is 403 " +
10547
+ "insufficient_role. 404 for a subscription that is not this tenant's. Refused by the " +
10548
+ "tool, sending nothing: a non-UUID `webhook_id` and a bad page or page_size.",
10549
+ inputSchema: {
10550
+ type: "object",
10551
+ properties: {
10552
+ webhook_id: { type: "string", description: "The UUID of the subscription." },
10553
+ page: { type: "integer", description: "Optional page number (default 1)." },
10554
+ page_size: { type: "integer", description: "Optional page size, 1..100 (default 25)." },
10555
+ },
10556
+ required: ["webhook_id"],
10557
+ },
10558
+ },
10559
+ {
10560
+ name: "token_budget_list",
10561
+ description:
10562
+ "LIST THE TENANT'S TOKEN BUDGETS (GET /api/v1/token-budgets), newest first: each with " +
10563
+ "`scope_type`, `scope_id`, `budget_millicents`, token limits, `alert_threshold_pct`, " +
10564
+ "and the live `current_spend_millicents`, `remaining_millicents` and " +
10565
+ "`utilization_pct`, plus `meta` paging. Filters `scope_type` (project, epic, story) " +
10566
+ "and `scope_id` (UUID); `page` and `page_size` (1..100, default 20). Any key: " +
10567
+ "`role: :agent`, sent as the session's own. Refused by the tool, sending nothing: an " +
10568
+ "unknown scope_type (loopctl would answer an empty list), a non-UUID scope_id, and a " +
10569
+ "bad page or page_size.",
10570
+ inputSchema: {
10571
+ type: "object",
10572
+ properties: {
10573
+ scope_type: {
10574
+ type: "string",
10575
+ enum: ["project", "epic", "story"],
10576
+ description: "Optional scope_type filter.",
10577
+ },
10578
+ scope_id: { type: "string", description: "Optional: the scoped entity's UUID." },
10579
+ page: { type: "integer", description: "Optional page number (default 1)." },
10580
+ page_size: { type: "integer", description: "Optional page size, 1..100 (default 20)." },
10581
+ },
10582
+ required: [],
10583
+ },
10584
+ },
10585
+ {
10586
+ name: "token_budget_get",
10587
+ description:
10588
+ "READ ONE TOKEN BUDGET (GET /api/v1/token-budgets/:id) with its live spend, remaining " +
10589
+ "and utilization, plus `effective_budget_millicents` and `budget_source` (the budget " +
10590
+ "that actually governs the scope after inheritance from epic, project or the tenant " +
10591
+ "default). Any key: `role: :agent`, sent as the session's own. 404 for a budget that " +
10592
+ "is not this tenant's. A non-UUID `budget_id` is refused by the tool, sending nothing.",
10593
+ inputSchema: {
10594
+ type: "object",
10595
+ properties: {
10596
+ budget_id: { type: "string", description: "The UUID of the budget." },
10597
+ },
10598
+ required: ["budget_id"],
10599
+ },
10600
+ },
10601
+ {
10602
+ name: "token_budget_update",
10603
+ description:
10604
+ "CHANGE A TOKEN BUDGET (PATCH /api/v1/token-budgets/:id): any of " +
10605
+ "`budget_millicents` (above 0), `budget_input_tokens` and `budget_output_tokens` (0 or " +
10606
+ "more, null clears), `alert_threshold_pct` (1..100) and `metadata` (replaces the " +
10607
+ "stored map). Changing the amount or threshold re-arms the warning and exceeded " +
10608
+ "alerts. The scope is fixed: delete and re-create to move a budget. Needs an " +
10609
+ "ORCHESTRATOR-role key or higher (`role: :orchestrator` with the hierarchy), sent on " +
10610
+ "LOOPCTL_ORCH_KEY verbatim, else LOOPCTL_USER_KEY, else the default key; an agent key " +
10611
+ "is 403 insufficient_role, and an agent-rooted tenant is 403 custody_tier_required. " +
10612
+ "404 for a budget that is not this tenant's; 422 for a value out of range. Refused by " +
10613
+ "the tool, sending nothing: a non-UUID `budget_id`, a call naming no field or naming " +
10614
+ "scope_type or scope_id (loopctl would ignore them and answer 200 unchanged), and a " +
10615
+ "metadata that is not an object.",
10616
+ inputSchema: {
10617
+ type: "object",
10618
+ properties: {
10619
+ budget_id: { type: "string", description: "The UUID of the budget." },
10620
+ budget_millicents: {
10621
+ type: "integer",
10622
+ description: "Optional: the budget in millicents (1/1000 of a cent), above 0.",
10623
+ },
10624
+ budget_input_tokens: {
10625
+ type: ["integer", "null"],
10626
+ description: "Optional: an input-token limit, 0 or more; null clears it.",
10627
+ },
10628
+ budget_output_tokens: {
10629
+ type: ["integer", "null"],
10630
+ description: "Optional: an output-token limit, 0 or more; null clears it.",
10631
+ },
10632
+ alert_threshold_pct: {
10633
+ type: "integer",
10634
+ minimum: 1,
10635
+ maximum: 100,
10636
+ description: "Optional: the percentage of the budget that fires the warning.",
10637
+ },
10638
+ metadata: { type: "object", description: "Optional: replaces the stored metadata." },
10639
+ },
10640
+ required: ["budget_id"],
10641
+ },
10642
+ },
10643
+ {
10644
+ name: "token_budget_delete",
10645
+ description:
10646
+ "DELETE A TOKEN BUDGET (DELETE /api/v1/token-budgets/:id); audited. Its usage reports " +
10647
+ "stay, and the scope falls back to an inherited budget. Needs a USER-role key " +
10648
+ "(`role: :user` with the hierarchy), sent on LOOPCTL_USER_KEY verbatim when set, else " +
10649
+ "the default key; an agent or orchestrator key is 403 insufficient_role, and an " +
10650
+ "agent-rooted tenant is 403 custody_tier_required. 404 for a budget that is not this " +
10651
+ "tenant's. A non-UUID `budget_id` is refused by the tool, sending nothing.",
10652
+ inputSchema: {
10653
+ type: "object",
10654
+ properties: {
10655
+ budget_id: { type: "string", description: "The UUID of the budget." },
10656
+ },
10657
+ required: ["budget_id"],
10658
+ },
10659
+ },
10660
+ {
10661
+ name: "token_usage_delete",
10662
+ description:
10663
+ "SOFT-DELETE A TOKEN USAGE REPORT (DELETE /api/v1/token-usage/:id): the report leaves " +
10664
+ "every total and analytics read, and budget warning flags reset when spend drops back " +
10665
+ "below them; audited. To adjust a report rather than remove it, use " +
10666
+ "token_usage_correct. Needs a USER-role key (`role: :user` with the hierarchy), sent on " +
10667
+ "LOOPCTL_USER_KEY verbatim when set, else the default key; an agent or orchestrator " +
10668
+ "key is 403 insufficient_role, and an agent-rooted tenant is 403 " +
10669
+ "custody_tier_required. 404 for a report that is missing, another tenant's or already " +
10670
+ "deleted. A non-UUID `report_id` is refused by the tool, sending nothing.",
10671
+ inputSchema: {
10672
+ type: "object",
10673
+ properties: {
10674
+ report_id: { type: "string", description: "The UUID of the token usage report." },
10675
+ },
10676
+ required: ["report_id"],
10677
+ },
10678
+ },
10679
+ {
10680
+ name: "token_usage_correct",
10681
+ description:
10682
+ "CORRECT A TOKEN USAGE REPORT (POST /api/v1/token-usage/:id/correction): records a NEW " +
10683
+ "report that references the original and carries signed deltas, so negative " +
10684
+ "`input_tokens`, `output_tokens` and `cost_millicents` subtract from the story's " +
10685
+ "totals. All three are required (0 for no change). Optional `model_name` and `phase` " +
10686
+ "(planning, implementing, reviewing, other) default to the original's; optional " +
10687
+ "`session_id`, `skill_version_id` and `metadata`. Answers 201 with the correction. " +
10688
+ "Needs a USER-role key, keyed as token_usage_delete; an agent or orchestrator key is " +
10689
+ "403 insufficient_role, and an agent-rooted tenant is 403 custody_tier_required. 404 " +
10690
+ "for an original that is missing, another tenant's or deleted; 422 when the " +
10691
+ "correction would drive any total below 0, when the original is itself a correction, " +
10692
+ "for an unknown phase, or for a skill_version_id that is not this tenant's. Refused by " +
10693
+ "the tool, sending nothing: a non-UUID `report_id` or skill_version_id, a delta that " +
10694
+ "is missing or not an integer, and a metadata that is not an object.",
10695
+ inputSchema: {
10696
+ type: "object",
10697
+ properties: {
10698
+ report_id: { type: "string", description: "The UUID of the report to correct." },
10699
+ input_tokens: { type: "integer", description: "Input-token delta (negative subtracts)." },
10700
+ output_tokens: { type: "integer", description: "Output-token delta (negative subtracts)." },
10701
+ cost_millicents: { type: "integer", description: "Cost delta in millicents." },
10702
+ model_name: { type: "string", description: "Optional: defaults to the original's." },
10703
+ phase: {
10704
+ type: "string",
10705
+ enum: ["planning", "implementing", "reviewing", "other"],
10706
+ description: "Optional: defaults to the original's.",
10707
+ },
10708
+ session_id: { type: "string", description: "Optional session id." },
10709
+ skill_version_id: { type: "string", description: "Optional: a skill version UUID." },
10710
+ metadata: { type: "object", description: "Optional structured detail." },
10711
+ },
10712
+ required: ["report_id", "input_tokens", "output_tokens", "cost_millicents"],
10713
+ },
10714
+ },
10715
+ {
10716
+ name: "cost_anomaly_resolve",
10717
+ description:
10718
+ "RESOLVE A COST ANOMALY (PATCH /api/v1/cost-anomalies/:id): marks it resolved; " +
10719
+ "audited. Answers its `id`, `resolved` and `updated_at`. List them with " +
10720
+ "get_cost_anomalies. Needs a USER-role key (`role: :user` with the hierarchy), sent on " +
10721
+ "LOOPCTL_USER_KEY verbatim when set, else the default key; an agent or orchestrator " +
10722
+ "key is 403 insufficient_role, and an agent-rooted tenant is 403 " +
10723
+ "custody_tier_required. 404 for an anomaly that is not this tenant's. A non-UUID " +
10724
+ "`anomaly_id` is refused by the tool, sending nothing.",
10725
+ inputSchema: {
10726
+ type: "object",
10727
+ properties: {
10728
+ anomaly_id: { type: "string", description: "The UUID of the cost anomaly." },
10729
+ },
10730
+ required: ["anomaly_id"],
10731
+ },
10732
+ },
10733
+ {
10734
+ name: "ingestion_anomaly_update",
10735
+ description:
10736
+ "RESOLVE, ARCHIVE OR UN-ARCHIVE AN INGESTION ANOMALY (PATCH " +
10737
+ "/api/v1/ingestion-anomalies/:id): `action` resolve (the default) marks it resolved; " +
10738
+ "archive hides it from the default list and suppresses re-detection, for a retired " +
10739
+ "source_type; unarchive restores monitoring. Audited. Answers its `id`, `resolved`, " +
10740
+ "`archived` and `updated_at`. List them with get_ingestion_anomalies. Needs a " +
10741
+ "USER-role key, keyed as cost_anomaly_resolve; an agent or orchestrator key is 403 " +
10742
+ "insufficient_role, and an agent-rooted tenant is 403 custody_tier_required. 404 for " +
10743
+ "an anomaly that is not this tenant's. Refused by the tool, sending nothing: a " +
10744
+ "non-UUID `anomaly_id` and an unknown action.",
10745
+ inputSchema: {
10746
+ type: "object",
10747
+ properties: {
10748
+ anomaly_id: { type: "string", description: "The UUID of the ingestion anomaly." },
10749
+ action: {
10750
+ type: "string",
10751
+ enum: ["resolve", "archive", "unarchive"],
10752
+ description: "Optional: resolve (default), archive or unarchive.",
10753
+ },
10754
+ },
10755
+ required: ["anomaly_id"],
10756
+ },
10757
+ },
10758
+ {
10759
+ name: "cost_trends",
10760
+ description:
10761
+ "READ THE COST TREND (GET /api/v1/analytics/trends): token and cost totals per day, or " +
10762
+ "per week with `granularity` weekly, with paging `meta`. Optional `project_id` (UUID, " +
10763
+ "slug or repo name), `since` and `until` (YYYY-MM-DD), `page` and `page_size` (1..100, " +
10764
+ "default 20). Needs an ORCHESTRATOR-role key or higher (`role: :orchestrator` with the " +
10765
+ "hierarchy), sent on LOOPCTL_ORCH_KEY verbatim, else LOOPCTL_USER_KEY, else the " +
10766
+ "default key; an agent key is 403 insufficient_role. 422 for a project_id naming no " +
10767
+ "project. Refused by the tool, sending nothing: a granularity other than daily or " +
10768
+ "weekly (loopctl would answer daily), a date that is not a real YYYY-MM-DD (loopctl " +
10769
+ "would drop it and answer for all time), and a bad page or page_size.",
10770
+ inputSchema: {
10771
+ type: "object",
10772
+ properties: {
10773
+ granularity: {
10774
+ type: "string",
10775
+ enum: ["daily", "weekly"],
10776
+ description: "Optional: daily (default) or weekly.",
10777
+ },
10778
+ project_id: {
10779
+ type: "string",
10780
+ description: "Optional: one project (UUID, slug or repo name).",
10781
+ },
10782
+ since: { type: "string", description: "Optional start date, YYYY-MM-DD." },
10783
+ until: { type: "string", description: "Optional end date, YYYY-MM-DD." },
10784
+ page: { type: "integer", description: "Optional page number (default 1)." },
10785
+ page_size: { type: "integer", description: "Optional page size, 1..100 (default 20)." },
10786
+ },
10787
+ required: [],
10788
+ },
10789
+ },
10790
+ {
10791
+ name: "model_mix",
10792
+ description:
10793
+ "READ THE MODEL-MIX MATRIX (GET /api/v1/analytics/model-mix): token and cost totals, " +
10794
+ "story counts and verification outcomes per (model_name, phase), plus a comparison of " +
10795
+ "agents that mix models against agents that use one. Optional `project_id` (UUID, slug " +
10796
+ "or repo name), `agent_id` (UUID), `since` and `until` (YYYY-MM-DD). Needs an " +
10797
+ "ORCHESTRATOR-role key or higher, keyed as cost_trends; an agent key is 403 " +
10798
+ "insufficient_role. 422 for a project_id naming no project. Refused by the tool, " +
10799
+ "sending nothing: a non-UUID agent_id and a date that is not a real YYYY-MM-DD.",
10800
+ inputSchema: {
10801
+ type: "object",
10802
+ properties: {
10803
+ project_id: {
10804
+ type: "string",
10805
+ description: "Optional: one project (UUID, slug or repo name).",
10806
+ },
10807
+ agent_id: { type: "string", description: "Optional: one agent's UUID." },
10808
+ since: { type: "string", description: "Optional start date, YYYY-MM-DD." },
10809
+ until: { type: "string", description: "Optional end date, YYYY-MM-DD." },
10810
+ },
10811
+ required: [],
10812
+ },
10813
+ },
10814
+ {
10815
+ name: "agent_model_profile",
10816
+ description:
10817
+ "READ ONE AGENT'S MODEL PROFILE (GET /api/v1/analytics/agents/:id/model-profile): the " +
10818
+ "models it used across phases, `model_count` and `is_model_blender` (more than one " +
10819
+ "model). Optional `project_id` (UUID, slug or repo name), `since` and `until` " +
10820
+ "(YYYY-MM-DD). Needs an ORCHESTRATOR-role key or higher, keyed as cost_trends; an " +
10821
+ "agent key is 403 insufficient_role. 404 for an agent that is not this tenant's, 422 " +
10822
+ "for a project_id naming no project. Refused by the tool, sending nothing: a non-UUID " +
10823
+ "`agent_id` and a date that is not a real YYYY-MM-DD.",
10824
+ inputSchema: {
10825
+ type: "object",
10826
+ properties: {
10827
+ agent_id: { type: "string", description: "The agent's UUID." },
10828
+ project_id: {
10829
+ type: "string",
10830
+ description: "Optional: one project (UUID, slug or repo name).",
10831
+ },
10832
+ since: { type: "string", description: "Optional start date, YYYY-MM-DD." },
10833
+ until: { type: "string", description: "Optional end date, YYYY-MM-DD." },
10834
+ },
10835
+ required: ["agent_id"],
10836
+ },
10837
+ },
10318
10838
 
10319
10839
  {
10320
10840
  name: "factory_overview",
@@ -13574,6 +14094,40 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
13574
14094
  return await renameAuthenticatorTool(args);
13575
14095
  case "update_tenant":
13576
14096
  return await updateTenantTool(args);
14097
+ case "webhook_create":
14098
+ return await webhookCreateTool(args);
14099
+ case "webhook_list":
14100
+ return await webhookListTool(args);
14101
+ case "webhook_update":
14102
+ return await webhookUpdateTool(args);
14103
+ case "webhook_delete":
14104
+ return await webhookDeleteTool(args);
14105
+ case "webhook_test":
14106
+ return await webhookTestTool(args);
14107
+ case "webhook_deliveries":
14108
+ return await webhookDeliveriesTool(args);
14109
+ case "token_budget_list":
14110
+ return await tokenBudgetListTool(args);
14111
+ case "token_budget_get":
14112
+ return await tokenBudgetGetTool(args);
14113
+ case "token_budget_update":
14114
+ return await tokenBudgetUpdateTool(args);
14115
+ case "token_budget_delete":
14116
+ return await tokenBudgetDeleteTool(args);
14117
+ case "token_usage_delete":
14118
+ return await tokenUsageDeleteTool(args);
14119
+ case "token_usage_correct":
14120
+ return await tokenUsageCorrectTool(args);
14121
+ case "cost_anomaly_resolve":
14122
+ return await costAnomalyResolveTool(args);
14123
+ case "ingestion_anomaly_update":
14124
+ return await ingestionAnomalyUpdateTool(args);
14125
+ case "cost_trends":
14126
+ return await costTrendsTool(args);
14127
+ case "model_mix":
14128
+ return await modelMixTool(args);
14129
+ case "agent_model_profile":
14130
+ return await agentModelProfileTool(args);
13577
14131
  case "factory_overview":
13578
14132
  return await factoryOverviewTool(args);
13579
14133
  case "decisions":