loopctl-mcp-server 1.3.0 → 1.5.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 (3) hide show
  1. package/README.md +16 -4
  2. package/index.js +306 -13
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  MCP (Model Context Protocol) server for [loopctl](https://loopctl.com) -- structural trust for AI development loops.
4
4
 
5
- Wraps the loopctl REST API into 35 typed MCP tools so AI coding agents (Claude Code, etc.) can interact with loopctl without writing curl commands.
5
+ Wraps the loopctl REST API into 41 typed MCP tools so AI coding agents (Claude Code, etc.) can interact with loopctl without writing curl commands.
6
6
 
7
7
  ## Installation
8
8
 
@@ -62,10 +62,11 @@ Or if installed locally:
62
62
  | `LOOPCTL_API_KEY` | Global API key override (if set, always used) | -- |
63
63
  | `LOOPCTL_ORCH_KEY` | Orchestrator role API key (verify, reject, review, import) | -- |
64
64
  | `LOOPCTL_AGENT_KEY` | Agent role API key (contract, claim, start, request-review) | -- |
65
+ | `LOOPCTL_USER_KEY` | User role API key. Required ONLY for destructive admin tools like `knowledge_bulk_publish`. Leave unset if you don't use those tools. | -- |
65
66
 
66
67
  Key resolution priority: `LOOPCTL_API_KEY` > tool-specific key > `LOOPCTL_ORCH_KEY`.
67
68
 
68
- ## Tools (35)
69
+ ## Tools (41)
69
70
 
70
71
  ### Project Tools
71
72
 
@@ -140,12 +141,23 @@ Key resolution priority: `LOOPCTL_API_KEY` > tool-specific key > `LOOPCTL_ORCH_K
140
141
  | Tool | Description |
141
142
  |---|---|
142
143
  | `knowledge_publish` | Publish a draft article, making it visible to all agents. Required: `article_id`. |
143
- | `knowledge_drafts` | List all draft (unpublished) knowledge articles. Optional: `limit`, `offset`. |
144
- | `knowledge_lint` | Run a lint check on the knowledge wiki to identify stale or low-coverage articles. Optional: `project_id`, `stale_days`, `min_coverage`. |
144
+ | `knowledge_bulk_publish` | **Requires `LOOPCTL_USER_KEY`.** Atomically publish up to 100 drafts in a single call. Required: `article_ids` (array). |
145
+ | `knowledge_drafts` | List draft (unpublished) knowledge articles with pagination. Optional: `limit` (default 20, max 20), `offset` (default 0), `project_id`. Returns `meta.total_count`. |
146
+ | `knowledge_lint` | Run a lint check on the knowledge wiki to identify stale or low-coverage articles. Optional: `project_id`, `stale_days`, `min_coverage`, `max_per_category` (default 50, max 500). True totals returned in `summary.total_per_category`. |
145
147
  | `knowledge_export` | Export all knowledge articles as a ZIP archive. Returns a curl command for direct download (ZIP binary cannot be returned as MCP content). Optional: `project_id`. |
146
148
  | `knowledge_ingest` | Submit a URL or raw content for knowledge extraction. Enqueues an Oban job. Required: `source_type`. One of: `url` or `content`. Optional: `project_id`. |
149
+ | `knowledge_ingest_batch` | Submit up to 50 ingestion items in a single request. Each item has the same shape as `knowledge_ingest`. Returns per-item results. Required: `items`. Optional: batch-level `project_id` default. |
147
150
  | `knowledge_ingestion_jobs` | List recent content ingestion jobs (last 7 days, max 50). |
148
151
 
152
+ ### Knowledge Analytics Tools (orchestrator key)
153
+
154
+ | Tool | Description |
155
+ |---|---|
156
+ | `knowledge_analytics_top` | Top accessed knowledge articles for the tenant. Optional: `limit` (default 20, max 100), `since_days` (default 7), `access_type` (`search`, `get`, `context`, `index`). |
157
+ | `knowledge_article_stats` | Per-article usage stats: total accesses, unique agents, by-type breakdown, recent events. Required: `article_id`. |
158
+ | `knowledge_agent_usage` | Per-agent (api_key) knowledge usage: total reads, unique articles, top read articles. Required: `agent_id`. Optional: `limit`, `since_days`. |
159
+ | `knowledge_unused_articles` | Published articles with zero accesses in the window. Optional: `days_unused` (default 30), `limit` (default 50, max 200). |
160
+
149
161
  ### Discovery Tools
150
162
 
151
163
  | Tool | Description |
package/index.js CHANGED
@@ -457,20 +457,34 @@ async function knowledgePublish({ article_id }) {
457
457
  return toContent(result);
458
458
  }
459
459
 
460
- async function knowledgeDrafts({ limit, offset }) {
460
+ async function knowledgeBulkPublish({ article_ids }) {
461
+ const result = await apiCall(
462
+ "POST",
463
+ "/api/v1/knowledge/bulk-publish",
464
+ { article_ids },
465
+ process.env.LOOPCTL_USER_KEY
466
+ );
467
+ return toContent(result);
468
+ }
469
+
470
+ async function knowledgeDrafts({ limit, offset, project_id }) {
461
471
  const params = new URLSearchParams();
462
- if (limit != null) params.set("limit", String(limit));
472
+ params.set(
473
+ "limit",
474
+ String(Math.min(limit ?? MAX_PAGE_SIZE, MAX_PAGE_SIZE))
475
+ );
463
476
  if (offset != null) params.set("offset", String(offset));
464
- const qs = params.toString();
465
- const path = qs ? `/api/v1/knowledge/drafts?${qs}` : "/api/v1/knowledge/drafts";
477
+ if (project_id) params.set("project_id", project_id);
478
+ const path = `/api/v1/knowledge/drafts?${params.toString()}`;
466
479
  const result = await apiCall("GET", path, null, process.env.LOOPCTL_ORCH_KEY);
467
480
  return toContent(result);
468
481
  }
469
482
 
470
- async function knowledgeLint({ project_id, stale_days, min_coverage }) {
483
+ async function knowledgeLint({ project_id, stale_days, min_coverage, max_per_category }) {
471
484
  const params = new URLSearchParams();
472
485
  if (stale_days != null) params.set("stale_days", String(stale_days));
473
486
  if (min_coverage != null) params.set("min_coverage", String(min_coverage));
487
+ if (max_per_category != null) params.set("max_per_category", String(max_per_category));
474
488
  const qs = params.toString();
475
489
  const basePath = project_id
476
490
  ? `/api/v1/projects/${project_id}/knowledge/lint`
@@ -489,11 +503,80 @@ async function knowledgeIngest({ url, content, source_type, project_id }) {
489
503
  return toContent(result);
490
504
  }
491
505
 
506
+ async function knowledgeIngestBatch({ items, project_id }) {
507
+ // If a batch-level project_id is supplied, apply it as a default to every
508
+ // item that doesn't already set its own.
509
+ const resolvedItems = Array.isArray(items)
510
+ ? items.map((item) =>
511
+ project_id && item && item.project_id == null
512
+ ? { ...item, project_id }
513
+ : item
514
+ )
515
+ : items;
516
+
517
+ const result = await apiCall(
518
+ "POST",
519
+ "/api/v1/knowledge/ingest/batch",
520
+ { items: resolvedItems },
521
+ process.env.LOOPCTL_ORCH_KEY
522
+ );
523
+ return toContent(result);
524
+ }
525
+
492
526
  async function knowledgeIngestionJobs() {
493
527
  const result = await apiCall("GET", "/api/v1/knowledge/ingestion-jobs", null, process.env.LOOPCTL_ORCH_KEY);
494
528
  return toContent(result);
495
529
  }
496
530
 
531
+ // --- Knowledge Analytics Tools (orch key) ---
532
+
533
+ async function knowledgeAnalyticsTop({ limit, since_days, access_type } = {}) {
534
+ const params = new URLSearchParams();
535
+ if (limit != null) params.set("limit", String(limit));
536
+ if (since_days != null) params.set("since_days", String(since_days));
537
+ if (access_type) params.set("access_type", access_type);
538
+ const qs = params.toString();
539
+ const path = qs
540
+ ? `/api/v1/knowledge/analytics/top-articles?${qs}`
541
+ : "/api/v1/knowledge/analytics/top-articles";
542
+ const result = await apiCall("GET", path, null, process.env.LOOPCTL_ORCH_KEY);
543
+ return toContent(result);
544
+ }
545
+
546
+ async function knowledgeArticleStats({ article_id }) {
547
+ const result = await apiCall(
548
+ "GET",
549
+ `/api/v1/knowledge/articles/${article_id}/stats`,
550
+ null,
551
+ process.env.LOOPCTL_ORCH_KEY
552
+ );
553
+ return toContent(result);
554
+ }
555
+
556
+ async function knowledgeAgentUsage({ agent_id, limit, since_days } = {}) {
557
+ const params = new URLSearchParams();
558
+ if (limit != null) params.set("limit", String(limit));
559
+ if (since_days != null) params.set("since_days", String(since_days));
560
+ const qs = params.toString();
561
+ const path = qs
562
+ ? `/api/v1/knowledge/analytics/agents/${agent_id}?${qs}`
563
+ : `/api/v1/knowledge/analytics/agents/${agent_id}`;
564
+ const result = await apiCall("GET", path, null, process.env.LOOPCTL_ORCH_KEY);
565
+ return toContent(result);
566
+ }
567
+
568
+ async function knowledgeUnusedArticles({ days_unused, limit } = {}) {
569
+ const params = new URLSearchParams();
570
+ if (days_unused != null) params.set("days_unused", String(days_unused));
571
+ if (limit != null) params.set("limit", String(limit));
572
+ const qs = params.toString();
573
+ const path = qs
574
+ ? `/api/v1/knowledge/analytics/unused-articles?${qs}`
575
+ : "/api/v1/knowledge/analytics/unused-articles";
576
+ const result = await apiCall("GET", path, null, process.env.LOOPCTL_ORCH_KEY);
577
+ return toContent(result);
578
+ }
579
+
497
580
  async function knowledgeExport({ project_id }) {
498
581
  const basePath = project_id
499
582
  ? `/api/v1/projects/${project_id}/knowledge/export`
@@ -1208,20 +1291,51 @@ const TOOLS = [
1208
1291
  required: ["article_id"],
1209
1292
  },
1210
1293
  },
1294
+ {
1295
+ name: "knowledge_bulk_publish",
1296
+ description:
1297
+ "Atomically publish up to 100 draft articles in a single call. " +
1298
+ "REQUIRES LOOPCTL_USER_KEY to be set in the MCP server env (user role — " +
1299
+ "orchestrator role is NOT sufficient for this destructive operation). " +
1300
+ "All articles must be drafts belonging to the tenant; if any fail validation, " +
1301
+ "the entire operation rolls back.",
1302
+ inputSchema: {
1303
+ type: "object",
1304
+ properties: {
1305
+ article_ids: {
1306
+ type: "array",
1307
+ items: { type: "string" },
1308
+ description: "List of draft article UUIDs to publish (max 100).",
1309
+ maxItems: 100,
1310
+ },
1311
+ },
1312
+ required: ["article_ids"],
1313
+ },
1314
+ },
1211
1315
  {
1212
1316
  name: "knowledge_drafts",
1213
1317
  description:
1214
- "List all draft (unpublished) knowledge articles. Requires orchestrator role. Use to review pending articles before publishing.",
1318
+ "List draft (unpublished) knowledge articles. Requires orchestrator role. " +
1319
+ "Returns paginated drafts with total_count in meta. Max 20 per page.",
1215
1320
  inputSchema: {
1216
1321
  type: "object",
1217
1322
  properties: {
1218
1323
  limit: {
1219
1324
  type: "integer",
1220
- description: "Optional: maximum number of drafts to return.",
1325
+ description: "Max drafts per page. Default 20, hard max 20.",
1326
+ default: 20,
1327
+ minimum: 1,
1328
+ maximum: 20,
1221
1329
  },
1222
1330
  offset: {
1223
1331
  type: "integer",
1224
- description: "Optional: pagination offset.",
1332
+ description: "Pagination offset. Default 0.",
1333
+ default: 0,
1334
+ minimum: 0,
1335
+ },
1336
+ project_id: {
1337
+ type: "string",
1338
+ description: "Optional: filter drafts to a specific project UUID.",
1225
1339
  },
1226
1340
  },
1227
1341
  required: [],
@@ -1231,7 +1345,9 @@ const TOOLS = [
1231
1345
  name: "knowledge_lint",
1232
1346
  description:
1233
1347
  "Run a lint check on the knowledge wiki to identify stale, low-coverage, or broken articles. " +
1234
- "Requires orchestrator role. Optionally scoped to a project.",
1348
+ "Requires orchestrator role. Optionally scoped to a project. " +
1349
+ "Each issue category is capped at max_per_category (default 50) with true totals " +
1350
+ "exposed in summary.total_per_category and per-category truncated flags.",
1235
1351
  inputSchema: {
1236
1352
  type: "object",
1237
1353
  properties: {
@@ -1244,10 +1360,18 @@ const TOOLS = [
1244
1360
  description: "Optional: flag articles not updated in this many days as stale.",
1245
1361
  },
1246
1362
  min_coverage: {
1247
- type: "number",
1248
- description: "Optional: minimum required coverage score (0.0-1.0) to flag under-covered articles.",
1249
- minimum: 0,
1250
- maximum: 1,
1363
+ type: "integer",
1364
+ description:
1365
+ "Optional: minimum published articles per category below which a coverage gap is reported (default 3).",
1366
+ minimum: 1,
1367
+ },
1368
+ max_per_category: {
1369
+ type: "integer",
1370
+ description:
1371
+ "Max items per category to return. Default 50, max 500. True totals are still reported in summary.total_per_category.",
1372
+ default: 50,
1373
+ minimum: 1,
1374
+ maximum: 500,
1251
1375
  },
1252
1376
  },
1253
1377
  required: [],
@@ -1300,6 +1424,56 @@ const TOOLS = [
1300
1424
  required: ["source_type"],
1301
1425
  },
1302
1426
  },
1427
+ {
1428
+ name: "knowledge_ingest_batch",
1429
+ description:
1430
+ "Submit up to 50 ingestion items in a single request. Each item follows the same " +
1431
+ "shape as knowledge_ingest (url OR content, source_type required). Returns a " +
1432
+ "per-item result array — individual failures do not abort the batch. " +
1433
+ "Requires orchestrator role.",
1434
+ inputSchema: {
1435
+ type: "object",
1436
+ properties: {
1437
+ items: {
1438
+ type: "array",
1439
+ description: "Array of ingestion items (1-50). Each item must include source_type and exactly one of url or content.",
1440
+ minItems: 1,
1441
+ maxItems: 50,
1442
+ items: {
1443
+ type: "object",
1444
+ properties: {
1445
+ url: {
1446
+ type: "string",
1447
+ description: "URL to fetch content from (exactly one of url or content required).",
1448
+ },
1449
+ content: {
1450
+ type: "string",
1451
+ description: "Raw content to extract from (exactly one of url or content required).",
1452
+ },
1453
+ source_type: {
1454
+ type: "string",
1455
+ description: "Source type (e.g., newsletter, skill, web_article, ingestion). Required.",
1456
+ },
1457
+ project_id: {
1458
+ type: "string",
1459
+ description: "Optional: scope the item to a specific project UUID.",
1460
+ },
1461
+ metadata: {
1462
+ type: "object",
1463
+ description: "Optional metadata map.",
1464
+ },
1465
+ },
1466
+ required: ["source_type"],
1467
+ },
1468
+ },
1469
+ project_id: {
1470
+ type: "string",
1471
+ description: "Optional batch-level default project UUID applied to items that don't specify their own.",
1472
+ },
1473
+ },
1474
+ required: ["items"],
1475
+ },
1476
+ },
1303
1477
  {
1304
1478
  name: "knowledge_ingestion_jobs",
1305
1479
  description:
@@ -1312,6 +1486,106 @@ const TOOLS = [
1312
1486
  },
1313
1487
  },
1314
1488
 
1489
+ // Knowledge Analytics Tools (orchestrator key)
1490
+ {
1491
+ name: "knowledge_analytics_top",
1492
+ description:
1493
+ "Return the top accessed knowledge articles for the tenant. " +
1494
+ "Use to identify which articles agents actually read. Requires orchestrator role.",
1495
+ inputSchema: {
1496
+ type: "object",
1497
+ properties: {
1498
+ limit: {
1499
+ type: "integer",
1500
+ description: "Max rows to return. Default 20, max 100.",
1501
+ minimum: 1,
1502
+ maximum: 100,
1503
+ },
1504
+ since_days: {
1505
+ type: "integer",
1506
+ description: "Look back this many days. Default 7.",
1507
+ minimum: 1,
1508
+ maximum: 365,
1509
+ },
1510
+ access_type: {
1511
+ type: "string",
1512
+ enum: ["search", "get", "context", "index"],
1513
+ description: "Optional: restrict to a single access type.",
1514
+ },
1515
+ },
1516
+ required: [],
1517
+ },
1518
+ },
1519
+ {
1520
+ name: "knowledge_article_stats",
1521
+ description:
1522
+ "Return per-article usage statistics: total accesses, unique agents, " +
1523
+ "by-type breakdown, and the 10 most recent events. Requires orchestrator role.",
1524
+ inputSchema: {
1525
+ type: "object",
1526
+ properties: {
1527
+ article_id: {
1528
+ type: "string",
1529
+ description: "The UUID of the article to inspect.",
1530
+ },
1531
+ },
1532
+ required: ["article_id"],
1533
+ },
1534
+ },
1535
+ {
1536
+ name: "knowledge_agent_usage",
1537
+ description:
1538
+ "Return knowledge usage for a specific agent (api_key): total reads, " +
1539
+ "unique articles, access type breakdown, and top read articles. " +
1540
+ "Requires orchestrator role.",
1541
+ inputSchema: {
1542
+ type: "object",
1543
+ properties: {
1544
+ agent_id: {
1545
+ type: "string",
1546
+ description: "API key UUID identifying the agent identity.",
1547
+ },
1548
+ limit: {
1549
+ type: "integer",
1550
+ description: "Max top articles to return. Default 20, max 100.",
1551
+ minimum: 1,
1552
+ maximum: 100,
1553
+ },
1554
+ since_days: {
1555
+ type: "integer",
1556
+ description: "Look back this many days. Default 7.",
1557
+ minimum: 1,
1558
+ maximum: 365,
1559
+ },
1560
+ },
1561
+ required: ["agent_id"],
1562
+ },
1563
+ },
1564
+ {
1565
+ name: "knowledge_unused_articles",
1566
+ description:
1567
+ "Return published articles that have not been accessed in the configured " +
1568
+ "time window. Use to identify dead-weight knowledge. Requires orchestrator role.",
1569
+ inputSchema: {
1570
+ type: "object",
1571
+ properties: {
1572
+ days_unused: {
1573
+ type: "integer",
1574
+ description: "Window length in days. Default 30.",
1575
+ minimum: 1,
1576
+ maximum: 365,
1577
+ },
1578
+ limit: {
1579
+ type: "integer",
1580
+ description: "Max rows to return. Default 50, max 200.",
1581
+ minimum: 1,
1582
+ maximum: 200,
1583
+ },
1584
+ },
1585
+ required: [],
1586
+ },
1587
+ },
1588
+
1315
1589
  // Discovery Tools
1316
1590
  {
1317
1591
  name: "list_routes",
@@ -1442,6 +1716,9 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
1442
1716
  case "knowledge_publish":
1443
1717
  return await knowledgePublish(args);
1444
1718
 
1719
+ case "knowledge_bulk_publish":
1720
+ return await knowledgeBulkPublish(args);
1721
+
1445
1722
  case "knowledge_drafts":
1446
1723
  return await knowledgeDrafts(args);
1447
1724
 
@@ -1455,9 +1732,25 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
1455
1732
  case "knowledge_ingest":
1456
1733
  return await knowledgeIngest(args);
1457
1734
 
1735
+ case "knowledge_ingest_batch":
1736
+ return await knowledgeIngestBatch(args);
1737
+
1458
1738
  case "knowledge_ingestion_jobs":
1459
1739
  return await knowledgeIngestionJobs();
1460
1740
 
1741
+ // Knowledge Analytics Tools
1742
+ case "knowledge_analytics_top":
1743
+ return await knowledgeAnalyticsTop(args);
1744
+
1745
+ case "knowledge_article_stats":
1746
+ return await knowledgeArticleStats(args);
1747
+
1748
+ case "knowledge_agent_usage":
1749
+ return await knowledgeAgentUsage(args);
1750
+
1751
+ case "knowledge_unused_articles":
1752
+ return await knowledgeUnusedArticles(args);
1753
+
1461
1754
  // Discovery Tools
1462
1755
  case "list_routes":
1463
1756
  return await listRoutes();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "loopctl-mcp-server",
3
- "version": "1.3.0",
3
+ "version": "1.5.0",
4
4
  "description": "MCP server for loopctl — structural trust for AI development loops",
5
5
  "type": "module",
6
6
  "main": "index.js",