mcp-adr-analysis-server 2.1.20 → 2.1.27

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 (253) hide show
  1. package/README.md +63 -0
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/src/config/ai-config.d.ts +54 -6
  4. package/dist/src/config/ai-config.d.ts.map +1 -1
  5. package/dist/src/config/ai-config.js +69 -6
  6. package/dist/src/config/ai-config.js.map +1 -1
  7. package/dist/src/config/ape-descriptions.d.ts +77 -0
  8. package/dist/src/config/ape-descriptions.d.ts.map +1 -0
  9. package/dist/src/config/ape-descriptions.js +177 -0
  10. package/dist/src/config/ape-descriptions.js.map +1 -0
  11. package/dist/src/index.d.ts +40 -0
  12. package/dist/src/index.d.ts.map +1 -1
  13. package/dist/src/index.js +934 -8
  14. package/dist/src/index.js.map +1 -1
  15. package/dist/src/prompts/adr-suggestion-prompts.d.ts +5 -0
  16. package/dist/src/prompts/adr-suggestion-prompts.d.ts.map +1 -1
  17. package/dist/src/prompts/adr-suggestion-prompts.js +22 -1
  18. package/dist/src/prompts/adr-suggestion-prompts.js.map +1 -1
  19. package/dist/src/prompts/prompt-catalog.d.ts +95 -0
  20. package/dist/src/prompts/prompt-catalog.d.ts.map +1 -0
  21. package/dist/src/prompts/prompt-catalog.js +300 -0
  22. package/dist/src/prompts/prompt-catalog.js.map +1 -0
  23. package/dist/src/resources/adrs-discovered-resource.d.ts +124 -0
  24. package/dist/src/resources/adrs-discovered-resource.d.ts.map +1 -0
  25. package/dist/src/resources/adrs-discovered-resource.js +174 -0
  26. package/dist/src/resources/adrs-discovered-resource.js.map +1 -0
  27. package/dist/src/resources/adrs-review-resource.d.ts +82 -0
  28. package/dist/src/resources/adrs-review-resource.d.ts.map +1 -0
  29. package/dist/src/resources/adrs-review-resource.js +160 -0
  30. package/dist/src/resources/adrs-review-resource.js.map +1 -0
  31. package/dist/src/resources/architectural-context-resource.d.ts +95 -0
  32. package/dist/src/resources/architectural-context-resource.d.ts.map +1 -0
  33. package/dist/src/resources/architectural-context-resource.js +428 -0
  34. package/dist/src/resources/architectural-context-resource.js.map +1 -0
  35. package/dist/src/resources/conversation-snapshot-resource.d.ts +92 -0
  36. package/dist/src/resources/conversation-snapshot-resource.d.ts.map +1 -0
  37. package/dist/src/resources/conversation-snapshot-resource.js +122 -0
  38. package/dist/src/resources/conversation-snapshot-resource.js.map +1 -0
  39. package/dist/src/resources/deployment-status-resource.js +1 -1
  40. package/dist/src/resources/deployment-status-resource.js.map +1 -1
  41. package/dist/src/resources/environment-analysis-resource.js +1 -1
  42. package/dist/src/resources/environment-analysis-resource.js.map +1 -1
  43. package/dist/src/resources/knowledge-graph-resource.d.ts +129 -0
  44. package/dist/src/resources/knowledge-graph-resource.d.ts.map +1 -0
  45. package/dist/src/resources/knowledge-graph-resource.js +217 -0
  46. package/dist/src/resources/knowledge-graph-resource.js.map +1 -0
  47. package/dist/src/resources/memory-expand-resource.d.ts +90 -0
  48. package/dist/src/resources/memory-expand-resource.d.ts.map +1 -0
  49. package/dist/src/resources/memory-expand-resource.js +176 -0
  50. package/dist/src/resources/memory-expand-resource.js.map +1 -0
  51. package/dist/src/resources/memory-stats-resource.d.ts +77 -0
  52. package/dist/src/resources/memory-stats-resource.d.ts.map +1 -0
  53. package/dist/src/resources/memory-stats-resource.js +108 -0
  54. package/dist/src/resources/memory-stats-resource.js.map +1 -0
  55. package/dist/src/resources/project-metrics-resource.js +1 -1
  56. package/dist/src/resources/project-metrics-resource.js.map +1 -1
  57. package/dist/src/resources/resource-cache.d.ts.map +1 -1
  58. package/dist/src/resources/resource-cache.js +2 -1
  59. package/dist/src/resources/resource-cache.js.map +1 -1
  60. package/dist/src/resources/server-context-resource.d.ts +69 -0
  61. package/dist/src/resources/server-context-resource.d.ts.map +1 -0
  62. package/dist/src/resources/server-context-resource.js +104 -0
  63. package/dist/src/resources/server-context-resource.js.map +1 -0
  64. package/dist/src/resources/tool-catalog-resource.d.ts +122 -0
  65. package/dist/src/resources/tool-catalog-resource.d.ts.map +1 -0
  66. package/dist/src/resources/tool-catalog-resource.js +167 -0
  67. package/dist/src/resources/tool-catalog-resource.js.map +1 -0
  68. package/dist/src/tools/adr-aggregator-tools.d.ts +185 -0
  69. package/dist/src/tools/adr-aggregator-tools.d.ts.map +1 -0
  70. package/dist/src/tools/adr-aggregator-tools.js +872 -0
  71. package/dist/src/tools/adr-aggregator-tools.js.map +1 -0
  72. package/dist/src/tools/adr-bootstrap-validation-tool.d.ts.map +1 -1
  73. package/dist/src/tools/adr-bootstrap-validation-tool.js +7 -6
  74. package/dist/src/tools/adr-bootstrap-validation-tool.js.map +1 -1
  75. package/dist/src/tools/adr-suggestion-tool.d.ts +5 -0
  76. package/dist/src/tools/adr-suggestion-tool.d.ts.map +1 -1
  77. package/dist/src/tools/adr-suggestion-tool.js +40 -71
  78. package/dist/src/tools/adr-suggestion-tool.js.map +1 -1
  79. package/dist/src/tools/analyze-gaps-tool.d.ts +57 -0
  80. package/dist/src/tools/analyze-gaps-tool.d.ts.map +1 -0
  81. package/dist/src/tools/analyze-gaps-tool.js +727 -0
  82. package/dist/src/tools/analyze-gaps-tool.js.map +1 -0
  83. package/dist/src/tools/bootstrap-validation-loop-tool.d.ts +23 -1
  84. package/dist/src/tools/bootstrap-validation-loop-tool.d.ts.map +1 -1
  85. package/dist/src/tools/bootstrap-validation-loop-tool.js +15 -5
  86. package/dist/src/tools/bootstrap-validation-loop-tool.js.map +1 -1
  87. package/dist/src/tools/ce-mcp-tools.d.ts +291 -0
  88. package/dist/src/tools/ce-mcp-tools.d.ts.map +1 -0
  89. package/dist/src/tools/ce-mcp-tools.js +1188 -0
  90. package/dist/src/tools/ce-mcp-tools.js.map +1 -0
  91. package/dist/src/tools/content-masking-tool.d.ts +11 -0
  92. package/dist/src/tools/content-masking-tool.d.ts.map +1 -1
  93. package/dist/src/tools/content-masking-tool.js +13 -6
  94. package/dist/src/tools/content-masking-tool.js.map +1 -1
  95. package/dist/src/tools/deployment-readiness-tool.d.ts +11 -0
  96. package/dist/src/tools/deployment-readiness-tool.d.ts.map +1 -1
  97. package/dist/src/tools/deployment-readiness-tool.js +10 -4
  98. package/dist/src/tools/deployment-readiness-tool.js.map +1 -1
  99. package/dist/src/tools/environment-analysis-tool.d.ts +96 -1
  100. package/dist/src/tools/environment-analysis-tool.d.ts.map +1 -1
  101. package/dist/src/tools/environment-analysis-tool.js +38 -46
  102. package/dist/src/tools/environment-analysis-tool.js.map +1 -1
  103. package/dist/src/tools/research-question-tool.d.ts.map +1 -1
  104. package/dist/src/tools/research-question-tool.js +3 -2
  105. package/dist/src/tools/research-question-tool.js.map +1 -1
  106. package/dist/src/tools/review-existing-adrs-tool.d.ts +5 -0
  107. package/dist/src/tools/review-existing-adrs-tool.d.ts.map +1 -1
  108. package/dist/src/tools/review-existing-adrs-tool.js +123 -42
  109. package/dist/src/tools/review-existing-adrs-tool.js.map +1 -1
  110. package/dist/src/tools/rule-generation-tool.d.ts.map +1 -1
  111. package/dist/src/tools/rule-generation-tool.js +3 -5
  112. package/dist/src/tools/rule-generation-tool.js.map +1 -1
  113. package/dist/src/tools/search-codebase-tool.d.ts +148 -0
  114. package/dist/src/tools/search-codebase-tool.d.ts.map +1 -0
  115. package/dist/src/tools/search-codebase-tool.js +406 -0
  116. package/dist/src/tools/search-codebase-tool.js.map +1 -0
  117. package/dist/src/tools/smart-git-push-tool-v2.js +1 -1
  118. package/dist/src/tools/smart-git-push-tool-v2.js.map +1 -1
  119. package/dist/src/tools/tool-catalog.d.ts +134 -0
  120. package/dist/src/tools/tool-catalog.d.ts.map +1 -0
  121. package/dist/src/tools/tool-catalog.js +1813 -0
  122. package/dist/src/tools/tool-catalog.js.map +1 -0
  123. package/dist/src/tools/tool-chain-orchestrator.d.ts +11 -2
  124. package/dist/src/tools/tool-chain-orchestrator.d.ts.map +1 -1
  125. package/dist/src/tools/tool-chain-orchestrator.js +11 -2
  126. package/dist/src/tools/tool-chain-orchestrator.js.map +1 -1
  127. package/dist/src/tools/tool-dispatcher.d.ts +98 -0
  128. package/dist/src/tools/tool-dispatcher.d.ts.map +1 -0
  129. package/dist/src/tools/tool-dispatcher.js +229 -0
  130. package/dist/src/tools/tool-dispatcher.js.map +1 -0
  131. package/dist/src/tools/tree-sitter-code-tools.d.ts +184 -0
  132. package/dist/src/tools/tree-sitter-code-tools.d.ts.map +1 -0
  133. package/dist/src/tools/tree-sitter-code-tools.js +642 -0
  134. package/dist/src/tools/tree-sitter-code-tools.js.map +1 -0
  135. package/dist/src/tools/troubleshoot-guided-workflow-tool.d.ts +22 -0
  136. package/dist/src/tools/troubleshoot-guided-workflow-tool.d.ts.map +1 -1
  137. package/dist/src/tools/troubleshoot-guided-workflow-tool.js +20 -3
  138. package/dist/src/tools/troubleshoot-guided-workflow-tool.js.map +1 -1
  139. package/dist/src/tools/update-knowledge-tool.d.ts +89 -0
  140. package/dist/src/tools/update-knowledge-tool.d.ts.map +1 -0
  141. package/dist/src/tools/update-knowledge-tool.js +222 -0
  142. package/dist/src/tools/update-knowledge-tool.js.map +1 -0
  143. package/dist/src/types/adr-aggregator.d.ts +692 -0
  144. package/dist/src/types/adr-aggregator.d.ts.map +1 -0
  145. package/dist/src/types/adr-aggregator.js +8 -0
  146. package/dist/src/types/adr-aggregator.js.map +1 -0
  147. package/dist/src/types/ce-mcp.d.ts +248 -0
  148. package/dist/src/types/ce-mcp.d.ts.map +1 -0
  149. package/dist/src/types/ce-mcp.js +27 -0
  150. package/dist/src/types/ce-mcp.js.map +1 -0
  151. package/dist/src/types/index.d.ts +3 -2
  152. package/dist/src/types/index.d.ts.map +1 -1
  153. package/dist/src/types/memory-entities.d.ts +48 -48
  154. package/dist/src/utils/adr-aggregator-client.d.ts +177 -0
  155. package/dist/src/utils/adr-aggregator-client.d.ts.map +1 -0
  156. package/dist/src/utils/adr-aggregator-client.js +396 -0
  157. package/dist/src/utils/adr-aggregator-client.js.map +1 -0
  158. package/dist/src/utils/adr-context-detector.js +1 -1
  159. package/dist/src/utils/adr-context-detector.js.map +1 -1
  160. package/dist/src/utils/adr-planning-task-integration.d.ts +260 -0
  161. package/dist/src/utils/adr-planning-task-integration.d.ts.map +1 -0
  162. package/dist/src/utils/adr-planning-task-integration.js +466 -0
  163. package/dist/src/utils/adr-planning-task-integration.js.map +1 -0
  164. package/dist/src/utils/adr-timeline-extractor.d.ts.map +1 -1
  165. package/dist/src/utils/adr-timeline-extractor.js +3 -2
  166. package/dist/src/utils/adr-timeline-extractor.js.map +1 -1
  167. package/dist/src/utils/ai-executor.d.ts +10 -0
  168. package/dist/src/utils/ai-executor.d.ts.map +1 -1
  169. package/dist/src/utils/ai-executor.js +14 -3
  170. package/dist/src/utils/ai-executor.js.map +1 -1
  171. package/dist/src/utils/automatic-prompt-engineering.d.ts +5 -0
  172. package/dist/src/utils/automatic-prompt-engineering.d.ts.map +1 -1
  173. package/dist/src/utils/automatic-prompt-engineering.js +10 -90
  174. package/dist/src/utils/automatic-prompt-engineering.js.map +1 -1
  175. package/dist/src/utils/bootstrap-task-integration.d.ts +214 -0
  176. package/dist/src/utils/bootstrap-task-integration.d.ts.map +1 -0
  177. package/dist/src/utils/bootstrap-task-integration.js +365 -0
  178. package/dist/src/utils/bootstrap-task-integration.js.map +1 -0
  179. package/dist/src/utils/config.d.ts +3 -0
  180. package/dist/src/utils/config.d.ts.map +1 -1
  181. package/dist/src/utils/config.js +13 -0
  182. package/dist/src/utils/config.js.map +1 -1
  183. package/dist/src/utils/dag-executor.js +1 -1
  184. package/dist/src/utils/dag-executor.js.map +1 -1
  185. package/dist/src/utils/deployment-task-integration.d.ts +260 -0
  186. package/dist/src/utils/deployment-task-integration.d.ts.map +1 -0
  187. package/dist/src/utils/deployment-task-integration.js +393 -0
  188. package/dist/src/utils/deployment-task-integration.js.map +1 -0
  189. package/dist/src/utils/dynamic-deployment-intelligence.js +1 -1
  190. package/dist/src/utils/dynamic-deployment-intelligence.js.map +1 -1
  191. package/dist/src/utils/enhanced-logging.d.ts +3 -0
  192. package/dist/src/utils/enhanced-logging.d.ts.map +1 -1
  193. package/dist/src/utils/enhanced-logging.js +9 -30
  194. package/dist/src/utils/enhanced-logging.js.map +1 -1
  195. package/dist/src/utils/environment-capability-registry.js +1 -1
  196. package/dist/src/utils/environment-capability-registry.js.map +1 -1
  197. package/dist/src/utils/file-system.d.ts.map +1 -1
  198. package/dist/src/utils/file-system.js +33 -3
  199. package/dist/src/utils/file-system.js.map +1 -1
  200. package/dist/src/utils/git-remote-detector.d.ts +67 -0
  201. package/dist/src/utils/git-remote-detector.d.ts.map +1 -0
  202. package/dist/src/utils/git-remote-detector.js +194 -0
  203. package/dist/src/utils/git-remote-detector.js.map +1 -0
  204. package/dist/src/utils/gitleaks-detector.js +1 -1
  205. package/dist/src/utils/gitleaks-detector.js.map +1 -1
  206. package/dist/src/utils/knowledge-graph-manager.d.ts +13 -0
  207. package/dist/src/utils/knowledge-graph-manager.d.ts.map +1 -1
  208. package/dist/src/utils/knowledge-graph-manager.js +13 -0
  209. package/dist/src/utils/knowledge-graph-manager.js.map +1 -1
  210. package/dist/src/utils/prompt-execution.d.ts +29 -1
  211. package/dist/src/utils/prompt-execution.d.ts.map +1 -1
  212. package/dist/src/utils/prompt-execution.js +29 -1
  213. package/dist/src/utils/prompt-execution.js.map +1 -1
  214. package/dist/src/utils/research-orchestrator.d.ts +87 -1
  215. package/dist/src/utils/research-orchestrator.d.ts.map +1 -1
  216. package/dist/src/utils/research-orchestrator.js +121 -17
  217. package/dist/src/utils/research-orchestrator.js.map +1 -1
  218. package/dist/src/utils/research-task-integration.d.ts +297 -0
  219. package/dist/src/utils/research-task-integration.d.ts.map +1 -0
  220. package/dist/src/utils/research-task-integration.js +449 -0
  221. package/dist/src/utils/research-task-integration.js.map +1 -0
  222. package/dist/src/utils/ripgrep-wrapper.d.ts.map +1 -1
  223. package/dist/src/utils/ripgrep-wrapper.js +17 -3
  224. package/dist/src/utils/ripgrep-wrapper.js.map +1 -1
  225. package/dist/src/utils/sandbox-executor.d.ts +145 -0
  226. package/dist/src/utils/sandbox-executor.d.ts.map +1 -0
  227. package/dist/src/utils/sandbox-executor.js +642 -0
  228. package/dist/src/utils/sandbox-executor.js.map +1 -0
  229. package/dist/src/utils/server-context-generator.d.ts +5 -0
  230. package/dist/src/utils/server-context-generator.d.ts.map +1 -1
  231. package/dist/src/utils/server-context-generator.js +38 -0
  232. package/dist/src/utils/server-context-generator.js.map +1 -1
  233. package/dist/src/utils/task-manager.d.ts +239 -0
  234. package/dist/src/utils/task-manager.d.ts.map +1 -0
  235. package/dist/src/utils/task-manager.js +528 -0
  236. package/dist/src/utils/task-manager.js.map +1 -0
  237. package/dist/src/utils/task-persistence.d.ts +82 -0
  238. package/dist/src/utils/task-persistence.d.ts.map +1 -0
  239. package/dist/src/utils/task-persistence.js +248 -0
  240. package/dist/src/utils/task-persistence.js.map +1 -0
  241. package/dist/src/utils/test-aware-defaults.d.ts +57 -0
  242. package/dist/src/utils/test-aware-defaults.d.ts.map +1 -0
  243. package/dist/src/utils/test-aware-defaults.js +71 -0
  244. package/dist/src/utils/test-aware-defaults.js.map +1 -0
  245. package/dist/src/utils/tree-sitter-analyzer.d.ts +42 -5
  246. package/dist/src/utils/tree-sitter-analyzer.d.ts.map +1 -1
  247. package/dist/src/utils/tree-sitter-analyzer.js +499 -17
  248. package/dist/src/utils/tree-sitter-analyzer.js.map +1 -1
  249. package/package.json +24 -19
  250. package/dist/src/tools/smart-git-push-tool.d.ts +0 -55
  251. package/dist/src/tools/smart-git-push-tool.d.ts.map +0 -1
  252. package/dist/src/tools/smart-git-push-tool.js +0 -1011
  253. package/dist/src/tools/smart-git-push-tool.js.map +0 -1
