@crowley/rag-mcp 1.0.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 (49) hide show
  1. package/dist/api-client.d.ts +4 -0
  2. package/dist/api-client.js +19 -0
  3. package/dist/context-enrichment.d.ts +44 -0
  4. package/dist/context-enrichment.js +190 -0
  5. package/dist/formatters.d.ts +33 -0
  6. package/dist/formatters.js +70 -0
  7. package/dist/index.d.ts +13 -0
  8. package/dist/index.js +109 -0
  9. package/dist/tool-registry.d.ts +20 -0
  10. package/dist/tool-registry.js +123 -0
  11. package/dist/tools/advanced.d.ts +9 -0
  12. package/dist/tools/advanced.js +315 -0
  13. package/dist/tools/agents.d.ts +8 -0
  14. package/dist/tools/agents.js +97 -0
  15. package/dist/tools/analytics.d.ts +9 -0
  16. package/dist/tools/analytics.js +261 -0
  17. package/dist/tools/architecture.d.ts +5 -0
  18. package/dist/tools/architecture.js +720 -0
  19. package/dist/tools/ask.d.ts +9 -0
  20. package/dist/tools/ask.js +256 -0
  21. package/dist/tools/cache.d.ts +5 -0
  22. package/dist/tools/cache.js +98 -0
  23. package/dist/tools/clustering.d.ts +9 -0
  24. package/dist/tools/clustering.js +251 -0
  25. package/dist/tools/confluence.d.ts +9 -0
  26. package/dist/tools/confluence.js +147 -0
  27. package/dist/tools/database.d.ts +5 -0
  28. package/dist/tools/database.js +429 -0
  29. package/dist/tools/feedback.d.ts +9 -0
  30. package/dist/tools/feedback.js +220 -0
  31. package/dist/tools/guidelines.d.ts +5 -0
  32. package/dist/tools/guidelines.js +146 -0
  33. package/dist/tools/indexing.d.ts +9 -0
  34. package/dist/tools/indexing.js +129 -0
  35. package/dist/tools/memory.d.ts +9 -0
  36. package/dist/tools/memory.js +565 -0
  37. package/dist/tools/pm.d.ts +9 -0
  38. package/dist/tools/pm.js +680 -0
  39. package/dist/tools/review.d.ts +8 -0
  40. package/dist/tools/review.js +213 -0
  41. package/dist/tools/search.d.ts +9 -0
  42. package/dist/tools/search.js +377 -0
  43. package/dist/tools/session.d.ts +10 -0
  44. package/dist/tools/session.js +386 -0
  45. package/dist/tools/suggestions.d.ts +9 -0
  46. package/dist/tools/suggestions.js +301 -0
  47. package/dist/types.d.ts +32 -0
  48. package/dist/types.js +4 -0
  49. package/package.json +40 -0
