codebase-analyzer-mcp 2.0.4 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +3 -3
- package/.claude-plugin/plugin.json +6 -4
- package/CLAUDE.md +6 -10
- package/README.md +29 -16
- package/agents/analysis/architecture-analyzer.md +1 -1
- package/agents/analysis/dataflow-tracer.md +1 -1
- package/agents/analysis/pattern-detective.md +1 -1
- package/agents/research/codebase-explorer.md +18 -10
- package/commands/analyze.md +8 -8
- package/dist/cli/index.js +530 -54
- package/dist/mcp/server.js +482 -45
- package/package.json +6 -9
- package/skills/codebase-analysis/SKILL.md +27 -94
- package/skills/codebase-analysis/references/api-reference.md +68 -1
- package/commands/compare.md +0 -66
- package/commands/explore.md +0 -64
- package/commands/patterns.md +0 -75
- package/commands/trace.md +0 -65
- package/skills/add-mcp-tool/SKILL.md +0 -209
- package/skills/debugging-analysis/SKILL.md +0 -213
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: add-mcp-tool
|
|
3
|
-
description: This skill guides adding new MCP tools to the codebase-analyzer server. Use when extending the analyzer with new capabilities like new analysis types, query tools, or integrations.
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# Adding MCP Tools
|
|
7
|
-
|
|
8
|
-
## Quick Start
|
|
9
|
-
|
|
10
|
-
To add a new MCP tool:
|
|
11
|
-
|
|
12
|
-
1. Create `src/mcp/tools/your-tool.ts`
|
|
13
|
-
2. Export from `src/mcp/tools/index.ts`
|
|
14
|
-
3. Register in `src/mcp/server.ts`
|
|
15
|
-
4. Add CLI command (optional)
|
|
16
|
-
5. Run `pnpm build`
|
|
17
|
-
|
|
18
|
-
## Step 1: Create Tool File
|
|
19
|
-
|
|
20
|
-
Create `src/mcp/tools/your-tool.ts`:
|
|
21
|
-
|
|
22
|
-
```typescript
|
|
23
|
-
import { z } from "zod";
|
|
24
|
-
import { resolveSource } from "../../core/repo-loader.js";
|
|
25
|
-
|
|
26
|
-
// Schema for MCP tool parameters
|
|
27
|
-
export const yourToolSchema = {
|
|
28
|
-
source: z
|
|
29
|
-
.string()
|
|
30
|
-
.describe("Local path or GitHub URL to the repository"),
|
|
31
|
-
yourParam: z
|
|
32
|
-
.string()
|
|
33
|
-
.optional()
|
|
34
|
-
.describe("Description of parameter"),
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export type YourToolInput = {
|
|
38
|
-
source: string;
|
|
39
|
-
yourParam?: string;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
// Execute function
|
|
43
|
-
export async function executeYourTool(input: YourToolInput): Promise<object> {
|
|
44
|
-
const { source, yourParam } = input;
|
|
45
|
-
|
|
46
|
-
// Resolve source (handles GitHub URLs)
|
|
47
|
-
const { repoPath, cleanup } = await resolveSource(source);
|
|
48
|
-
|
|
49
|
-
try {
|
|
50
|
-
// Your implementation here
|
|
51
|
-
const result = {
|
|
52
|
-
// Your result structure
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
return result;
|
|
56
|
-
} finally {
|
|
57
|
-
// Clean up temp directory if GitHub clone
|
|
58
|
-
if (cleanup) await cleanup();
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
## Step 2: Export from Index
|
|
64
|
-
|
|
65
|
-
Add to `src/mcp/tools/index.ts`:
|
|
66
|
-
|
|
67
|
-
```typescript
|
|
68
|
-
export {
|
|
69
|
-
yourToolSchema,
|
|
70
|
-
executeYourTool,
|
|
71
|
-
type YourToolInput,
|
|
72
|
-
} from "./your-tool.js";
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
## Step 3: Register in Server
|
|
76
|
-
|
|
77
|
-
Add to `src/mcp/server.ts`:
|
|
78
|
-
|
|
79
|
-
```typescript
|
|
80
|
-
import {
|
|
81
|
-
yourToolSchema,
|
|
82
|
-
executeYourTool,
|
|
83
|
-
} from "./tools/index.js";
|
|
84
|
-
|
|
85
|
-
server.tool(
|
|
86
|
-
"your_tool_name",
|
|
87
|
-
"Description of what the tool does",
|
|
88
|
-
{
|
|
89
|
-
source: yourToolSchema.source,
|
|
90
|
-
yourParam: yourToolSchema.yourParam,
|
|
91
|
-
},
|
|
92
|
-
async ({ source, yourParam }) => {
|
|
93
|
-
try {
|
|
94
|
-
const result = await executeYourTool({ source, yourParam });
|
|
95
|
-
return {
|
|
96
|
-
content: [{
|
|
97
|
-
type: "text" as const,
|
|
98
|
-
text: JSON.stringify(result, null, 2),
|
|
99
|
-
}],
|
|
100
|
-
};
|
|
101
|
-
} catch (error) {
|
|
102
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
103
|
-
return {
|
|
104
|
-
content: [{
|
|
105
|
-
type: "text" as const,
|
|
106
|
-
text: `Error: ${message}`,
|
|
107
|
-
}],
|
|
108
|
-
isError: true,
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
);
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
## Step 4: Add CLI Command (Optional)
|
|
116
|
-
|
|
117
|
-
Add to `src/cli/index.ts`:
|
|
118
|
-
|
|
119
|
-
```typescript
|
|
120
|
-
program
|
|
121
|
-
.command("your-command")
|
|
122
|
-
.description("What this command does")
|
|
123
|
-
.argument("<source>", "Local path or GitHub URL")
|
|
124
|
-
.option("-p, --param <value>", "Your parameter")
|
|
125
|
-
.action(async (source: string, options) => {
|
|
126
|
-
try {
|
|
127
|
-
const { executeYourTool } = await import("../mcp/tools/your-tool.js");
|
|
128
|
-
const result = await executeYourTool({
|
|
129
|
-
source,
|
|
130
|
-
yourParam: options.param,
|
|
131
|
-
});
|
|
132
|
-
console.log(JSON.stringify(result, null, 2));
|
|
133
|
-
} catch (error) {
|
|
134
|
-
console.error(error instanceof Error ? error.message : String(error));
|
|
135
|
-
process.exit(1);
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
## Step 5: Add Types (If Needed)
|
|
141
|
-
|
|
142
|
-
Add to `src/types.ts`:
|
|
143
|
-
|
|
144
|
-
```typescript
|
|
145
|
-
export interface YourToolResult {
|
|
146
|
-
// Define your result structure
|
|
147
|
-
}
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
## Patterns to Follow
|
|
151
|
-
|
|
152
|
-
### Use Existing Layers
|
|
153
|
-
|
|
154
|
-
If your tool does analysis, consider using existing layers:
|
|
155
|
-
|
|
156
|
-
```typescript
|
|
157
|
-
import { surfaceAnalysis } from "../../core/layers/index.js";
|
|
158
|
-
|
|
159
|
-
const surface = await surfaceAnalysis(repoPath, { exclude });
|
|
160
|
-
```
|
|
161
|
-
|
|
162
|
-
### Handle Partial Failures
|
|
163
|
-
|
|
164
|
-
Don't throw on every error - capture and continue:
|
|
165
|
-
|
|
166
|
-
```typescript
|
|
167
|
-
const warnings: string[] = [];
|
|
168
|
-
const failures: { area: string; error: string }[] = [];
|
|
169
|
-
|
|
170
|
-
try {
|
|
171
|
-
// risky operation
|
|
172
|
-
} catch (error) {
|
|
173
|
-
failures.push({
|
|
174
|
-
area: "operation-name",
|
|
175
|
-
error: error.message
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
return { result, warnings, failures };
|
|
180
|
-
```
|
|
181
|
-
|
|
182
|
-
### Respect Token Budget
|
|
183
|
-
|
|
184
|
-
Check budget before expensive operations:
|
|
185
|
-
|
|
186
|
-
```typescript
|
|
187
|
-
if (estimatedTokens > tokenBudget) {
|
|
188
|
-
warnings.push(`Estimated tokens (${estimatedTokens}) exceeds budget`);
|
|
189
|
-
}
|
|
190
|
-
```
|
|
191
|
-
|
|
192
|
-
## Testing
|
|
193
|
-
|
|
194
|
-
After adding:
|
|
195
|
-
|
|
196
|
-
```bash
|
|
197
|
-
pnpm build
|
|
198
|
-
pnpm cba your-command ./test-repo
|
|
199
|
-
```
|
|
200
|
-
|
|
201
|
-
## Checklist
|
|
202
|
-
|
|
203
|
-
- [ ] Tool file created with schema and execute function
|
|
204
|
-
- [ ] Exported from index.ts
|
|
205
|
-
- [ ] Registered in server.ts
|
|
206
|
-
- [ ] CLI command added (if applicable)
|
|
207
|
-
- [ ] Types added to types.ts (if needed)
|
|
208
|
-
- [ ] `pnpm build` passes
|
|
209
|
-
- [ ] Tool works via MCP and CLI
|
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: debugging-analysis
|
|
3
|
-
description: This skill helps troubleshoot issues with codebase analysis - failed analyses, incorrect results, performance problems, and Gemini API errors. Use when analysis isn't working as expected.
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# Debugging Analysis Issues
|
|
7
|
-
|
|
8
|
-
## Common Issues
|
|
9
|
-
|
|
10
|
-
### 1. Analysis Fails Immediately
|
|
11
|
-
|
|
12
|
-
**Symptom:** Error on startup, no analysis runs
|
|
13
|
-
|
|
14
|
-
**Check:**
|
|
15
|
-
```bash
|
|
16
|
-
# Verify build
|
|
17
|
-
pnpm build
|
|
18
|
-
|
|
19
|
-
# Check for TypeScript errors
|
|
20
|
-
pnpm tsc --noEmit
|
|
21
|
-
|
|
22
|
-
# Test CLI works
|
|
23
|
-
pnpm cba capabilities
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
**Common causes:**
|
|
27
|
-
- TypeScript compilation errors
|
|
28
|
-
- Missing dependencies (`pnpm install`)
|
|
29
|
-
- Syntax error in recent changes
|
|
30
|
-
|
|
31
|
-
### 2. Gemini API Errors
|
|
32
|
-
|
|
33
|
-
**Symptom:** Semantic analysis fails with API error
|
|
34
|
-
|
|
35
|
-
**Check:**
|
|
36
|
-
```bash
|
|
37
|
-
# Verify API key is set
|
|
38
|
-
echo $GEMINI_API_KEY
|
|
39
|
-
|
|
40
|
-
# Test with explicit key
|
|
41
|
-
GEMINI_API_KEY=your-key pnpm cba analyze . -d deep -s
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
**Common causes:**
|
|
45
|
-
- Missing `GEMINI_API_KEY` environment variable
|
|
46
|
-
- Invalid or expired API key
|
|
47
|
-
- Rate limiting (wait and retry)
|
|
48
|
-
- Network issues
|
|
49
|
-
|
|
50
|
-
**Fix:** Set API key:
|
|
51
|
-
```bash
|
|
52
|
-
export GEMINI_API_KEY=your-key-here
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
### 3. Analysis Returns Empty Results
|
|
56
|
-
|
|
57
|
-
**Symptom:** Analysis completes but sections are empty
|
|
58
|
-
|
|
59
|
-
**Check:**
|
|
60
|
-
```bash
|
|
61
|
-
# Run with verbose output
|
|
62
|
-
pnpm cba analyze . -v
|
|
63
|
-
|
|
64
|
-
# Check surface analysis
|
|
65
|
-
pnpm cba analyze . -d surface
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
**Common causes:**
|
|
69
|
-
- All files excluded by patterns
|
|
70
|
-
- Repository is empty or only has ignored files
|
|
71
|
-
- Focus filter matches nothing
|
|
72
|
-
|
|
73
|
-
**Debug:**
|
|
74
|
-
```typescript
|
|
75
|
-
// In orchestrator.ts, check modulesToAnalyze
|
|
76
|
-
console.log("Modules to analyze:", modulesToAnalyze);
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
### 4. Wrong Repository Name
|
|
80
|
-
|
|
81
|
-
**Symptom:** Shows temp directory name instead of repo name
|
|
82
|
-
|
|
83
|
-
**Check:** Ensure `sourceName` is passed through:
|
|
84
|
-
1. `extractSourceName()` in analyze.ts or cli/index.ts
|
|
85
|
-
2. Passed to `orchestrateAnalysis()` options
|
|
86
|
-
3. Passed to `surfaceAnalysis()` options
|
|
87
|
-
4. Used in `buildRepositoryMap()`
|
|
88
|
-
|
|
89
|
-
### 5. Structural Analysis Slow
|
|
90
|
-
|
|
91
|
-
**Symptom:** Takes too long on large repos
|
|
92
|
-
|
|
93
|
-
**Check:**
|
|
94
|
-
```bash
|
|
95
|
-
# See batch progress
|
|
96
|
-
pnpm cba analyze . -v
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
**Tune:**
|
|
100
|
-
- Reduce `MAX_PARALLEL_STRUCTURAL` in orchestrator.ts
|
|
101
|
-
- Use `--focus` to limit modules
|
|
102
|
-
- Increase `--exclude` patterns
|
|
103
|
-
|
|
104
|
-
### 6. Property Access Errors
|
|
105
|
-
|
|
106
|
-
**Symptom:** `Cannot read properties of undefined`
|
|
107
|
-
|
|
108
|
-
**Debug:**
|
|
109
|
-
```typescript
|
|
110
|
-
// Add defensive checks
|
|
111
|
-
const value = result?.property?.nested ?? defaultValue;
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
**Common pattern:** Type definition doesn't match actual usage
|
|
115
|
-
- Check `src/types.ts` for correct property names
|
|
116
|
-
- Grep for usages of old property names
|
|
117
|
-
|
|
118
|
-
## Debug Mode
|
|
119
|
-
|
|
120
|
-
Enable verbose logging:
|
|
121
|
-
|
|
122
|
-
```bash
|
|
123
|
-
# CLI
|
|
124
|
-
pnpm cba analyze . -v
|
|
125
|
-
|
|
126
|
-
# Programmatic
|
|
127
|
-
logger.setVerbose(true);
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
This shows:
|
|
131
|
-
- Surface analysis progress
|
|
132
|
-
- Structural batch progress
|
|
133
|
-
- Semantic analysis calls
|
|
134
|
-
- Timing information
|
|
135
|
-
|
|
136
|
-
## Log Categories
|
|
137
|
-
|
|
138
|
-
The logger uses categories for filtering:
|
|
139
|
-
|
|
140
|
-
```typescript
|
|
141
|
-
logger.surface("message"); // Surface layer
|
|
142
|
-
logger.structural("message"); // Structural layer
|
|
143
|
-
logger.semantic("message"); // Semantic layer
|
|
144
|
-
logger.orchestrator("message"); // Orchestration
|
|
145
|
-
logger.error("category", "message"); // Errors
|
|
146
|
-
```
|
|
147
|
-
|
|
148
|
-
## Testing Individual Layers
|
|
149
|
-
|
|
150
|
-
### Surface Only
|
|
151
|
-
```bash
|
|
152
|
-
pnpm cba analyze . -d surface
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
### Structural Without Semantic
|
|
156
|
-
```bash
|
|
157
|
-
pnpm cba analyze . -d standard
|
|
158
|
-
```
|
|
159
|
-
|
|
160
|
-
### With Semantic
|
|
161
|
-
```bash
|
|
162
|
-
pnpm cba analyze . -d deep -s
|
|
163
|
-
```
|
|
164
|
-
|
|
165
|
-
## Inspecting Cache
|
|
166
|
-
|
|
167
|
-
Analysis results are cached for `expand_section`:
|
|
168
|
-
|
|
169
|
-
```typescript
|
|
170
|
-
// In orchestrator.ts
|
|
171
|
-
import { analysisCache } from "./cache.js";
|
|
172
|
-
|
|
173
|
-
// Check cache
|
|
174
|
-
const cached = analysisCache.getByAnalysisId(analysisId);
|
|
175
|
-
console.log("Cached result:", cached);
|
|
176
|
-
```
|
|
177
|
-
|
|
178
|
-
## Gemini Retry Logic
|
|
179
|
-
|
|
180
|
-
The Gemini client in `src/core/gemini.ts` has retry logic:
|
|
181
|
-
|
|
182
|
-
```typescript
|
|
183
|
-
// Check retry configuration
|
|
184
|
-
const MAX_RETRIES = 3;
|
|
185
|
-
const RETRY_DELAY = 1000;
|
|
186
|
-
```
|
|
187
|
-
|
|
188
|
-
If retries fail, check:
|
|
189
|
-
- API quotas
|
|
190
|
-
- Request payload size
|
|
191
|
-
- Network connectivity
|
|
192
|
-
|
|
193
|
-
## Performance Profiling
|
|
194
|
-
|
|
195
|
-
For slow analyses:
|
|
196
|
-
|
|
197
|
-
```bash
|
|
198
|
-
# Time the analysis
|
|
199
|
-
time pnpm cba analyze . -d standard -q
|
|
200
|
-
|
|
201
|
-
# Profile with Node
|
|
202
|
-
node --prof dist/cli/index.js analyze .
|
|
203
|
-
```
|
|
204
|
-
|
|
205
|
-
## Checklist for Issues
|
|
206
|
-
|
|
207
|
-
- [ ] `pnpm build` succeeds
|
|
208
|
-
- [ ] `pnpm cba capabilities` returns JSON
|
|
209
|
-
- [ ] Surface analysis works (`-d surface`)
|
|
210
|
-
- [ ] Standard analysis works (`-d standard`)
|
|
211
|
-
- [ ] Semantic analysis works (if API key set)
|
|
212
|
-
- [ ] Verbose mode shows progress (`-v`)
|
|
213
|
-
- [ ] No TypeScript errors (`pnpm tsc --noEmit`)
|