package/dist/src/index.js CHANGED
@@ -17,12 +17,16 @@ import { CONVERSATION_CONTEXT_SCHEMA } from './types/conversation-context.js';
17
17
  import { maskMcpResponse, createMaskingConfig, } from './utils/output-masking.js';
18
18
  import { loadConfig, validateProjectPath, createLogger, printConfigSummary, } from './utils/config.js';
19
19
  import { KnowledgeGraphManager } from './utils/knowledge-graph-manager.js';
20
+ import { getEnhancedModeDefault, getKnowledgeEnhancementDefault, } from './utils/test-aware-defaults.js';
20
21
  import { StateReinforcementManager } from './utils/state-reinforcement-manager.js';
21
22
  import { ConversationMemoryManager } from './utils/conversation-memory-manager.js';
22
23
  import { MemoryEntityManager } from './utils/memory-entity-manager.js';
23
24
  import { RootManager } from './utils/root-manager.js';
24
25
  import { ServerContextGenerator } from './utils/server-context-generator.js';
25
26
  import { createNoOpContext } from './types/tool-context.js';
27
+ import { executeSearchTools, getSearchToolsDefinition, } from './tools/tool-dispatcher.js';
28
+ import { shouldUseCEMCPDirective, getCEMCPDirective, formatDirectiveResponse, } from './tools/ce-mcp-tools.js';
29
+ import { loadAIConfig, isCEMCPEnabled } from './config/ai-config.js';
26
30
  /**
27
31
  * Get version from package.json
28
32
  */
