@afterxleep/doc-bot 1.21.0 → 1.22.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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +92 -50
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@afterxleep/doc-bot",
3
- "version": "1.21.0",
3
+ "version": "1.22.0",
4
4
  "description": "Generic MCP server for intelligent documentation access in any project",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
package/src/index.js CHANGED
@@ -364,13 +364,17 @@ class DocsServer {
364
364
  },
365
365
  {
366
366
  name: 'doc_bot',
367
- description: 'ALWAYS call this first for any task. Returns mandatory project standards (alwaysApply rules) that must be followed, plus a catalog of available documentation tools. Provides intelligent guidance while trusting your judgment on what additional context you need based on your familiarity with the codebase.',
367
+ description: 'ALWAYS call this first for any task. Returns mandatory project standards (alwaysApply rules) that must be followed, plus a catalog of available documentation tools. Provides intelligent guidance while trusting your judgment on what additional context you need based on your familiarity with the codebase. Supports pagination for large rule sets.',
368
368
  inputSchema: {
369
369
  type: 'object',
370
370
  properties: {
371
371
  task: {
372
372
  type: 'string',
373
373
  description: 'What do you need help with? Examples: "create REST API", "understand auth flow", "document this pattern", "find database models"'
374
+ },
375
+ page: {
376
+ type: 'number',
377
+ description: 'Page number for paginated results (default: 1). Use this when the response indicates more pages are available.'
374
378
  }
375
379
  },
376
380
  required: ['task']
@@ -702,11 +706,12 @@ class DocsServer {
702
706
 
703
707
  case 'doc_bot': {
704
708
  const assistantTask = args?.task || '';
709
+ const docBotPage = args?.page || 1;
705
710
  const docBotMandatoryRules = await this.docService.getGlobalRules();
706
711
  return {
707
712
  content: [{
708
713
  type: 'text',
709
- text: this.getIntelligentGatekeeperResponse(assistantTask, docBotMandatoryRules)
714
+ text: this.getIntelligentGatekeeperResponse(assistantTask, docBotMandatoryRules, docBotPage)
710
715
  }]
711
716
  };
712
717
  }
@@ -1249,13 +1254,13 @@ Try:
1249
1254
  return output;
1250
1255
  }
1251
1256
 
1252
- getIntelligentGatekeeperResponse(task, mandatoryRules) {
1257
+ getIntelligentGatekeeperResponse(task, mandatoryRules, page = 1) {
1253
1258
  // Check for administrative/management tasks first
1254
1259
  const isDocsetManagement = /add.*docset|remove.*docset|list.*docset|install.*docset/i.test(task);
1255
1260
  const isRuleManagement = /add.*rule|create.*rule|update.*rule|document.*pattern|capture.*pattern/i.test(task);
1256
1261
  const isDocumentManagement = /refresh.*doc|reload.*doc|index.*doc|get.*index/i.test(task);
1257
1262
 
1258
- // Handle administrative tasks with direct action guidance
1263
+ // Handle administrative tasks with direct action guidance (no pagination needed)
1259
1264
  if (isDocsetManagement) {
1260
1265
  let guidance = `# 📦 Docset Management\n\n`;
1261
1266
 
@@ -1308,64 +1313,101 @@ Try:
1308
1313
  return guidance;
1309
1314
  }
1310
1315
 
1311
- // For coding/general tasks: Return mandatory rules + tool catalog
1312
- let response = `# Mandatory Project Standards\n\n`;
1316
+ // For coding/general tasks: Use smart pagination for mandatory rules
1317
+ const TOKEN_LIMIT = 24000; // Keep under 25K with buffer for tool catalog
1318
+ const toolCatalog = this.getToolCatalog(task);
1319
+ const toolCatalogTokens = TokenEstimator.estimateTokens(toolCatalog);
1313
1320
 
1314
- if (!mandatoryRules || mandatoryRules.length === 0) {
1315
- response += `*No mandatory rules defined for this project.*\n\n`;
1316
- } else {
1317
- response += `These rules apply to ALL code in this project:\n\n`;
1318
- mandatoryRules.forEach((rule, index) => {
1319
- response += `## ${index + 1}. ${rule.metadata?.title || rule.fileName}\n\n`;
1320
- response += `${rule.content}\n\n`;
1321
- if (index < mandatoryRules.length - 1) {
1322
- response += `---\n\n`;
1323
- }
1324
- });
1321
+ // Reserve tokens for tool catalog and headers
1322
+ const availableTokensForRules = TOKEN_LIMIT - toolCatalogTokens - 500;
1323
+
1324
+ // Format rules with pagination
1325
+ const formatRuleContent = (rules) => {
1326
+ let content = `# Mandatory Project Standards\n\n`;
1327
+
1328
+ if (!rules || rules.length === 0) {
1329
+ content += `*No mandatory rules defined for this project.*\n\n`;
1330
+ } else {
1331
+ content += `These rules apply to ALL code in this project:\n\n`;
1332
+ rules.forEach((rule, index) => {
1333
+ content += `## ${index + 1}. ${rule.metadata?.title || rule.fileName}\n\n`;
1334
+ content += `${rule.content}\n\n`;
1335
+ if (index < rules.length - 1) {
1336
+ content += `---\n\n`;
1337
+ }
1338
+ });
1339
+ }
1340
+
1341
+ return content;
1342
+ };
1343
+
1344
+ // Use smart pagination service
1345
+ const paginatedResult = this.paginationService.smartPaginate(
1346
+ mandatoryRules || [],
1347
+ formatRuleContent,
1348
+ page,
1349
+ availableTokensForRules
1350
+ );
1351
+
1352
+ let response = paginatedResult.content;
1353
+
1354
+ // Add pagination info if there are multiple pages
1355
+ if (paginatedResult.hasMore) {
1356
+ response += `\n---\n\n`;
1357
+ response += `📄 **Page ${paginatedResult.page} of ${paginatedResult.totalPages}**\n\n`;
1358
+ response += `⚠️ **More mandatory rules available**: Call \`doc_bot(task: "${task}", page: ${paginatedResult.page + 1})\` to see the next page.\n\n`;
1359
+ response += `💡 You must review ALL pages before proceeding to ensure compliance with all project standards.\n\n`;
1325
1360
  }
1326
1361
 
1327
- response += `---\n\n`;
1328
- response += `## Additional Documentation Tools Available\n\n`;
1329
- response += `You have access to these tools for finding contextual information:\n\n`;
1362
+ // Add tool catalog
1363
+ response += toolCatalog;
1364
+
1365
+ return response;
1366
+ }
1367
+
1368
+ getToolCatalog(task) {
1369
+ let catalog = `---\n\n`;
1370
+ catalog += `## Additional Documentation Tools Available\n\n`;
1371
+ catalog += `You have access to these tools for finding contextual information:\n\n`;
1330
1372
 
1331
- response += `**\`search_documentation(query)\`**\n`;
1332
- response += `- Search project docs for patterns, examples, conventions\n`;
1333
- response += `- Use when: You need to understand how something is implemented in this codebase\n`;
1334
- response += `- Examples: \`search_documentation("authentication")\`, \`search_documentation("validation")\`\n`;
1335
- response += `- Tip: Use technical terms (class names, API names), not descriptions\n\n`;
1373
+ catalog += `**\`search_documentation(query)\`**\n`;
1374
+ catalog += `- Search project docs for patterns, examples, conventions\n`;
1375
+ catalog += `- Use when: You need to understand how something is implemented in this codebase\n`;
1376
+ catalog += `- Examples: \`search_documentation("authentication")\`, \`search_documentation("validation")\`\n`;
1377
+ catalog += `- Tip: Use technical terms (class names, API names), not descriptions\n\n`;
1336
1378
 
1337
- response += `**\`get_file_docs(filePath)\`**\n`;
1338
- response += `- Get file-specific or directory-specific documentation\n`;
1339
- response += `- Use when: Working with specific files and need conventions for that area\n`;
1340
- response += `- Examples: \`get_file_docs("src/components/Auth.tsx")\`, \`get_file_docs("services/**")\`\n\n`;
1379
+ catalog += `**\`get_file_docs(filePath)\`**\n`;
1380
+ catalog += `- Get file-specific or directory-specific documentation\n`;
1381
+ catalog += `- Use when: Working with specific files and need conventions for that area\n`;
1382
+ catalog += `- Examples: \`get_file_docs("src/components/Auth.tsx")\`, \`get_file_docs("services/**")\`\n\n`;
1341
1383
 
1342
- response += `**\`explore_api(apiName)\`**\n`;
1343
- response += `- Deep-dive into framework/API documentation (all methods, properties, examples)\n`;
1344
- response += `- Use when: Using frameworks or APIs you're unfamiliar with\n`;
1345
- response += `- Examples: \`explore_api("URLSession")\`, \`explore_api("React.Component")\`\n\n`;
1384
+ catalog += `**\`explore_api(apiName)\`**\n`;
1385
+ catalog += `- Deep-dive into framework/API documentation (all methods, properties, examples)\n`;
1386
+ catalog += `- Use when: Using frameworks or APIs you're unfamiliar with\n`;
1387
+ catalog += `- Examples: \`explore_api("URLSession")\`, \`explore_api("React.Component")\`\n\n`;
1346
1388
 
1347
- response += `**\`read_specific_document(fileName)\`**\n`;
1348
- response += `- Read full content of a specific documentation file\n`;
1349
- response += `- Use when: Search results show a relevant doc and you need complete details\n`;
1350
- response += `- Examples: \`read_specific_document("api-patterns.md")\`\n\n`;
1389
+ catalog += `**\`read_specific_document(fileName)\`**\n`;
1390
+ catalog += `- Read full content of a specific documentation file\n`;
1391
+ catalog += `- Use when: Search results show a relevant doc and you need complete details\n`;
1392
+ catalog += `- Examples: \`read_specific_document("api-patterns.md")\`\n\n`;
1351
1393
 
1352
- response += `**\`get_global_rules()\`**\n`;
1353
- response += `- Get complete project philosophy and engineering principles\n`;
1354
- response += `- Use when: Making architectural decisions or need comprehensive context\n\n`;
1394
+ catalog += `**\`get_global_rules()\`**\n`;
1395
+ catalog += `- Get complete project philosophy and engineering principles\n`;
1396
+ catalog += `- Use when: Making architectural decisions or need comprehensive context\n\n`;
1355
1397
 
1356
- response += `---\n\n`;
1357
- response += `## Your Task: "${task}"\n\n`;
1358
- response += `**You now have:**\n`;
1359
- response += `✅ Mandatory project standards (above)\n`;
1360
- response += `✅ Tools to explore codebase-specific patterns (listed above)\n\n`;
1398
+ catalog += `---\n\n`;
1399
+ catalog += `## Your Task: "${task}"\n\n`;
1400
+ catalog += `**You now have:**\n`;
1401
+ catalog += `✅ Mandatory project standards (above)\n`;
1402
+ catalog += `✅ Tools to explore codebase-specific patterns (listed above)\n\n`;
1361
1403
 
1362
- response += `**Your decision:**\n`;
1363
- response += `- If you understand how to implement this correctly with the standards above → proceed\n`;
1364
- response += `- If you need to understand existing patterns in this codebase → use the tools above\n\n`;
1404
+ catalog += `**Your decision:**\n`;
1405
+ catalog += `- If you understand how to implement this correctly with the standards above → proceed\n`;
1406
+ catalog += `- If you need to understand existing patterns in this codebase → use the tools above\n\n`;
1365
1407
 
1366
- response += `Remember: You know the codebase context best. Use additional tools only if you need them.\n`;
1408
+ catalog += `Remember: You know the codebase context best. Use additional tools only if you need them.\n`;
1367
1409
 
1368
- return response;
1410
+ return catalog;
1369
1411
  }
1370
1412
 
1371
1413
  async createOrUpdateRule({ fileName, title, description, keywords, alwaysApply, content }) {