@@ -0,0 +1,220 @@
1
+ /**
2
+ * Feedback tools module - search feedback, memory feedback, query suggestions,
3
+ * and quality metrics.
4
+ */
5
+ import { pct } from "../formatters.js";
6
+ /**
7
+ * Create the feedback tools module with project-specific descriptions.
8
+ */
9
+ export function createFeedbackTools(projectName) {
10
+ const tools = [
11
+ {
12
+ name: "feedback_search",
13
+ description: `Provide feedback on a search result quality for ${projectName}. Helps improve future search results.`,
14
+ inputSchema: {
15
+ type: "object",
16
+ properties: {
17
+ query: {
18
+ type: "string",
19
+ description: "The original search query",
20
+ },
21
+ feedbackType: {
22
+ type: "string",
23
+ enum: ["helpful", "not_helpful", "partially"],
24
+ description: "How helpful the results were",
25
+ },
26
+ file: {
27
+ type: "string",
28
+ description: "The file from results being rated",
29
+ },
30
+ suggestedQuery: {
31
+ type: "string",
32
+ description: "A better query that would have found the right results",
33
+ },
34
+ },
35
+ required: ["query", "feedbackType"],
36
+ },
37
+ },
38
+ {
39
+ name: "feedback_memory",
40
+ description: `Provide feedback on a memory's accuracy for ${projectName}. Helps keep memory quality high.`,
41
+ inputSchema: {
42
+ type: "object",
43
+ properties: {
44
+ memoryId: {
45
+ type: "string",
46
+ description: "The memory ID to provide feedback on",
47
+ },
48
+ feedback: {
49
+ type: "string",
50
+ enum: ["accurate", "outdated", "incorrect"],
51
+ description: "Feedback on the memory's accuracy",
52
+ },
53
+ correction: {
54
+ type: "string",
55
+ description: "Corrected information if the memory is wrong",
56
+ },
57
+ },
58
+ required: ["memoryId", "feedback"],
59
+ },
60
+ },
61
+ {
62
+ name: "suggest_better_query",
63
+ description: `Get query improvement suggestions based on feedback patterns for ${projectName}.`,
64
+ inputSchema: {
65
+ type: "object",
66
+ properties: {
67
+ query: {
68
+ type: "string",
69
+ description: "The query to get suggestions for",
70
+ },
71
+ context: {
72
+ type: "string",
73
+ description: "Additional context about what you are looking for",
74
+ },
75
+ },
76
+ required: ["query"],
77
+ },
78
+ },
79
+ {
80
+ name: "get_quality_metrics",
81
+ description: `Get search and memory quality metrics for ${projectName}.`,
82
+ inputSchema: {
83
+ type: "object",
84
+ properties: {},
85
+ },
86
+ },
87
+ ];
88
+ const handlers = {
89
+ feedback_search: async (args, ctx) => {
90
+ const { query, feedbackType, file, suggestedQuery } = args;
91
+ const response = await ctx.api.post("/api/feedback/search", {
92
+ projectName: ctx.projectName,
93
+ query,
94
+ feedbackType,
95
+ file,
96
+ suggestedQuery,
97
+ });
98
+ const emojis = {
99
+ helpful: "\ud83d\udc4d",
100
+ not_helpful: "\ud83d\udc4e",
101
+ partially: "\ud83e\udd14",
102
+ };
103
+ const emoji = emojis[feedbackType] || "";
104
+ let result = `${emoji} **Search Feedback Recorded**\n\n`;
105
+ result += `- **Query:** ${query}\n`;
106
+ result += `- **Feedback:** ${feedbackType}\n`;
107
+ if (file)
108
+ result += `- **File:** ${file}\n`;
109
+ if (suggestedQuery)
110
+ result += `- **Suggested Query:** ${suggestedQuery}\n`;
111
+ return result;
112
+ },
113
+ feedback_memory: async (args, ctx) => {
114
+ const { memoryId, feedback, correction } = args;
115
+ const response = await ctx.api.post("/api/feedback/memory", {
116
+ projectName: ctx.projectName,
117
+ memoryId,
118
+ feedback,
119
+ correction,
120
+ });
121
+ const emojis = {
122
+ accurate: "\u2705",
123
+ outdated: "\u23f0",
124
+ incorrect: "\u274c",
125
+ };
126
+ const emoji = emojis[feedback] || "";
127
+ let result = `${emoji} **Memory Feedback Recorded**\n\n`;
128
+ result += `- **Memory ID:** ${memoryId}\n`;
129
+ result += `- **Feedback:** ${feedback}\n`;
130
+ if (correction)
131
+ result += `- **Correction:** ${correction}\n`;
132
+ return result;
133
+ },
134
+ suggest_better_query: async (args, ctx) => {
135
+ const { query, context } = args;
136
+ let suggestions = [];
137
+ try {
138
+ const response = await ctx.api.post("/api/query/suggest", {
139
+ projectName: ctx.projectName,
140
+ query,
141
+ context,
142
+ });
143
+ suggestions = response.data.suggestions || [];
144
+ }
145
+ catch {
146
+ // Fallback to query analyze
147
+ }
148
+ if (!suggestions || suggestions.length === 0) {
149
+ try {
150
+ const fallback = await ctx.api.post("/api/query/analyze", {
151
+ projectName: ctx.projectName,
152
+ query,
153
+ context,
154
+ });
155
+ suggestions = fallback.data.suggestions || [];
156
+ }
157
+ catch {
158
+ return "No query suggestions available.";
159
+ }
160
+ }
161
+ if (!suggestions || suggestions.length === 0) {
162
+ return "No query suggestions available.";
163
+ }
164
+ const sourceEmojis = {
165
+ feedback: "\ud83d\udcca",
166
+ pattern: "\ud83d\udd04",
167
+ ai: "\ud83e\udd16",
168
+ };
169
+ let result = `## Query Suggestions\n\n`;
170
+ for (const s of suggestions) {
171
+ const emoji = sourceEmojis[s.source] || "";
172
+ result += `- ${emoji} **${s.query || s.suggestion}**`;
173
+ if (s.confidence)
174
+ result += ` (confidence: ${pct(s.confidence)})`;
175
+ result += "\n";
176
+ }
177
+ return result;
178
+ },
179
+ get_quality_metrics: async (_args, ctx) => {
180
+ const response = await ctx.api.get(`/api/quality/${ctx.projectName}`);
181
+ const data = response.data;
182
+ let result = `## Quality Metrics: ${projectName}\n\n`;
183
+ if (data.searchQuality) {
184
+ const sq = data.searchQuality;
185
+ result += `### Search Quality\n`;
186
+ result += `- Helpful: ${pct(sq.helpfulRate || 0)}\n`;
187
+ result += `- Partially Helpful: ${pct(sq.partialRate || 0)}\n`;
188
+ result += `- Not Helpful: ${pct(sq.notHelpfulRate || 0)}\n\n`;
189
+ }
190
+ if (data.memoryQuality) {
191
+ const mq = data.memoryQuality;
192
+ result += `### Memory Quality\n`;
193
+ result += `- Accuracy: ${pct(mq.accuracyRate || 0)}\n`;
194
+ result += `- Outdated: ${pct(mq.outdatedRate || 0)}\n`;
195
+ result += `- Incorrect: ${pct(mq.incorrectRate || 0)}\n\n`;
196
+ }
197
+ if (data.trends) {
198
+ const trendEmojis = {
199
+ up: "\ud83d\udcc8",
200
+ down: "\ud83d\udcc9",
201
+ flat: "\u27a1\ufe0f",
202
+ };
203
+ result += `### Trends\n`;
204
+ for (const [metric, direction] of Object.entries(data.trends)) {
205
+ const emoji = trendEmojis[direction] || "\u27a1\ufe0f";
206
+ result += `- ${emoji} ${metric}: ${direction}\n`;
207
+ }
208
+ result += "\n";
209
+ }
210
+ if (data.problematicQueries && data.problematicQueries.length > 0) {
211
+ result += `### Problematic Queries\n`;
212
+ for (const q of data.problematicQueries) {
213
+ result += `- "${q.query}" (${q.count || 0} times)\n`;
214
+ }
215
+ }
216
+ return result;
217
+ },
218
+ };
219
+ return { tools, handlers };
220
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * RAG Guidelines Tool
3
+ */
4
+ import type { ToolModule } from "../types.js";
5
+ export declare function createGuidelinesTools(projectName: string): ToolModule;
@@ -0,0 +1,146 @@
1
+ /**
2
+ * RAG Guidelines Tool
3
+ */
4
+ export function createGuidelinesTools(projectName) {
5
+ const tools = [
6
+ {
7
+ name: "get_rag_guidelines",
8
+ description: `Get recommended settings and best practices for working with RAG in ${projectName}. Shows optimal tool usage patterns, query strategies, and session management tips.`,
9
+ inputSchema: {
10
+ type: "object",
11
+ properties: {
12
+ focus: {
13
+ type: "string",
14
+ enum: ["all", "search", "memory", "session", "feedback", "performance"],
15
+ description: "Focus area for guidelines (default: all)",
16
+ default: "all",
17
+ },
18
+ context: {
19
+ type: "string",
20
+ enum: ["coding", "debugging", "reviewing", "learning", "documenting"],
21
+ description: "Current work context for tailored recommendations",
22
+ },
23
+ },
24
+ },
25
+ },
26
+ ];
27
+ const handlers = {
28
+ get_rag_guidelines: async (args, ctx) => {
29
+ const { focus = "all", context } = args;
30
+ let result = `# 📚 RAG Guidelines for ${ctx.projectName}\n\n`;
31
+ if (context) {
32
+ const contextTips = {
33
+ coding: "🔧 **Mode: Coding** - Focus on implementation patterns and related code",
34
+ debugging: "🐛 **Mode: Debugging** - Focus on error patterns and similar issues",
35
+ reviewing: "👀 **Mode: Reviewing** - Focus on patterns, ADRs, and best practices",
36
+ learning: "📖 **Mode: Learning** - Focus on documentation and explanations",
37
+ documenting: "📝 **Mode: Documenting** - Focus on existing docs and patterns",
38
+ };
39
+ result += `${contextTips[context] || ""}\n\n`;
40
+ }
41
+ if (focus === "all" || focus === "search") {
42
+ result += `## 🔍 Search Best Practices\n\n`;
43
+ result += `### Query Formulation\n`;
44
+ result += `- **Be specific**: "authentication middleware express" > "auth code"\n`;
45
+ result += `- **Include context**: Add file types, modules, or features\n`;
46
+ result += `- **Use technical terms**: Match actual code terminology\n`;
47
+ result += `- **Combine concepts**: "error handling async database"\n\n`;
48
+ result += `### Tool Selection\n`;
49
+ result += `| Goal | Tool | When |\n`;
50
+ result += `|------|------|------|\n`;
51
+ result += `| Find code | \`search_codebase\` | General code search |\n`;
52
+ result += `| Find similar | \`search_similar\` | Have code snippet |\n`;
53
+ result += `| Understand | \`ask_codebase\` | Need explanation |\n`;
54
+ result += `| Find feature | \`find_feature\` | Know what it does |\n`;
55
+ result += `| Group by file | \`grouped_search\` | Overview needed |\n`;
56
+ result += `| Exact + semantic | \`hybrid_search\` | Specific terms |\n\n`;
57
+ }
58
+ if (focus === "all" || focus === "memory") {
59
+ result += `## 🧠 Memory Best Practices\n\n`;
60
+ result += `### What to Remember\n`;
61
+ result += `| Type | Use For | Example |\n`;
62
+ result += `|------|---------|----------|\n`;
63
+ result += `| \`decision\` | Architecture choices | "Use WebSocket for real-time" |\n`;
64
+ result += `| \`insight\` | Learned patterns | "Service X fails under load" |\n`;
65
+ result += `| \`context\` | Project knowledge | "Module Y handles payments" |\n`;
66
+ result += `| \`todo\` | Tasks to track | "Refactor auth after v2" |\n`;
67
+ result += `| \`note\` | General notes | "Config in .env.local" |\n\n`;
68
+ result += `### Architecture Knowledge\n`;
69
+ result += `- Record ADRs: \`record_adr\` for major decisions\n`;
70
+ result += `- Record patterns: \`record_pattern\` for code structures\n`;
71
+ result += `- Record tech debt: \`record_tech_debt\` for known issues\n`;
72
+ result += `- Check before coding: \`check_architecture\`\n\n`;
73
+ }
74
+ if (focus === "all" || focus === "session") {
75
+ result += `## 📋 Session Management\n\n`;
76
+ result += `### Recommended Workflow\n`;
77
+ result += `\`\`\`\n`;
78
+ result += `1. start_session # Begin with context\n`;
79
+ result += `2. warm_cache # Pre-load embeddings\n`;
80
+ result += `3. ... work ... # Tools auto-track activity\n`;
81
+ result += `4. end_session # Save learnings, get summary\n`;
82
+ result += `\`\`\`\n\n`;
83
+ }
84
+ if (focus === "all" || focus === "feedback") {
85
+ result += `## 👍 Feedback Guidelines\n\n`;
86
+ result += `| Result Quality | Action |\n`;
87
+ result += `|----------------|--------|\n`;
88
+ result += `| Found what needed | \`feedback_search\` -> helpful |\n`;
89
+ result += `| Partially useful | \`feedback_search\` -> partially_helpful |\n`;
90
+ result += `| Not relevant | \`feedback_search\` -> not_helpful + better query |\n\n`;
91
+ }
92
+ if (focus === "all" || focus === "performance") {
93
+ result += `## ⚡ Performance Optimization\n\n`;
94
+ result += `### Expected Performance\n`;
95
+ result += `| Operation | L1 Hit | L2 Hit | Miss |\n`;
96
+ result += `|-----------|--------|--------|------|\n`;
97
+ result += `| Embedding | 1-5ms | 5-15ms | 50-200ms |\n`;
98
+ result += `| Search | 20-50ms | 50-150ms | 100-500ms |\n`;
99
+ result += `| Memory recall | 10-30ms | 30-100ms | 100-300ms |\n\n`;
100
+ }
101
+ if (context) {
102
+ result += `## 🎯 Recommendations for ${context.charAt(0).toUpperCase() + context.slice(1)}\n\n`;
103
+ const contextRecs = {
104
+ coding: [
105
+ "Use `suggest_implementation` before writing new code",
106
+ "Check `suggest_related_code` for dependencies",
107
+ "Run `check_architecture` to validate patterns",
108
+ ],
109
+ debugging: [
110
+ "Search for error messages with `hybrid_search`",
111
+ "Use `ask_codebase` to understand error context",
112
+ "Record solutions as `insight` memories",
113
+ ],
114
+ reviewing: [
115
+ "Check `get_adrs` for architectural decisions",
116
+ "Use `get_patterns` for expected structures",
117
+ "Run `check_architecture` on changes",
118
+ ],
119
+ learning: [
120
+ "Start with `ask_codebase` for explanations",
121
+ "Use `explain_code` for complex snippets",
122
+ "Remember insights for future reference",
123
+ ],
124
+ documenting: [
125
+ "Use `search_docs` for existing documentation",
126
+ "Check `get_patterns` for structure templates",
127
+ "Record new patterns with `record_pattern`",
128
+ ],
129
+ };
130
+ const recs = contextRecs[context] || [];
131
+ recs.forEach((rec, i) => {
132
+ result += `${i + 1}. ${rec}\n`;
133
+ });
134
+ result += "\n";
135
+ }
136
+ result += `## 📌 Quick Reference\n\n`;
137
+ result += `- \`search_codebase\` - Find code\n`;
138
+ result += `- \`ask_codebase\` - Get explanations\n`;
139
+ result += `- \`remember\` - Save knowledge\n`;
140
+ result += `- \`recall\` - Retrieve knowledge\n`;
141
+ result += `- \`suggest_better_query\` - Improve searches\n`;
142
+ return result;
143
+ },
144
+ };
145
+ return { tools, handlers };
146
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Indexing tools module - codebase indexing, status, zero-downtime reindex,
3
+ * and alias management.
4
+ */
5
+ import type { ToolModule } from "../types.js";
6
+ /**
7
+ * Create the indexing tools module with project-specific descriptions.
8
+ */
9
+ export declare function createIndexingTools(projectName: string): ToolModule;
@@ -0,0 +1,129 @@
1
+ /**
2
+ * Indexing tools module - codebase indexing, status, zero-downtime reindex,
3
+ * and alias management.
4
+ */
5
+ /**
6
+ * Create the indexing tools module with project-specific descriptions.
7
+ */
8
+ export function createIndexingTools(projectName) {
9
+ const tools = [
10
+ {
11
+ name: "index_codebase",
12
+ description: `Index or re-index the ${projectName} codebase for RAG search.`,
13
+ inputSchema: {
14
+ type: "object",
15
+ properties: {
16
+ path: {
17
+ type: "string",
18
+ description: "Path to index (default: entire project)",
19
+ },
20
+ force: {
21
+ type: "boolean",
22
+ description: "Force re-index even if already indexed",
23
+ default: false,
24
+ },
25
+ },
26
+ },
27
+ },
28
+ {
29
+ name: "get_index_status",
30
+ description: `Get the indexing status for ${projectName} codebase.`,
31
+ inputSchema: {
32
+ type: "object",
33
+ properties: {},
34
+ },
35
+ },
36
+ {
37
+ name: "reindex_zero_downtime",
38
+ description: `Reindex ${projectName} codebase with zero downtime using alias swap.`,
39
+ inputSchema: {
40
+ type: "object",
41
+ properties: {
42
+ path: {
43
+ type: "string",
44
+ description: "Path to index (default: entire project)",
45
+ },
46
+ patterns: {
47
+ type: "array",
48
+ items: { type: "string" },
49
+ description: "File patterns to include (e.g., ['**/*.ts', '**/*.py'])",
50
+ },
51
+ excludePatterns: {
52
+ type: "array",
53
+ items: { type: "string" },
54
+ description: "File patterns to exclude (e.g., ['node_modules/**'])",
55
+ },
56
+ },
57
+ },
58
+ },
59
+ {
60
+ name: "list_aliases",
61
+ description: "List all collection aliases and their mappings.",
62
+ inputSchema: {
63
+ type: "object",
64
+ properties: {},
65
+ },
66
+ },
67
+ ];
68
+ const handlers = {
69
+ index_codebase: async (args, ctx) => {
70
+ const { path, force = false } = args;
71
+ const response = await ctx.api.post("/api/index", {
72
+ collection: `${ctx.collectionPrefix}codebase`,
73
+ path: path || ctx.projectPath,
74
+ force,
75
+ });
76
+ const data = response.data;
77
+ let result = `## Indexing ${projectName}\n\n`;
78
+ result += `- **Status:** ${data.status || "started"}\n`;
79
+ result += `- **Files to process:** ${data.filesToProcess ?? "N/A"}\n`;
80
+ return result;
81
+ },
82
+ get_index_status: async (_args, ctx) => {
83
+ const response = await ctx.api.get(`/api/index/status/${ctx.collectionPrefix}codebase`);
84
+ const data = response.data;
85
+ let result = `## Index Status: ${projectName}\n\n`;
86
+ result += `- **Status:** ${data.status || "unknown"}\n`;
87
+ result += `- **Total Files:** ${data.totalFiles ?? "N/A"}\n`;
88
+ result += `- **Indexed Files:** ${data.indexedFiles ?? "N/A"}\n`;
89
+ result += `- **Last Updated:** ${data.lastUpdated ? new Date(data.lastUpdated).toLocaleString() : "Never"}\n`;
90
+ result += `- **Vector Count:** ${data.vectorCount ?? "N/A"}\n`;
91
+ return result;
92
+ },
93
+ reindex_zero_downtime: async (args, ctx) => {
94
+ const { path, patterns, excludePatterns } = args;
95
+ const response = await ctx.api.post("/api/reindex", {
96
+ collection: `${ctx.collectionPrefix}codebase`,
97
+ path: path || ctx.projectPath,
98
+ patterns,
99
+ excludePatterns,
100
+ });
101
+ const data = response.data;
102
+ let result = `## Zero-Downtime Reindex: ${projectName}\n\n`;
103
+ result += `- **Alias:** ${data.alias || "N/A"}\n`;
104
+ result += `- **Status:** ${data.status || "started"}\n`;
105
+ result += `- **Message:** ${data.message || "Reindex initiated"}\n`;
106
+ return result;
107
+ },
108
+ list_aliases: async (_args, ctx) => {
109
+ const response = await ctx.api.get("/api/aliases");
110
+ const aliases = response.data.aliases || response.data;
111
+ if (!aliases || (Array.isArray(aliases) && aliases.length === 0)) {
112
+ return "No aliases configured.";
113
+ }
114
+ let result = `## Collection Aliases\n\n`;
115
+ if (Array.isArray(aliases)) {
116
+ for (const a of aliases) {
117
+ result += `- **${a.alias}** -> ${a.collection}\n`;
118
+ }
119
+ }
120
+ else {
121
+ for (const [alias, collection] of Object.entries(aliases)) {
122
+ result += `- **${alias}** -> ${collection}\n`;
123
+ }
124
+ }
125
+ return result;
126
+ },
127
+ };
128
+ return { tools, handlers };
129
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Memory tools module - Agent memory management tools.
3
+ *
4
+ * Tools: remember, recall, list_memories, forget, update_todo,
5
+ * batch_remember, validate_memory, review_memories,
6
+ * promote_memory, run_quality_gates, memory_maintenance
7
+ */
8
+ import type { ToolModule } from "../types.js";
9
+ export declare function createMemoryTools(projectName: string): ToolModule;