@@ -166,6 +170,8 @@ export class McpAdrAnalysisServer {
166
170
  this.server.setRequestHandler(ListToolsRequestSchema, async () => {
167
171
  return {
168
172
  tools: [
173
+ // Meta-tool for dynamic tool discovery (CE-MCP Phase 3)
174
+ getSearchToolsDefinition(),
169
175
  {
170
176
  name: 'analyze_project_ecosystem',
171
177
  description: 'Comprehensive recursive project ecosystem analysis with advanced prompting techniques (Knowledge Generation + Reflexion)',
@@ -1388,6 +1394,54 @@ export class McpAdrAnalysisServer {
1388
1394
  required: ['question'],
1389
1395
  },
1390
1396
  },
1397
+ {
1398
+ name: 'search_codebase',
1399
+ description: 'Atomic tool for searching codebase files based on query patterns. Returns raw file matches with relevance scores. Extracted from ResearchOrchestrator per ADR-018.',
1400
+ inputSchema: {
1401
+ type: 'object',
1402
+ properties: {
1403
+ query: {
1404
+ type: 'string',
1405
+ description: 'Search query (e.g., "Docker configuration", "authentication")',
1406
+ },
1407
+ projectPath: {
1408
+ type: 'string',
1409
+ description: 'Path to project root',
1410
+ default: '.',
1411
+ },
1412
+ scope: {
1413
+ type: 'array',
1414
+ items: { type: 'string' },
1415
+ description: 'Optional file scope patterns (e.g., ["src/**", "config/**"])',
1416
+ },
1417
+ includeContent: {
1418
+ type: 'boolean',
1419
+ description: 'Include file content in results',
1420
+ default: false,
1421
+ },
1422
+ maxFiles: {
1423
+ type: 'number',
1424
+ description: 'Maximum files to return',
1425
+ default: 20,
1426
+ minimum: 1,
1427
+ maximum: 100,
1428
+ },
1429
+ enableTreeSitter: {
1430
+ type: 'boolean',
1431
+ description: 'Use tree-sitter for enhanced analysis',
1432
+ default: true,
1433
+ },
1434
+ relevanceThreshold: {
1435
+ type: 'number',
1436
+ description: 'Minimum relevance threshold (0-1)',
1437
+ default: 0.2,
1438
+ minimum: 0,
1439
+ maximum: 1,
1440
+ },
1441
+ },
1442
+ required: ['query'],
1443
+ },
1444
+ },
1391
1445
  {
1392
1446
  name: 'llm_web_search',
1393
1447
  description: 'LLM-managed web search using Firecrawl for cross-platform support',
@@ -2944,6 +2998,48 @@ export class McpAdrAnalysisServer {
2944
2998
  properties: {},
2945
2999
  },
2946
3000
  },
3001
+ {
3002
+ name: 'update_knowledge',
3003
+ description: 'ADR-018: Simple CRUD operations for knowledge graph. Add/remove entities (intents, ADRs, tools, code) and relationships. Use knowledge://graph resource to read current state (zero token cost).',
3004
+ inputSchema: {
3005
+ type: 'object',
3006
+ properties: {
3007
+ operation: {
3008
+ type: 'string',
3009
+ enum: ['add_entity', 'remove_entity', 'add_relationship', 'remove_relationship'],
3010
+ description: 'Type of operation to perform on the knowledge graph',
3011
+ },
3012
+ entity: {
3013
+ type: 'string',
3014
+ description: 'Entity ID (for add_entity/remove_entity operations)',
3015
+ },
3016
+ entityType: {
3017
+ type: 'string',
3018
+ enum: ['intent', 'adr', 'code', 'tool', 'decision'],
3019
+ description: 'Type of entity (required for add_entity operation)',
3020
+ },
3021
+ relationship: {
3022
+ type: 'string',
3023
+ enum: ['implements', 'uses', 'created', 'depends-on', 'supersedes'],
3024
+ description: 'Relationship type (for add_relationship/remove_relationship)',
3025
+ },
3026
+ source: {
3027
+ type: 'string',
3028
+ description: 'Source node ID (for relationship operations)',
3029
+ },
3030
+ target: {
3031
+ type: 'string',
3032
+ description: 'Target node ID (for relationship operations)',
3033
+ },
3034
+ metadata: {
3035
+ type: 'object',
3036
+ description: 'Additional metadata for the entity or relationship',
3037
+ additionalProperties: true,
3038
+ },
3039
+ },
3040
+ required: ['operation'],
3041
+ },
3042
+ },
2947
3043
  {
2948
3044
  name: 'get_server_context',
2949
3045
  description: "Generate a comprehensive context file showing the server's current state, memory, and capabilities. Creates .mcp-server-context.md that can be @ referenced in conversations for instant LLM awareness",
@@ -2972,6 +3068,398 @@ export class McpAdrAnalysisServer {
2972
3068
  },
2973
3069
  },
2974
3070
  },
3071
+ {
3072
+ name: 'get_current_datetime',
3073
+ description: 'Get the current date and time in various formats. Useful for timestamping ADRs, research documents, and other architectural artifacts. Returns ISO 8601, human-readable, and ADR-specific date formats.',
3074
+ inputSchema: {
3075
+ type: 'object',
3076
+ properties: {
3077
+ timezone: {
3078
+ type: 'string',
3079
+ description: 'Timezone for the datetime (e.g., "UTC", "America/New_York", "Europe/London"). Defaults to UTC.',
3080
+ default: 'UTC',
3081
+ },
3082
+ format: {
3083
+ type: 'string',
3084
+ enum: ['iso', 'human', 'adr', 'all'],
3085
+ description: 'Output format: "iso" for ISO 8601, "human" for human-readable, "adr" for ADR date format (YYYY-MM-DD), "all" for all formats',
3086
+ default: 'all',
3087
+ },
3088
+ includeTimestamp: {
3089
+ type: 'boolean',
3090
+ description: 'Include Unix timestamp in milliseconds',
3091
+ default: true,
3092
+ },
3093
+ },
3094
+ },
3095
+ },
3096
+ // Session management tool for dynamic project switching
3097
+ {
3098
+ name: 'set_project_path',
3099
+ description: 'Dynamically set the active project path for the current session. Call this at the start of a session to switch between projects without restarting the server or modifying environment variables. All subsequent tool calls will use this path as the default.',
3100
+ inputSchema: {
3101
+ type: 'object',
3102
+ properties: {
3103
+ path: {
3104
+ type: 'string',
3105
+ description: 'Absolute path to the project directory. Must be an existing directory.',
3106
+ },
3107
+ validatePath: {
3108
+ type: 'boolean',
3109
+ description: 'Whether to validate that the path exists and is a directory (default: true)',
3110
+ default: true,
3111
+ },
3112
+ },
3113
+ required: ['path'],
3114
+ },
3115
+ },
3116
+ // CE-MCP Phase 4: Lazy Prompt Loading Tool
3117
+ {
3118
+ name: 'load_prompt',
3119
+ description: 'Load a specific prompt or prompt section on-demand. Part of CE-MCP lazy loading system that reduces token usage by ~96% by loading prompts only when needed. Use this to retrieve prompt templates for ADR generation, analysis, deployment, and other operations.',
3120
+ inputSchema: {
3121
+ type: 'object',
3122
+ properties: {
3123
+ promptName: {
3124
+ type: 'string',
3125
+ description: 'Name of the prompt to load (e.g., "adr-suggestion", "deployment-analysis", "environment-analysis", "research-question", "rule-generation", "analysis", "security")',
3126
+ enum: [
3127
+ 'adr-suggestion',
3128
+ 'deployment-analysis',
3129
+ 'environment-analysis',
3130
+ 'research-question',
3131
+ 'rule-generation',
3132
+ 'analysis',
3133
+ 'research-integration',
3134
+ 'validated-pattern',
3135
+ 'security',
3136
+ ],
3137
+ },
3138
+ section: {
3139
+ type: 'string',
3140
+ description: 'Specific section within the prompt to load. If not provided, loads the entire prompt. Available sections depend on the prompt.',
3141
+ },
3142
+ estimateOnly: {
3143
+ type: 'boolean',
3144
+ description: 'If true, returns only token estimate without loading the full prompt content',
3145
+ default: false,
3146
+ },
3147
+ },
3148
+ required: ['promptName'],
3149
+ },
3150
+ },
3151
+ // ADR Aggregator Integration Tools (https://adraggregator.com)
3152
+ {
3153
+ name: 'sync_to_aggregator',
3154
+ description: 'Sync ADRs to ADR Aggregator platform (https://adraggregator.com) for centralized tracking, visualization, and team collaboration. Supports incremental and full sync modes with optional metadata.',
3155
+ inputSchema: {
3156
+ type: 'object',
3157
+ properties: {
3158
+ full_sync: {
3159
+ type: 'boolean',
3160
+ description: 'Replace all ADRs instead of incremental sync',
3161
+ default: false,
3162
+ },
3163
+ include_metadata: {
3164
+ type: 'boolean',
3165
+ description: 'Include analysis metadata in sync',
3166
+ default: true,
3167
+ },
3168
+ include_diagrams: {
3169
+ type: 'boolean',
3170
+ description: 'Include Mermaid diagrams (Pro+ tier)',
3171
+ default: false,
3172
+ },
3173
+ include_timeline: {
3174
+ type: 'boolean',
3175
+ description: 'Include timeline/staleness data',
3176
+ default: false,
3177
+ },
3178
+ include_security_scan: {
3179
+ type: 'boolean',
3180
+ description: 'Include security scan results',
3181
+ default: false,
3182
+ },
3183
+ include_code_links: {
3184
+ type: 'boolean',
3185
+ description: 'Include AST-based code links (Pro+ tier)',
3186
+ default: false,
3187
+ },
3188
+ adr_paths: {
3189
+ type: 'array',
3190
+ items: { type: 'string' },
3191
+ description: 'Specific ADR paths to sync (syncs all if not provided)',
3192
+ },
3193
+ projectPath: {
3194
+ type: 'string',
3195
+ description: 'Project path (defaults to PROJECT_PATH)',
3196
+ },
3197
+ },
3198
+ },
3199
+ },
3200
+ {
3201
+ name: 'get_adr_context',
3202
+ description: 'Fetch ADR context from ADR Aggregator including summaries, diagrams, timeline data, and code links. Useful for getting a consolidated view of architectural decisions.',
3203
+ inputSchema: {
3204
+ type: 'object',
3205
+ properties: {
3206
+ include_diagrams: {
3207
+ type: 'boolean',
3208
+ description: 'Include Mermaid diagrams (Pro+ tier)',
3209
+ default: false,
3210
+ },
3211
+ include_timeline: {
3212
+ type: 'boolean',
3213
+ description: 'Include timeline data',
3214
+ default: true,
3215
+ },
3216
+ include_code_links: {
3217
+ type: 'boolean',
3218
+ description: 'Include code links (Pro+ tier)',
3219
+ default: false,
3220
+ },
3221
+ include_research: {
3222
+ type: 'boolean',
3223
+ description: 'Include research context (Pro+ tier)',
3224
+ default: false,
3225
+ },
3226
+ staleness_filter: {
3227
+ type: 'string',
3228
+ enum: ['all', 'fresh', 'stale', 'very_stale'],
3229
+ description: 'Filter by staleness level',
3230
+ default: 'all',
3231
+ },
3232
+ graph_depth: {
3233
+ type: 'number',
3234
+ description: 'Knowledge graph depth (Team tier)',
3235
+ minimum: 1,
3236
+ maximum: 5,
3237
+ },
3238
+ projectPath: {
3239
+ type: 'string',
3240
+ description: 'Project path (defaults to PROJECT_PATH)',
3241
+ },
3242
+ },
3243
+ },
3244
+ },
3245
+ {
3246
+ name: 'get_staleness_report',
3247
+ description: 'Get ADR staleness report from ADR Aggregator with review compliance metrics. Identifies stale ADRs that need attention and provides governance insights.',
3248
+ inputSchema: {
3249
+ type: 'object',
3250
+ properties: {
3251
+ threshold: {
3252
+ type: 'number',
3253
+ description: 'Days threshold for staleness',
3254
+ default: 90,
3255
+ },
3256
+ projectPath: {
3257
+ type: 'string',
3258
+ description: 'Project path (defaults to PROJECT_PATH)',
3259
+ },
3260
+ },
3261
+ },
3262
+ },
3263
+ {
3264
+ name: 'get_adr_templates',
3265
+ description: 'Get domain-specific ADR templates and anti-patterns from ADR Aggregator. Includes best practices for web applications, microservices, APIs, and more. No authentication required.',
3266
+ inputSchema: {
3267
+ type: 'object',
3268
+ properties: {
3269
+ domain: {
3270
+ type: 'string',
3271
+ description: 'Domain filter (web_application, microservices, api, data_platform, etc.)',
3272
+ },
3273
+ },
3274
+ },
3275
+ },
3276
+ {
3277
+ name: 'get_adr_diagrams',
3278
+ description: 'Get Mermaid diagrams for ADRs from ADR Aggregator. Includes workflow, relationship, and impact diagrams. Requires Pro+ tier.',
3279
+ inputSchema: {
3280
+ type: 'object',
3281
+ properties: {
3282
+ adr_path: {
3283
+ type: 'string',
3284
+ description: 'Specific ADR path (returns all if not specified)',
3285
+ },
3286
+ projectPath: {
3287
+ type: 'string',
3288
+ description: 'Project path (defaults to PROJECT_PATH)',
3289
+ },
3290
+ },
3291
+ },
3292
+ },
3293
+ {
3294
+ name: 'validate_adr_compliance',
3295
+ description: 'Validate ADR compliance against implementation via ADR Aggregator. Checks that code actually implements documented decisions. Requires Pro+ tier.',
3296
+ inputSchema: {
3297
+ type: 'object',
3298
+ properties: {
3299
+ adr_paths: {
3300
+ type: 'array',
3301
+ items: { type: 'string' },
3302
+ description: 'Specific ADR paths to validate',
3303
+ },
3304
+ validation_type: {
3305
+ type: 'string',
3306
+ enum: ['implementation', 'architecture', 'security', 'all'],
3307
+ description: 'Type of validation to perform',
3308
+ default: 'all',
3309
+ },
3310
+ projectPath: {
3311
+ type: 'string',
3312
+ description: 'Project path (defaults to PROJECT_PATH)',
3313
+ },
3314
+ },
3315
+ },
3316
+ },
3317
+ {
3318
+ name: 'get_knowledge_graph',
3319
+ description: 'Get cross-repository knowledge graph from ADR Aggregator with analytics and insights. Visualize ADR relationships across repositories. Requires Team tier.',
3320
+ inputSchema: {
3321
+ type: 'object',
3322
+ properties: {
3323
+ scope: {
3324
+ type: 'string',
3325
+ enum: ['repository', 'organization'],
3326
+ description: 'Scope of the graph',
3327
+ default: 'repository',
3328
+ },
3329
+ include_analytics: {
3330
+ type: 'boolean',
3331
+ description: 'Include graph analytics and insights',
3332
+ default: true,
3333
+ },
3334
+ projectPath: {
3335
+ type: 'string',
3336
+ description: 'Project path (defaults to PROJECT_PATH)',
3337
+ },
3338
+ },
3339
+ },
3340
+ },
3341
+ {
3342
+ name: 'update_implementation_status',
3343
+ description: 'Update the implementation status of synced ADRs directly from the IDE. Supports statuses: not_started, in_progress, implemented, deprecated, blocked. Requires Pro+ tier.',
3344
+ inputSchema: {
3345
+ type: 'object',
3346
+ properties: {
3347
+ updates: {
3348
+ type: 'array',
3349
+ items: {
3350
+ type: 'object',
3351
+ properties: {
3352
+ adr_path: {
3353
+ type: 'string',
3354
+ description: 'Path to the ADR file relative to project root',
3355
+ },
3356
+ implementation_status: {
3357
+ type: 'string',
3358
+ enum: [
3359
+ 'not_started',
3360
+ 'in_progress',
3361
+ 'implemented',
3362
+ 'deprecated',
3363
+ 'blocked',
3364
+ ],
3365
+ description: 'New implementation status',
3366
+ },
3367
+ notes: {
3368
+ type: 'string',
3369
+ description: 'Optional notes about the status change',
3370
+ },
3371
+ },
3372
+ required: ['adr_path', 'implementation_status'],
3373
+ },
3374
+ description: 'Array of ADR status updates to apply',
3375
+ },
3376
+ projectPath: {
3377
+ type: 'string',
3378
+ description: 'Project path (defaults to PROJECT_PATH)',
3379
+ },
3380
+ },
3381
+ required: ['updates'],
3382
+ },
3383
+ },
3384
+ {
3385
+ name: 'get_adr_priorities',
3386
+ description: 'Get ADR priorities for roadmap and backlog planning from ADR Aggregator. Returns prioritized ADRs with scores, dependencies, blockers, implementation status, and gap counts.',
3387
+ inputSchema: {
3388
+ type: 'object',
3389
+ properties: {
3390
+ include_ai: {
3391
+ type: 'boolean',
3392
+ description: 'Include AI-based priority recommendations',
3393
+ default: false,
3394
+ },
3395
+ projectPath: {
3396
+ type: 'string',
3397
+ description: 'Project path (defaults to PROJECT_PATH)',
3398
+ },
3399
+ },
3400
+ },
3401
+ },
3402
+ {
3403
+ name: 'analyze_gaps',
3404
+ description: 'Scan local codebase and compare with ADRs to detect bi-directional gaps. Finds: (1) ADR-to-code gaps: file references in ADRs that do not exist, (2) Code-to-ADR gaps: technologies in package.json and architectural patterns without ADR coverage. Reports gaps to ADR Aggregator for tracking.',
3405
+ inputSchema: {
3406
+ type: 'object',
3407
+ properties: {
3408
+ projectPath: {
3409
+ type: 'string',
3410
+ description: 'Project path (defaults to PROJECT_PATH)',
3411
+ },
3412
+ reportToAggregator: {
3413
+ type: 'boolean',
3414
+ description: 'Whether to report gaps to ADR Aggregator',
3415
+ default: true,
3416
+ },
3417
+ includeDismissed: {
3418
+ type: 'boolean',
3419
+ description: 'Include previously dismissed gaps in analysis',
3420
+ default: false,
3421
+ },
3422
+ scanDirectories: {
3423
+ type: 'array',
3424
+ items: { type: 'string' },
3425
+ description: 'Specific directories to scan (defaults to src, lib, app, packages)',
3426
+ },
3427
+ includePatterns: {
3428
+ type: 'array',
3429
+ items: { type: 'string' },
3430
+ description: 'File patterns to include in scan (regex)',
3431
+ },
3432
+ excludePatterns: {
3433
+ type: 'array',
3434
+ items: { type: 'string' },
3435
+ description: 'File patterns to exclude from scan (regex)',
3436
+ },
3437
+ },
3438
+ },
3439
+ },
3440
+ {
3441
+ name: 'get_gaps',
3442
+ description: 'Get current code gaps from ADR Aggregator. Returns gaps with their status (open, dismissed, resolved) for tracking and management.',
3443
+ inputSchema: {
3444
+ type: 'object',
3445
+ properties: {
3446
+ projectPath: {
3447
+ type: 'string',
3448
+ description: 'Project path (defaults to PROJECT_PATH)',
3449
+ },
3450
+ includeDismissed: {
3451
+ type: 'boolean',
3452
+ description: 'Include dismissed gaps',
3453
+ default: false,
3454
+ },
3455
+ includeResolved: {
3456
+ type: 'boolean',
3457
+ description: 'Include resolved gaps',
3458
+ default: false,
3459
+ },
3460
+ },
3461
+ },
3462
+ },
2975
3463
  ],
2976
3464
  };
2977
3465
  });
@@ -3040,6 +3528,18 @@ export class McpAdrAnalysisServer {
3040
3528
  try {
3041
3529
  let response;
3042
3530
  const safeArgs = args || {};
3531
+ // CE-MCP Mode: Check if tool should return directive instead of executing
3532
+ const aiConfig = loadAIConfig();
3533
+ if (isCEMCPEnabled(aiConfig) &&
3534
+ shouldUseCEMCPDirective(name, { mode: aiConfig.executionMode })) {
3535
+ const directive = getCEMCPDirective(name, safeArgs);
3536
+ if (directive) {
3537
+ this.logger.info(`[CE-MCP] Returning directive for tool: ${name}`);
3538
+ return formatDirectiveResponse(directive);
3539
+ }
3540
+ // Fall through to legacy execution if no directive available
3541
+ this.logger.info(`[CE-MCP] No directive available for ${name}, using legacy path`);
3542
+ }
3043
3543
  switch (name) {
3044
3544
  case 'analyze_project_ecosystem':
3045
3545
  response = await this.analyzeProjectEcosystem(safeArgs, context);
@@ -3128,6 +3628,9 @@ export class McpAdrAnalysisServer {
3128
3628
  case 'perform_research':
3129
3629
  response = await this.performResearch(safeArgs, context);
3130
3630
  break;
3631
+ case 'search_codebase':
3632
+ response = await this.searchCodebase(safeArgs);
3633
+ break;
3131
3634
  case 'llm_web_search':
3132
3635
  response = await this.llmWebSearch(safeArgs);
3133
3636
  break;
@@ -3211,9 +3714,89 @@ export class McpAdrAnalysisServer {
3211
3714
  case 'get_memory_stats':
3212
3715
  response = await this.getMemoryStats();
3213
3716
  break;
3717
+ case 'update_knowledge':
3718
+ response = await this.updateKnowledge(safeArgs);
3719
+ break;
3214
3720
  case 'get_server_context':
3215
3721
  response = await this.getServerContext(safeArgs);
3216
3722
  break;
3723
+ case 'get_current_datetime':
3724
+ response = await this.getCurrentDatetime(safeArgs);
3725
+ break;
3726
+ case 'search_tools':
3727
+ response = {
3728
+ content: [
3729
+ {
3730
+ type: 'text',
3731
+ text: JSON.stringify(executeSearchTools(safeArgs), null, 2),
3732
+ },
3733
+ ],
3734
+ };
3735
+ break;
3736
+ case 'set_project_path':
3737
+ response = await this.setProjectPath(safeArgs);
3738
+ break;
3739
+ case 'load_prompt':
3740
+ response = await this.loadPrompt(safeArgs);
3741
+ break;
3742
+ // ADR Aggregator Integration Tools
3743
+ case 'sync_to_aggregator': {
3744
+ const { syncToAggregator } = await import('./tools/adr-aggregator-tools.js');
3745
+ response = { ...(await syncToAggregator(safeArgs, context)) };
3746
+ break;
3747
+ }
3748
+ case 'get_adr_context': {
3749
+ const { getAdrContext } = await import('./tools/adr-aggregator-tools.js');
3750
+ response = { ...(await getAdrContext(safeArgs, context)) };
3751
+ break;
3752
+ }
3753
+ case 'get_staleness_report': {
3754
+ const { getStalenessReport } = await import('./tools/adr-aggregator-tools.js');
3755
+ response = { ...(await getStalenessReport(safeArgs, context)) };
3756
+ break;
3757
+ }
3758
+ case 'get_adr_templates': {
3759
+ const { getAdrTemplates } = await import('./tools/adr-aggregator-tools.js');
3760
+ response = { ...(await getAdrTemplates(safeArgs, context)) };
3761
+ break;
3762
+ }
3763
+ case 'get_adr_diagrams': {
3764
+ const { getAdrDiagrams } = await import('./tools/adr-aggregator-tools.js');
3765
+ response = { ...(await getAdrDiagrams(safeArgs, context)) };
3766
+ break;
3767
+ }
3768
+ case 'validate_adr_compliance': {
3769
+ const { validateAdrCompliance } = await import('./tools/adr-aggregator-tools.js');
3770
+ response = { ...(await validateAdrCompliance(safeArgs, context)) };
3771
+ break;
3772
+ }
3773
+ case 'get_knowledge_graph': {
3774
+ const { getKnowledgeGraph } = await import('./tools/adr-aggregator-tools.js');
3775
+ response = { ...(await getKnowledgeGraph(safeArgs, context)) };
3776
+ break;
3777
+ }
3778
+ case 'update_implementation_status': {
3779
+ const { updateAdrImplementationStatus } = await import('./tools/adr-aggregator-tools.js');
3780
+ response = {
3781
+ ...(await updateAdrImplementationStatus(safeArgs, context)),
3782
+ };
3783
+ break;
3784
+ }
3785
+ case 'get_adr_priorities': {
3786
+ const { getAdrPriorities } = await import('./tools/adr-aggregator-tools.js');
3787
+ response = { ...(await getAdrPriorities(safeArgs, context)) };
3788
+ break;
3789
+ }
3790
+ case 'analyze_gaps': {
3791
+ const { analyzeGaps } = await import('./tools/analyze-gaps-tool.js');
3792
+ response = { ...(await analyzeGaps(safeArgs, context)) };
3793
+ break;
3794
+ }
3795
+ case 'get_gaps': {
3796
+ const { getGaps } = await import('./tools/analyze-gaps-tool.js');
3797
+ response = { ...(await getGaps(safeArgs, context)) };
3798
+ break;
3799
+ }
3217
3800
  default:
3218
3801
  throw new McpAdrError(`Unknown tool: ${name}`, 'UNKNOWN_TOOL');
3219
3802
  }
@@ -3410,6 +3993,13 @@ export class McpAdrAnalysisServer {
3410
3993
  description: 'Base code repository information for a platform pattern including URL, integration instructions, required files, and script entrypoint',
3411
3994
  mimeType: 'application/json',
3412
3995
  },
3996
+ // NEW Knowledge Graph Resource (ADR-018)
3997
+ {
3998
+ uri: 'knowledge://graph',
3999
+ name: 'Knowledge Graph',
4000
+ description: 'Read-only knowledge graph structure with nodes (intents, ADRs, tools, code files) and edges (relationships). Zero token cost for querying graph state. Use update_knowledge tool to modify.',
4001
+ mimeType: 'application/json',
4002
+ },
3413
4003
  ],
3414
4004
  };
3415
4005
  });
@@ -3579,6 +4169,10 @@ export class McpAdrAnalysisServer {
3579
4169
  type: 'text',
3580
4170
  text: `# AI Execution Status Diagnostic
3581
4171
 
4172
+ > **Note**: As of Phase 5, this server uses CE-MCP (Claude-Enriched MCP) mode by default.
4173
+ > In CE-MCP mode, tools return orchestration directives that the host LLM executes directly,
4174
+ > eliminating the need for external API calls. The configuration below applies to legacy mode only.
4175
+
3582
4176
  ## Current Configuration
3583
4177
  - **AI Execution Enabled**: ${status.isEnabled ? '✅ YES' : '❌ NO'}
3584
4178
  - **Has API Key**: ${status.hasApiKey ? '✅ YES' : '❌ NO'}
@@ -4092,7 +4686,9 @@ This guidance ensures your development work is **architecturally aligned**, **qu
4092
4686
  const ctx = context || createNoOpContext();
4093
4687
  // Use configured project path if not provided in args
4094
4688
  const projectPath = args.projectPath || this.config.projectPath;
4095
- const { includePatterns, enhancedMode = true, knowledgeEnhancement = true, learningEnabled = true, technologyFocus = [], analysisDepth = 'comprehensive', includeEnvironment = true, recursiveDepth = 'comprehensive', analysisScope = [],
4689
+ const { includePatterns, enhancedMode = getEnhancedModeDefault(), // Environment-aware default
4690
+ knowledgeEnhancement = getKnowledgeEnhancementDefault(), // Environment-aware default
4691
+ learningEnabled = true, technologyFocus = [], analysisDepth = 'comprehensive', includeEnvironment = true, recursiveDepth = 'comprehensive', analysisScope = [],
4096
4692
  // conversationContext - TODO: implement context integration for ecosystem analysis
4097
4693
  } = args;
4098
4694
  this.logger.info(`Generating comprehensive ecosystem analysis for project at: ${projectPath}`);
@@ -4131,7 +4727,10 @@ This guidance ensures your development work is **architecturally aligned**, **qu
4131
4727
  this.logger.warn('Failed to initialize ADR knowledge base:', error);
4132
4728
  // Don't fail the entire analysis if ADR initialization fails
4133
4729
  }
4134
- // Import advanced prompting utilities if enhanced mode is enabled
4730
+ // DEPRECATED: Legacy context assembly for enhanced mode
4731
+ // This section is part of the OpenRouter execution path and will be removed
4732
+ // in a future release. For CE-MCP mode, use createAnalyzeProjectEcosystemDirective()
4733
+ // from src/tools/ce-mcp-tools.ts instead. See ADR-014.
4135
4734
  let generateArchitecturalKnowledge = null;
4136
4735
  let executeWithReflexion = null;
4137
4736
  let retrieveRelevantMemories = null;
@@ -4698,7 +5297,9 @@ This **outcome-focused approach** ensures architectural work delivers **measurab
4698
5297
  }
4699
5298
  async generateAdrsFromPrd(args, context) {
4700
5299
  const ctx = context || createNoOpContext();
4701
- const { prdPath, enhancedMode = true, promptOptimization = true, knowledgeEnhancement = true, prdType = 'general', } = args;
5300
+ const { prdPath, enhancedMode = getEnhancedModeDefault(), // Environment-aware default
5301
+ promptOptimization = true, knowledgeEnhancement = getKnowledgeEnhancementDefault(), // Environment-aware default
5302
+ prdType = 'general', } = args;
4702
5303
  const outputDirectory = args['outputDirectory'] || this.config.adrDirectory;
4703
5304
  this.logger.info(`Generating enhanced ADRs from PRD: ${prdPath} to ${outputDirectory}`);
4704
5305
  this.logger.info(`Enhancement features - APE: ${promptOptimization}, Knowledge: ${knowledgeEnhancement}, Type: ${prdType}`);
@@ -6182,13 +6783,11 @@ Please provide:
6182
6783
  responseText += `**ADR Directory:** ${adrDirectory}\n`;
6183
6784
  responseText += `**Total ADRs:** ${result.totalAdrs}\n\n`;
6184
6785
  // Add timeline summary
6185
- if (result.adrs.some((adr) => adr.timeline)) {
6186
- const withTimeline = result.adrs.filter((adr) => adr.timeline).length;
6786
+ if (result.adrs.some(adr => adr.timeline)) {
6787
+ const withTimeline = result.adrs.filter(adr => adr.timeline).length;
6187
6788
  responseText += `## Timeline Data\n\n`;
6188
6789
  responseText += `- **ADRs with Timeline:** ${withTimeline}/${result.totalAdrs}\n`;
6189
- const ages = result.adrs
6190
- .filter((adr) => adr.timeline)
6191
- .map((adr) => adr.timeline.age_days);
6790
+ const ages = result.adrs.filter(adr => adr.timeline).map(adr => adr.timeline.age_days);
6192
6791
  if (ages.length > 0) {
6193
6792
  const avgAge = Math.floor(ages.reduce((a, b) => a + b, 0) / ages.length);
6194
6793
  const oldestAge = Math.max(...ages);
@@ -6321,6 +6920,21 @@ Please provide:
6321
6920
  throw new McpAdrError(`Failed to perform research: ${error instanceof Error ? error.message : String(error)}`, 'RESEARCH_EXECUTION_ERROR');
6322
6921
  }
6323
6922
  }
6923
+ /**
6924
+ * Search codebase tool implementation
6925
+ */
6926
+ async searchCodebase(args) {
6927
+ if (!('query' in args) || typeof args['query'] !== 'string') {
6928
+ throw new McpAdrError('Missing required parameter: query', 'INVALID_ARGUMENTS');
6929
+ }
6930
+ try {
6931
+ const { searchCodebaseTool } = await import('./tools/search-codebase-tool.js');
6932
+ return await searchCodebaseTool(args);
6933
+ }
6934
+ catch (error) {
6935
+ throw new McpAdrError(`Failed to search codebase: ${error instanceof Error ? error.message : String(error)}`, 'SEARCH_ERROR');
6936
+ }
6937
+ }
6324
6938
  /**
6325
6939
  * LLM web search tool implementation
6326
6940
  */
@@ -6666,6 +7280,33 @@ Please provide:
6666
7280
  await import('./resources/validated-pattern-by-platform-resource.js');
6667
7281
  await import('./resources/pattern-sources-by-platform-resource.js');
6668
7282
  await import('./resources/pattern-base-code-by-platform-resource.js');
7283
+ // Phase 1 & 2 resources (PR #346)
7284
+ await import('./resources/server-context-resource.js');
7285
+ await import('./resources/memory-stats-resource.js');
7286
+ await import('./resources/conversation-snapshot-resource.js');
7287
+ await import('./resources/tool-catalog-resource.js');
7288
+ await import('./resources/adrs-discovered-resource.js');
7289
+ // Knowledge Graph Resource (ADR-018)
7290
+ const { generateKnowledgeGraphResource } = await import('./resources/knowledge-graph-resource.js');
7291
+ // Handle knowledge://graph specially to inject KnowledgeGraphManager
7292
+ if (uri === 'knowledge://graph') {
7293
+ const url = new globalThis.URL(uri);
7294
+ const result = await generateKnowledgeGraphResource({}, url.searchParams, this.kgManager);
7295
+ return {
7296
+ contents: [
7297
+ {
7298
+ uri,
7299
+ mimeType: result.contentType,
7300
+ text: JSON.stringify(result.data, null, 2),
7301
+ },
7302
+ ],
7303
+ _meta: {
7304
+ lastModified: result.lastModified,
7305
+ etag: result.etag,
7306
+ cacheKey: result.cacheKey,
7307
+ },
7308
+ };
7309
+ }
6669
7310
  // Try routing first (handles templated resources)
6670
7311
  if (resourceRouter.canRoute(uri)) {
6671
7312
  const result = await resourceRouter.route(uri);
@@ -7298,6 +7939,19 @@ This tool has been deprecated and replaced with memory-centric health scoring.
7298
7939
  throw new McpAdrError(`Memory stats retrieval failed: ${error instanceof Error ? error.message : String(error)}`, 'MEMORY_STATS_ERROR');
7299
7940
  }
7300
7941
  }
7942
+ /**
7943
+ * Update Knowledge Tool (ADR-018)
7944
+ * Simple CRUD operations for knowledge graph
7945
+ */
7946
+ async updateKnowledge(args) {
7947
+ try {
7948
+ const { updateKnowledge } = await import('./tools/update-knowledge-tool.js');
7949
+ return await updateKnowledge(args, createNoOpContext(), this.kgManager);
7950
+ }
7951
+ catch (error) {
7952
+ throw new McpAdrError(`Knowledge update failed: ${error instanceof Error ? error.message : String(error)}`, 'KNOWLEDGE_UPDATE_ERROR');
7953
+ }
7954
+ }
7301
7955
  /**
7302
7956
  * Get Server Context Tool
7303
7957
  * Generates comprehensive server context file for LLM @ referencing
@@ -7311,6 +7965,278 @@ This tool has been deprecated and replaced with memory-centric health scoring.
7311
7965
  throw new McpAdrError(`Server context generation failed: ${error instanceof Error ? error.message : String(error)}`, 'SERVER_CONTEXT_ERROR');
7312
7966
  }
7313
7967
  }
7968
+ /**
7969
+ * Get Current Datetime Tool
7970
+ * Returns the current date and time in various formats for ADR generation and timestamping
7971
+ */
7972
+ async getCurrentDatetime(args) {
7973
+ const { timezone = 'UTC', format = 'all', includeTimestamp = true } = args;
7974
+ try {
7975
+ const now = new Date();
7976
+ // Format date for different timezones
7977
+ const formatOptions = {
7978
+ timeZone: timezone,
7979
+ year: 'numeric',
7980
+ month: '2-digit',
7981
+ day: '2-digit',
7982
+ hour: '2-digit',
7983
+ minute: '2-digit',
7984
+ second: '2-digit',
7985
+ hour12: false,
7986
+ };
7987
+ // Get date parts for the specified timezone
7988
+ const formatter = new Intl.DateTimeFormat('en-CA', {
7989
+ timeZone: timezone,
7990
+ year: 'numeric',
7991
+ month: '2-digit',
7992
+ day: '2-digit',
7993
+ });
7994
+ const parts = formatter.formatToParts(now);
7995
+ const year = parts.find(p => p.type === 'year')?.value || '';
7996
+ const month = parts.find(p => p.type === 'month')?.value || '';
7997
+ const day = parts.find(p => p.type === 'day')?.value || '';
7998
+ // ADR date format: YYYY-MM-DD
7999
+ const adrDate = `${year}-${month}-${day}`;
8000
+ // ISO 8601 format
8001
+ const isoDate = now.toISOString();
8002
+ // Human-readable format
8003
+ const humanFormatter = new Intl.DateTimeFormat('en-US', {
8004
+ ...formatOptions,
8005
+ weekday: 'long',
8006
+ month: 'long',
8007
+ });
8008
+ const humanDate = humanFormatter.format(now);
8009
+ // Build response based on requested format
8010
+ let responseData = {};
8011
+ switch (format) {
8012
+ case 'iso':
8013
+ responseData = { iso: isoDate };
8014
+ break;
8015
+ case 'human':
8016
+ responseData = { human: humanDate };
8017
+ break;
8018
+ case 'adr':
8019
+ responseData = { adr: adrDate };
8020
+ break;
8021
+ case 'all':
8022
+ default:
8023
+ responseData = {
8024
+ iso: isoDate,
8025
+ human: humanDate,
8026
+ adr: adrDate,
8027
+ timezone: timezone,
8028
+ };
8029
+ }
8030
+ if (includeTimestamp) {
8031
+ responseData['timestamp'] = now.getTime();
8032
+ }
8033
+ const responseText = `# Current Date and Time
8034
+
8035
+ ## Formats
8036
+ ${format === 'all' || format === 'iso' ? `- **ISO 8601**: ${isoDate}` : ''}
8037
+ ${format === 'all' || format === 'human' ? `- **Human Readable**: ${humanDate}` : ''}
8038
+ ${format === 'all' || format === 'adr' ? `- **ADR Date (YYYY-MM-DD)**: ${adrDate}` : ''}
8039
+ ${format === 'all' ? `- **Timezone**: ${timezone}` : ''}
8040
+ ${includeTimestamp ? `- **Unix Timestamp (ms)**: ${now.getTime()}` : ''}
8041
+
8042
+ ## Usage for ADR Generation
8043
+
8044
+ When generating ADRs, use the ADR date format (\`${adrDate}\`) in the Date field:
8045
+
8046
+ \`\`\`markdown
8047
+ # ADR-XXXX: [Title]
8048
+
8049
+ ## Date
8050
+ ${adrDate}
8051
+
8052
+ ## Status
8053
+ Proposed
8054
+ \`\`\`
8055
+
8056
+ ## Raw Data
8057
+
8058
+ \`\`\`json
8059
+ ${JSON.stringify(responseData, null, 2)}
8060
+ \`\`\`
8061
+ `;
8062
+ return {
8063
+ content: [
8064
+ {
8065
+ type: 'text',
8066
+ text: responseText,
8067
+ },
8068
+ ],
8069
+ };
8070
+ }
8071
+ catch (error) {
8072
+ throw new McpAdrError(`Failed to get current datetime: ${error instanceof Error ? error.message : String(error)}`, 'DATETIME_ERROR');
8073
+ }
8074
+ }
8075
+ /**
8076
+ * Set Project Path Tool - Dynamic Session Configuration
8077
+ *
8078
+ * @description Dynamically sets the active project path for the current session.
8079
+ * This allows switching between projects without restarting the server or modifying
8080
+ * environment variables. Updates both the config and the RootManager.
8081
+ *
8082
+ * @param args - Set project path arguments
8083
+ * @param args.path - Absolute path to the project directory
8084
+ * @param args.validatePath - Whether to validate the path exists (default: true)
8085
+ * @returns Promise<CallToolResult> - Confirmation of the path change
8086
+ */
8087
+ async setProjectPath(args) {
8088
+ const { path: newPath, validatePath = true } = args;
8089
+ const { resolve } = await import('path');
8090
+ try {
8091
+ // Resolve to absolute path
8092
+ const absolutePath = resolve(newPath);
8093
+ const previousPath = this.config.projectPath;
8094
+ // Validate the path if requested
8095
+ if (validatePath) {
8096
+ await validateProjectPath(absolutePath);
8097
+ }
8098
+ // Update the server configuration
8099
+ this.config.projectPath = absolutePath;
8100
+ // Re-initialize the RootManager with the new path
8101
+ this.rootManager = new RootManager(absolutePath, this.config.adrDirectory);
8102
+ this.logger.info(`Project path changed: ${previousPath} -> ${absolutePath}`);
8103
+ const responseText = `# Project Path Updated
8104
+
8105
+ ## Configuration
8106
+ - **Previous Path**: \`${previousPath}\`
8107
+ - **New Path**: \`${absolutePath}\`
8108
+ - **ADR Directory**: \`${this.config.adrDirectory}\`
8109
+ - **Full ADR Path**: \`${resolve(absolutePath, this.config.adrDirectory)}\`
8110
+
8111
+ ## Status
8112
+ ✅ Project path successfully updated for this session.
8113
+
8114
+ ## Note
8115
+ All subsequent tool calls will use this path as the default project path.
8116
+ You can still override it per-tool by passing \`projectPath\` as an argument.
8117
+
8118
+ To make this permanent, set the \`PROJECT_PATH\` environment variable.
8119
+ `;
8120
+ return {
8121
+ content: [
8122
+ {
8123
+ type: 'text',
8124
+ text: responseText,
8125
+ },
8126
+ ],
8127
+ };
8128
+ }
8129
+ catch (error) {
8130
+ throw new McpAdrError(`Failed to set project path: ${error instanceof Error ? error.message : String(error)}`, 'SET_PROJECT_PATH_ERROR');
8131
+ }
8132
+ }
8133
+ /**
8134
+ * Load Prompt Tool - CE-MCP Phase 4 Lazy Loading
8135
+ *
8136
+ * @description Loads prompts on-demand instead of eagerly loading all prompts at startup.
8137
+ * This reduces token usage by ~96% (from 28K tokens to ~1K on-demand).
8138
+ *
8139
+ * @param args - Load prompt arguments
8140
+ * @param args.promptName - Name of the prompt to load
8141
+ * @param args.section - Optional section within the prompt
8142
+ * @param args.estimateOnly - If true, returns only token estimate
8143
+ * @returns Promise<CallToolResult> - Loaded prompt content or estimate
8144
+ */
8145
+ async loadPrompt(args) {
8146
+ const { promptName, section, estimateOnly = false } = args;
8147
+ // Import the prompt catalog dynamically to enable lazy loading
8148
+ const { getPromptLoader, getPromptMetadata, calculateTokenSavings } = await import('./prompts/prompt-catalog.js');
8149
+ const metadata = getPromptMetadata(promptName);
8150
+ if (!metadata) {
8151
+ const availablePrompts = [
8152
+ 'adr-suggestion',
8153
+ 'deployment-analysis',
8154
+ 'environment-analysis',
8155
+ 'research-question',
8156
+ 'rule-generation',
8157
+ 'analysis',
8158
+ 'research-integration',
8159
+ 'validated-pattern',
8160
+ 'security',
8161
+ ];
8162
+ return {
8163
+ content: [
8164
+ {
8165
+ type: 'text',
8166
+ text: JSON.stringify({
8167
+ success: false,
8168
+ error: `Unknown prompt: ${promptName}`,
8169
+ availablePrompts,
8170
+ hint: 'Use one of the available prompt names listed above',
8171
+ }, null, 2),
8172
+ },
8173
+ ],
8174
+ isError: true,
8175
+ };
8176
+ }
8177
+ // If estimate only, return token information without loading
8178
+ if (estimateOnly) {
8179
+ const loader = getPromptLoader();
8180
+ const estimatedTokens = loader.getEstimatedTokens(promptName, section);
8181
+ const savings = calculateTokenSavings([promptName]);
8182
+ return {
8183
+ content: [
8184
+ {
8185
+ type: 'text',
8186
+ text: JSON.stringify({
8187
+ success: true,
8188
+ promptName,
8189
+ section: section || 'full',
8190
+ estimatedTokens,
8191
+ metadata: {
8192
+ file: metadata.file,
8193
+ category: metadata.category,
8194
+ totalTokens: metadata.tokens,
8195
+ availableSections: metadata.sections,
8196
+ loadOnDemand: metadata.loadOnDemand,
8197
+ },
8198
+ tokenSavings: {
8199
+ loaded: savings.loaded,
8200
+ total: savings.total,
8201
+ saved: savings.saved,
8202
+ percentage: `${savings.percentage}%`,
8203
+ },
8204
+ }, null, 2),
8205
+ },
8206
+ ],
8207
+ };
8208
+ }
8209
+ // Load the prompt content
8210
+ try {
8211
+ const loader = getPromptLoader();
8212
+ const content = await loader.loadPrompt(promptName, section);
8213
+ return {
8214
+ content: [
8215
+ {
8216
+ type: 'text',
8217
+ text: `# Loaded Prompt: ${promptName}${section ? ` (section: ${section})` : ''}
8218
+
8219
+ ## Metadata
8220
+ - **Category**: ${metadata.category}
8221
+ - **Estimated Tokens**: ${metadata.tokens}
8222
+ - **Available Sections**: ${metadata.sections.join(', ')}
8223
+
8224
+ ## Content
8225
+
8226
+ ${content}
8227
+
8228
+ ---
8229
+
8230
+ *Loaded on-demand via CE-MCP lazy loading system. Token savings: ~96% compared to eager loading all prompts.*
8231
+ `,
8232
+ },
8233
+ ],
8234
+ };
8235
+ }
8236
+ catch (error) {
8237
+ throw new McpAdrError(`Failed to load prompt '${promptName}'${section ? ` section '${section}'` : ''}: ${error instanceof Error ? error.message : String(error)}`, 'PROMPT_LOAD_ERROR');
8238
+ }
8239
+ }
7314
8240
  }
7315
8241
  /**
7316
8242
  * Main execution function for the MCP ADR Analysis Server