@agentbrain/mcp-server 1.4.36 → 1.4.38

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/README.md CHANGED
@@ -89,11 +89,15 @@ Then reopen it.
89
89
 
90
90
  1. Start a new conversation in Claude Desktop
91
91
  2. Look for the **🔌 icon** in the toolbar or bottom of the chat
92
- 3. Click it - you should see "agentbrain" with 5 tools:
92
+ 3. Click it - you should see "agentbrain" with 9 tools:
93
93
  - `scan_repo`
94
+ - `load_standards`
94
95
  - `load_context`
96
+ - `setup_repo` ⭐ NEW
97
+ - `save_context` ⭐ NEW
95
98
  - `load_spec`
96
- - `load_standards`
99
+ - `detect_doom_loop`
100
+ - `create_spec`
97
101
  - `save_handoff`
98
102
 
99
103
  #### Step 6: Try It Out!
@@ -222,7 +226,7 @@ Look for MCP tools in the Windsurf interface, then ask:
222
226
 
223
227
  ## Available Tools
224
228
 
225
- Once configured, your agent can use these 5 tools:
229
+ Once configured, your agent can use these 9 tools:
226
230
 
227
231
  ### 1. `scan_repo` - Analyze Repository Structure
228
232
 
@@ -375,6 +379,161 @@ This ensures the next session starts with awareness of potential issues.
375
379
 
376
380
  ---
377
381
 
382
+ ### 6. `setup_repo` ⭐ NEW - Agent-Driven Context Setup
383
+
384
+ **What it does:** Scans the repository and returns file tree + key file contents so your **agent** can generate context documents. No API key required!
385
+
386
+ **Parameters:**
387
+ - `repo_path` (required): Path to repository
388
+
389
+ **Example prompts:**
390
+ - "Set up AgentBrain for this project"
391
+ - "Scan /path/to/project and help me generate context"
392
+ - "Initialize AgentBrain context for my repo"
393
+
394
+ **Returns:**
395
+ ```json
396
+ {
397
+ "repo_path": "/path/to/project",
398
+ "file_tree": "src/index.ts (typescript)\nsrc/auth.ts (typescript)\n...",
399
+ "key_files": [
400
+ { "path": "package.json", "content": "..." },
401
+ { "path": "src/index.ts", "content": "..." }
402
+ ],
403
+ "instructions": "Based on the file tree and key files above, generate:\n1. context.md\n2. dependency-map.md\n3. patterns.md\nThen call save_context()..."
404
+ }
405
+ ```
406
+
407
+ **How it works:**
408
+ 1. Scans repository to find 30 most relevant files
409
+ 2. Returns file tree and actual file contents
410
+ 3. Your **agent reads and analyzes** the code
411
+ 4. Agent generates 3 context documents based on what it learned
412
+ 5. Agent calls `save_context()` to save them
413
+
414
+ **Cost:** Free - pure file I/O, no API calls
415
+
416
+ **Why this is better:**
417
+ - **No API key needed** - your agent does the analysis
418
+ - **Agent understands** - it reads actual code, not generated summaries
419
+ - **Customizable** - agent can focus on what matters for your current task
420
+ - **One-time setup** - after saving, `load_context` works instantly
421
+
422
+ ---
423
+
424
+ ### 7. `save_context` ⭐ NEW - Save Agent-Generated Context
425
+
426
+ **What it does:** Saves the 3 context documents generated by your agent to `.agentbrain/` directory. Works with `setup_repo` for fully agent-driven setup.
427
+
428
+ **Parameters:**
429
+ - `repo_path` (required): Path to repository
430
+ - `context` (required): Content for context.md (architecture, modules, tech stack)
431
+ - `dependency_map` (required): Content for dependency-map.md (module relationships, data flow)
432
+ - `patterns` (required): Content for patterns.md (conventions, patterns, standards)
433
+
434
+ **Example prompts:**
435
+ - "Save the context I generated to .agentbrain/"
436
+ - "Write these context files to disk"
437
+
438
+ **Returns:**
439
+ ```json
440
+ {
441
+ "success": true,
442
+ "files_written": [
443
+ ".agentbrain/context.md",
444
+ ".agentbrain/dependency-map.md",
445
+ ".agentbrain/patterns.md",
446
+ ".agentbrain/cache.json"
447
+ ],
448
+ "message": "Context saved successfully. load_context will now work without an API key."
449
+ }
450
+ ```
451
+
452
+ **What it creates:**
453
+ - `.agentbrain/context.md` - Architecture overview
454
+ - `.agentbrain/dependency-map.md` - Module relationships
455
+ - `.agentbrain/patterns.md` - Coding conventions
456
+ - `.agentbrain/cache.json` - Cache metadata with git hash
457
+
458
+ **Cost:** Free - pure file I/O
459
+
460
+ **After saving:**
461
+ - `load_context` works instantly
462
+ - `load_standards` works (if you also create standards file)
463
+ - `load_spec`, `detect_doom_loop`, `save_handoff` all work
464
+ - No API key needed for any subsequent operations
465
+
466
+ ---
467
+
468
+ ### 8. `create_spec` - Create Task Specification
469
+
470
+ **What it does:** Creates a new task specification file from agent-generated content.
471
+
472
+ **Parameters:**
473
+ - `repoPath` (required): Path to repository
474
+ - `task` (required): Task description or name
475
+ - `content` (required): Full specification content
476
+
477
+ **Example prompts:**
478
+ - "Create a spec for adding OAuth authentication"
479
+ - "Save this specification as add-stripe-integration"
480
+
481
+ **Returns:**
482
+ ```json
483
+ {
484
+ "specPath": ".agentbrain/specs/add-oauth-authentication.md",
485
+ "slug": "add-oauth-authentication"
486
+ }
487
+ ```
488
+
489
+ **Cost:** Free - writes to disk
490
+
491
+ **Note:** The agent can analyze your request, draft a comprehensive spec (problem, approach, acceptance criteria, etc.), then call this tool to save it.
492
+
493
+ ---
494
+
495
+ ### 9. `detect_doom_loop` - Manually Check for Doom Loops
496
+
497
+ **What it does:** Analyzes recent git history to detect if you're stuck modifying the same files repeatedly.
498
+
499
+ **Parameters:**
500
+ - `repo_path` (required): Path to repository
501
+ - `commit_count` (optional): Number of commits to analyze (default: 10)
502
+ - `threshold` (optional): Min occurrences to trigger warning (default: 4)
503
+
504
+ **Example prompts:**
505
+ - "Check if I'm in a doom loop"
506
+ - "Analyze my recent commits for patterns"
507
+ - "Am I stuck on any files?"
508
+
509
+ **Returns:**
510
+ ```json
511
+ {
512
+ "detected": true,
513
+ "files": [
514
+ { "path": "src/auth.ts", "count": 8, "percentage": 80 },
515
+ { "path": "src/main.ts", "count": 6, "percentage": 60 }
516
+ ],
517
+ "message": "Doom loop detected. You've modified src/auth.ts 8 times in the last 10 commits (80%). Stop coding and investigate the root cause."
518
+ }
519
+ ```
520
+
521
+ **Cost:** Free - analyzes local git history
522
+
523
+ **When to use:**
524
+ - When you feel stuck on a problem
525
+ - After multiple failed attempts
526
+ - Before starting a coding session
527
+ - When agent suggests checking
528
+
529
+ **What to do if detected:**
530
+ - Stop coding immediately
531
+ - Review why the file keeps being modified
532
+ - Plan a different approach
533
+ - Consider refactoring or architectural changes
534
+
535
+ ---
536
+
378
537
  ## Complete Workflow Example
379
538
 
380
539
  ### Morning: Start Your Day
@@ -632,16 +791,25 @@ agentbrain setup --no-confirm
632
791
 
633
792
  ## Tips for Best Results
634
793
 
635
- ### 1. Generate Context First
794
+ ### 1. Generate Context (Two Options)
636
795
 
637
- Before using the MCP server, generate context once via CLI:
796
+ **Option A: Agent-Driven Setup** (Recommended, no API key needed)
797
+ ```
798
+ You: "Set up AgentBrain for /path/to/project"
799
+ Agent: *Uses setup_repo tool*
800
+ Agent: "I've analyzed your codebase. Let me generate context documents..."
801
+ Agent: *Generates context.md, dependency-map.md, patterns.md*
802
+ Agent: *Uses save_context tool*
803
+ Agent: "Done! Context saved to .agentbrain/. All tools now work instantly."
804
+ ```
638
805
 
806
+ **Option B: CLI Setup** (Requires API key once)
639
807
  ```bash
640
808
  cd /path/to/project
641
809
  agentbrain init
642
810
  ```
643
811
 
644
- This creates the cache, making MCP tool calls instant and free.
812
+ Both create the cache, making MCP tool calls instant and free.
645
813
 
646
814
  ### 2. Paths Are Flexible
647
815
 
@@ -678,17 +846,32 @@ This gives your agent full project awareness immediately.
678
846
  **Q: Does this cost money?**
679
847
  A: Depends on the tool:
680
848
  - `scan_repo` - Free
849
+ - `setup_repo` ⭐ NEW - Free (no API key needed!)
850
+ - `save_context` ⭐ NEW - Free
681
851
  - `load_spec` - Free
682
852
  - `load_standards` - Free
853
+ - `detect_doom_loop` - Free
854
+ - `create_spec` - Free
683
855
  - `load_context` (cached) - Free
684
- - `load_context` (first time) - ~$0.02-0.05
856
+ - `load_context` (first time with API key) - ~$0.02-0.05
685
857
  - `save_handoff` - ~$0.01
686
858
 
859
+ **Q: Can I use AgentBrain without an API key?**
860
+ A: YES! Use the new `setup_repo` + `save_context` workflow:
861
+ 1. Ask your agent to "Set up AgentBrain for /path/to/project"
862
+ 2. Agent uses `setup_repo` to scan files (no API call)
863
+ 3. Agent reads and analyzes the code
864
+ 4. Agent generates context documents
865
+ 5. Agent uses `save_context` to save them (no API call)
866
+ After that, ALL tools work without an API key!
867
+
687
868
  **Q: Where does it get the API key?**
688
- A: From environment variables (`ANTHROPIC_API_KEY` or `OPENAI_API_KEY`) or from `~/.agentbrain/config.json` (set via `agentbrain config`).
869
+ A: From environment variables (`ANTHROPIC_API_KEY` or `OPENAI_API_KEY`) or from `~/.agentbrain/config.json` (set via `agentbrain config`). But with `setup_repo` + `save_context`, you don't need one!
689
870
 
690
871
  **Q: Can I use this without the CLI?**
691
- A: Yes! The MCP server works standalone. But using the CLI once to generate initial context (`agentbrain init`) will make subsequent MCP calls free and instant.
872
+ A: Yes! The MCP server works standalone. You can either:
873
+ - Use `setup_repo` + `save_context` (no API key, agent-driven)
874
+ - Use CLI once (`agentbrain init`) to generate context (requires API key)
692
875
 
693
876
  **Q: Which agent is best?**
694
877
  A: All three work great:
package/dist/index.js CHANGED
@@ -10,6 +10,37 @@ import { loadSpecTool, loadSpecSchema } from './tools/load-spec.js';
10
10
  import { detectDoomLoop, detectDoomLoopSchema } from './tools/detect-doom-loop.js';
11
11
  import { createSpecTool, createSpecSchema } from './tools/create-spec.js';
12
12
  import { saveHandoff, saveHandoffSchema } from './tools/save-handoff.js';
13
+ import { setupRepo, setupRepoSchema } from './tools/setup-repo.js';
14
+ import { saveContext, saveContextSchema } from './tools/save-context.js';
15
+ import { existsSync } from 'node:fs';
16
+ import { join, resolve } from 'node:path';
17
+ import { homedir } from 'node:os';
18
+ /**
19
+ * Expand path: handles ~, relative paths, etc.
20
+ */
21
+ function expandPath(path) {
22
+ if (path.startsWith('~/') || path === '~') {
23
+ return path.replace('~', homedir());
24
+ }
25
+ return resolve(path);
26
+ }
27
+ /**
28
+ * Check if .agentbrain/ directory exists. If not, return bootstrap message.
29
+ * Returns null if bootstrap is not needed (directory exists).
30
+ */
31
+ async function checkBootstrap(repo_path) {
32
+ const expandedPath = expandPath(repo_path);
33
+ const contextDir = join(expandedPath, '.agentbrain');
34
+ if (!existsSync(contextDir)) {
35
+ return ('No .agentbrain/ directory found. To set up context without an API key:\n\n' +
36
+ '1. Call setup_repo() to scan the repo and get instructions\n' +
37
+ '2. Generate the three context documents based on what setup_repo returns\n' +
38
+ '3. Call save_context() with your generated content\n\n' +
39
+ 'After that, this tool will work instantly with no API key needed.\n\n' +
40
+ 'Alternative: Run `agentbrain setup` in your terminal (requires API key, one-time ~$0.03)');
41
+ }
42
+ return null;
43
+ }
13
44
  // Create MCP server
14
45
  const server = new Server({
15
46
  name: 'agentbrain',
@@ -26,6 +57,8 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
26
57
  scanRepoSchema,
27
58
  loadStandardsSchema,
28
59
  loadContextSchema,
60
+ setupRepoSchema,
61
+ saveContextSchema,
29
62
  loadSpecSchema,
30
63
  detectDoomLoopSchema,
31
64
  createSpecSchema,
@@ -45,12 +78,24 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
45
78
  };
46
79
  }
47
80
  case 'load_standards': {
81
+ const bootstrap = await checkBootstrap(args.repo_path);
82
+ if (bootstrap) {
83
+ return {
84
+ content: [{ type: 'text', text: bootstrap }],
85
+ };
86
+ }
48
87
  const result = await loadStandards(args);
49
88
  return {
50
89
  content: [{ type: 'text', text: result.content }],
51
90
  };
52
91
  }
53
92
  case 'load_context': {
93
+ const bootstrap = await checkBootstrap(args.repo_path);
94
+ if (bootstrap) {
95
+ return {
96
+ content: [{ type: 'text', text: bootstrap }],
97
+ };
98
+ }
54
99
  const result = await loadContext(args);
55
100
  return {
56
101
  content: [
@@ -62,6 +107,12 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
62
107
  };
63
108
  }
64
109
  case 'load_spec': {
110
+ const bootstrap = await checkBootstrap(args.repoPath);
111
+ if (bootstrap) {
112
+ return {
113
+ content: [{ type: 'text', text: bootstrap }],
114
+ };
115
+ }
65
116
  const result = await loadSpecTool(args);
66
117
  return {
67
118
  content: [
@@ -75,6 +126,12 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
75
126
  };
76
127
  }
77
128
  case 'detect_doom_loop': {
129
+ const bootstrap = await checkBootstrap(args.repo_path);
130
+ if (bootstrap) {
131
+ return {
132
+ content: [{ type: 'text', text: bootstrap }],
133
+ };
134
+ }
78
135
  const result = await detectDoomLoop(args);
79
136
  return {
80
137
  content: [
@@ -97,6 +154,12 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
97
154
  };
98
155
  }
99
156
  case 'save_handoff': {
157
+ const bootstrap = await checkBootstrap(args.repo_path);
158
+ if (bootstrap) {
159
+ return {
160
+ content: [{ type: 'text', text: bootstrap }],
161
+ };
162
+ }
100
163
  const result = await saveHandoff(args);
101
164
  return {
102
165
  content: [
@@ -107,6 +170,28 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
107
170
  ],
108
171
  };
109
172
  }
173
+ case 'setup_repo': {
174
+ const result = await setupRepo(args);
175
+ return {
176
+ content: [
177
+ {
178
+ type: 'text',
179
+ text: `# Repository Setup Data\n\n## File Tree\n${result.file_tree}\n\n## Key Files (${result.key_files.length} files)\n\n${result.key_files.map(f => `### ${f.path}\n\`\`\`\n${f.content}\n\`\`\``).join('\n\n')}\n\n## Instructions\n\n${result.instructions}`,
180
+ },
181
+ ],
182
+ };
183
+ }
184
+ case 'save_context': {
185
+ const result = await saveContext(args);
186
+ return {
187
+ content: [
188
+ {
189
+ type: 'text',
190
+ text: `${result.message}\n\nFiles written:\n${result.files_written.map(f => `- ${f}`).join('\n')}`,
191
+ },
192
+ ],
193
+ };
194
+ }
110
195
  default:
111
196
  throw new Error(`Unknown tool: ${name}`);
112
197
  }
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,wBAAwB;AAExB,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAA;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAA;AAChF,OAAO,EACL,qBAAqB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"file":"load-context.d.ts","sourceRoot":"","sources":["../../src/tools/load-context.ts"],"names":[],"mappings":"AAMA,OAAO,EAOL,KAAK,iBAAiB,EACvB,MAAM,kBAAkB,CAAA;AAYzB,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,MAAM,CAAA;IACjB,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,OAAO,CAAA;IAClB,UAAU,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,YAAY,CAAC,EAAE,iBAAiB,GAAG,IAAI,CAAA;CACxC;AAED,wBAAsB,WAAW,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAoHrF;AAED,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;CAkB7B,CAAA"}
1
+ {"version":3,"file":"load-context.d.ts","sourceRoot":"","sources":["../../src/tools/load-context.ts"],"names":[],"mappings":"AAMA,OAAO,EAOL,KAAK,iBAAiB,EACvB,MAAM,kBAAkB,CAAA;AAYzB,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,MAAM,CAAA;IACjB,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,OAAO,CAAA;IAClB,UAAU,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,YAAY,CAAC,EAAE,iBAAiB,GAAG,IAAI,CAAA;CACxC;AAED,wBAAsB,WAAW,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAqHrF;AAED,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;CAkB7B,CAAA"}
@@ -73,25 +73,26 @@ export async function loadContext(input) {
73
73
  doom_warning: doomWarning,
74
74
  };
75
75
  }
76
- // Need to generate - requires API key (only loaded if we reach this point)
76
+ // Need to generate - check for API key first
77
77
  let aiConfig;
78
78
  try {
79
79
  aiConfig = await loadAIConfig();
80
80
  }
81
81
  catch {
82
- // No API key configured - return helpful message
82
+ // No API key configured - return bootstrap instructions
83
83
  return {
84
- content: 'No context found for this repository and no API key configured.\n\n' +
85
- 'To fix:\n' +
86
- '1. Run `agentbrain setup` in your repo to generate context (one-time, ~$0.03)\n' +
87
- '2. After setup, load_context works without an API key\n\n' +
88
- 'The API key is only needed for first-time generation.',
84
+ content: 'No context found for this repository. To set up context without an API key:\n\n' +
85
+ '1. Call setup_repo() to scan the repo and get instructions\n' +
86
+ '2. Generate the three context documents based on what setup_repo returns\n' +
87
+ '3. Call save_context() with your generated content\n\n' +
88
+ 'After that, load_context will work instantly with no API key needed.\n\n' +
89
+ 'Alternative: Run `agentbrain setup` in your terminal (requires API key, one-time ~$0.03)',
89
90
  fromCache: false,
90
91
  tokensUsed: 0,
91
92
  doom_warning: null,
92
93
  };
93
94
  }
94
- // Generate new context
95
+ // Generate new context using API
95
96
  const result = await generateContext({
96
97
  repoPath: expandedPath,
97
98
  aiConfig,
@@ -1 +1 @@
1
- {"version":3,"file":"load-context.js","sourceRoot":"","sources":["../../src/tools/load-context.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAE9D,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AACpC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,EAAE,OAAO,EAAE,MAA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E,CAAC,WAAW,CAAC;KACxB;CACF,CAAA"}
@@ -0,0 +1,40 @@
1
+ export interface SaveContextInput {
2
+ repo_path: string;
3
+ context: string;
4
+ dependency_map: string;
5
+ patterns: string;
6
+ }
7
+ export interface SaveContextOutput {
8
+ success: boolean;
9
+ files_written: string[];
10
+ agent_detected: 'cursor' | 'windsurf' | 'claude' | 'unknown';
11
+ message: string;
12
+ }
13
+ export declare function saveContext(input: SaveContextInput): Promise<SaveContextOutput>;
14
+ export declare const saveContextSchema: {
15
+ name: string;
16
+ description: string;
17
+ inputSchema: {
18
+ type: string;
19
+ properties: {
20
+ repo_path: {
21
+ type: string;
22
+ description: string;
23
+ };
24
+ context: {
25
+ type: string;
26
+ description: string;
27
+ };
28
+ dependency_map: {
29
+ type: string;
30
+ description: string;
31
+ };
32
+ patterns: {
33
+ type: string;
34
+ description: string;
35
+ };
36
+ };
37
+ required: string[];
38
+ };
39
+ };
40
+ //# sourceMappingURL=save-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"save-context.d.ts","sourceRoot":"","sources":["../../src/tools/save-context.ts"],"names":[],"mappings":"AAkBA,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,MAAM,CAAA;IACf,cAAc,EAAE,MAAM,CAAA;IACtB,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,OAAO,CAAA;IAChB,aAAa,EAAE,MAAM,EAAE,CAAA;IACvB,cAAc,EAAE,QAAQ,GAAG,UAAU,GAAG,QAAQ,GAAG,SAAS,CAAA;IAC5D,OAAO,EAAE,MAAM,CAAA;CAChB;AAwGD,wBAAsB,WAAW,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAwHrF;AAED,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;CA0B7B,CAAA"}
@@ -0,0 +1,236 @@
1
+ // MCP tool: save_context - save agent-generated context to disk
2
+ import { writeFile, mkdir, readFile } from 'node:fs/promises';
3
+ import { existsSync } from 'node:fs';
4
+ import { join, resolve } from 'node:path';
5
+ import { homedir } from 'node:os';
6
+ import { getGitHash, ensureGitignore } from '@agentbrain/core';
7
+ /**
8
+ * Expand path: handles ~, relative paths, etc.
9
+ */
10
+ function expandPath(path) {
11
+ if (path.startsWith('~/') || path === '~') {
12
+ return path.replace('~', homedir());
13
+ }
14
+ return resolve(path);
15
+ }
16
+ /**
17
+ * Detect agent type from filesystem
18
+ */
19
+ function detectAgentType(repoPath) {
20
+ if (existsSync(join(repoPath, '.cursor'))) {
21
+ return 'cursor';
22
+ }
23
+ if (existsSync(join(repoPath, '.windsurf'))) {
24
+ return 'windsurf';
25
+ }
26
+ if (existsSync(join(repoPath, 'CLAUDE.md'))) {
27
+ return 'claude';
28
+ }
29
+ return 'unknown';
30
+ }
31
+ /**
32
+ * Get agent file content
33
+ */
34
+ function getAgentFileContent(isModernFormat) {
35
+ const baseContent = `## AgentBrain Context
36
+ @.agentbrain/context.md
37
+ @.agentbrain/patterns.md
38
+ @.agentbrain/dependency-map.md
39
+
40
+ ## Workflow
41
+ - Always read context at session start via load_context()
42
+ - Before any task: load_spec() or agentbrain spec "task"
43
+ - After commits: context auto-updates via git hook
44
+ - If stuck in a loop: detect_doom_loop() or agentbrain doom
45
+ - End of session: save_handoff() or agentbrain handoff
46
+ - If context feels stale: agentbrain init
47
+
48
+ ## MCP Tools
49
+ - load_context() — full codebase context
50
+ - load_spec() — spec for current task
51
+ - detect_doom_loop() — check for stuck patterns
52
+ - save_handoff() — end of session handoff
53
+ - setup_repo() — first time MCP setup
54
+ - save_context() — save agent-generated context`;
55
+ if (isModernFormat) {
56
+ return `---
57
+ description: AgentBrain codebase context and workflow
58
+ alwaysApply: true
59
+ ---
60
+
61
+ ${baseContent}`;
62
+ }
63
+ return baseContent;
64
+ }
65
+ /**
66
+ * Check if agent file already contains AgentBrain section
67
+ */
68
+ async function hasAgentBrainSection(filePath) {
69
+ if (!existsSync(filePath)) {
70
+ return false;
71
+ }
72
+ const content = await readFile(filePath, 'utf-8');
73
+ return content.includes('── AgentBrain ──');
74
+ }
75
+ /**
76
+ * Append AgentBrain section to agent file
77
+ */
78
+ async function appendToAgentFile(filePath, content) {
79
+ const marker = '# ── AgentBrain ──────────────────────────────';
80
+ const endMarker = '# ── End AgentBrain ──────────────────────────';
81
+ if (await hasAgentBrainSection(filePath)) {
82
+ return; // Already has AgentBrain section
83
+ }
84
+ let existingContent = '';
85
+ if (existsSync(filePath)) {
86
+ existingContent = await readFile(filePath, 'utf-8');
87
+ }
88
+ const agentBrainSection = `\n${marker}\n${content}\n${endMarker}\n`;
89
+ await writeFile(filePath, existingContent + agentBrainSection, 'utf-8');
90
+ }
91
+ /**
92
+ * Create modern agent file (with frontmatter)
93
+ */
94
+ async function createModernAgentFile(filePath, content) {
95
+ const dir = join(filePath, '..');
96
+ if (!existsSync(dir)) {
97
+ await mkdir(dir, { recursive: true });
98
+ }
99
+ // Modern files get replaced entirely (they're auto-loaded)
100
+ await writeFile(filePath, content, 'utf-8');
101
+ }
102
+ export async function saveContext(input) {
103
+ const { repo_path, context, dependency_map, patterns } = input;
104
+ // Expand path to handle ~, relative paths, etc.
105
+ const expandedPath = expandPath(repo_path);
106
+ const contextDir = join(expandedPath, '.agentbrain');
107
+ const filesWritten = [];
108
+ // Step 1: Create .agentbrain directory if it doesn't exist
109
+ if (!existsSync(contextDir)) {
110
+ await mkdir(contextDir, { recursive: true });
111
+ }
112
+ // Step 2: Write the three context files
113
+ const contextPath = join(contextDir, 'context.md');
114
+ const depMapPath = join(contextDir, 'dependency-map.md');
115
+ const patternsPath = join(contextDir, 'patterns.md');
116
+ await writeFile(contextPath, context, 'utf-8');
117
+ await writeFile(depMapPath, dependency_map, 'utf-8');
118
+ await writeFile(patternsPath, patterns, 'utf-8');
119
+ filesWritten.push('.agentbrain/context.md', '.agentbrain/dependency-map.md', '.agentbrain/patterns.md');
120
+ // Step 3: Get current git hash and write cache.json
121
+ const gitHash = await getGitHash(expandedPath);
122
+ const cachePath = join(contextDir, 'cache.json');
123
+ const cache = {
124
+ gitHash,
125
+ docs: {
126
+ context: {
127
+ type: 'context',
128
+ content: context,
129
+ savedAt: new Date().toISOString(),
130
+ },
131
+ 'dependency-map': {
132
+ type: 'dependency-map',
133
+ content: dependency_map,
134
+ savedAt: new Date().toISOString(),
135
+ },
136
+ patterns: {
137
+ type: 'patterns',
138
+ content: patterns,
139
+ savedAt: new Date().toISOString(),
140
+ },
141
+ },
142
+ savedAt: new Date().toISOString(),
143
+ };
144
+ await writeFile(cachePath, JSON.stringify(cache, null, 2), 'utf-8');
145
+ filesWritten.push('.agentbrain/cache.json');
146
+ // Step 4: Update .gitignore
147
+ await ensureGitignore(expandedPath);
148
+ // Step 5: Detect agent type
149
+ const agentType = detectAgentType(expandedPath);
150
+ // Step 6: Create agent files based on detection
151
+ const modernContent = getAgentFileContent(true);
152
+ const legacyContent = getAgentFileContent(false);
153
+ if (agentType === 'cursor') {
154
+ // Create modern format
155
+ const modernPath = join(expandedPath, '.cursor', 'rules', 'agentbrain.mdc');
156
+ await createModernAgentFile(modernPath, modernContent);
157
+ filesWritten.push('.cursor/rules/agentbrain.mdc');
158
+ // Create legacy fallback
159
+ const legacyPath = join(expandedPath, '.cursorrules');
160
+ await appendToAgentFile(legacyPath, legacyContent);
161
+ filesWritten.push('.cursorrules');
162
+ }
163
+ else if (agentType === 'windsurf') {
164
+ // Create modern format (plain markdown, no frontmatter for Windsurf)
165
+ const modernPath = join(expandedPath, '.windsurf', 'rules', 'agentbrain.md');
166
+ await createModernAgentFile(modernPath, legacyContent); // Use legacyContent (no frontmatter)
167
+ filesWritten.push('.windsurf/rules/agentbrain.md');
168
+ // Create legacy fallback
169
+ const legacyPath = join(expandedPath, '.windsurfrules');
170
+ await appendToAgentFile(legacyPath, legacyContent);
171
+ filesWritten.push('.windsurfrules');
172
+ }
173
+ else if (agentType === 'claude') {
174
+ // Just create/append to CLAUDE.md
175
+ const claudePath = join(expandedPath, 'CLAUDE.md');
176
+ await appendToAgentFile(claudePath, legacyContent);
177
+ filesWritten.push('CLAUDE.md');
178
+ }
179
+ else {
180
+ // Unknown - create all legacy files as safe default
181
+ const claudePath = join(expandedPath, 'CLAUDE.md');
182
+ const cursorPath = join(expandedPath, '.cursorrules');
183
+ const windsurfPath = join(expandedPath, '.windsurfrules');
184
+ await appendToAgentFile(claudePath, legacyContent);
185
+ await appendToAgentFile(cursorPath, legacyContent);
186
+ await appendToAgentFile(windsurfPath, legacyContent);
187
+ filesWritten.push('CLAUDE.md', '.cursorrules', '.windsurfrules');
188
+ }
189
+ // Step 7: Generate message
190
+ let message = '';
191
+ if (agentType === 'cursor') {
192
+ message = `Detected Cursor (.cursor/ directory found). Created .cursor/rules/agentbrain.mdc (modern, always applied) and .cursorrules (legacy fallback).`;
193
+ }
194
+ else if (agentType === 'windsurf') {
195
+ message = `Detected Windsurf (.windsurf/ directory found). Created .windsurf/rules/agentbrain.md (modern, always applied) and .windsurfrules (legacy fallback).`;
196
+ }
197
+ else if (agentType === 'claude') {
198
+ message = `Detected Claude (CLAUDE.md found). Updated CLAUDE.md with AgentBrain context loading instructions.`;
199
+ }
200
+ else {
201
+ message = `Could not detect your agent type. Created CLAUDE.md, .cursorrules, and .windsurfrules as a safe default. If you're using Cursor, .cursor/rules/agentbrain.mdc gives better performance. If Windsurf, use .windsurf/rules/agentbrain.md instead.`;
202
+ }
203
+ return {
204
+ success: true,
205
+ files_written: filesWritten,
206
+ agent_detected: agentType,
207
+ message: `Context saved successfully. ${message} load_context will now work without an API key.`,
208
+ };
209
+ }
210
+ export const saveContextSchema = {
211
+ name: 'save_context',
212
+ description: 'Save agent-generated context files to .agentbrain/ directory. No API key required - pure file I/O. After saving, load_context will work instantly without needing API calls.',
213
+ inputSchema: {
214
+ type: 'object',
215
+ properties: {
216
+ repo_path: {
217
+ type: 'string',
218
+ description: 'Absolute path to the repository',
219
+ },
220
+ context: {
221
+ type: 'string',
222
+ description: 'Content for context.md (architecture, modules, tech stack)',
223
+ },
224
+ dependency_map: {
225
+ type: 'string',
226
+ description: 'Content for dependency-map.md (module relationships, data flow)',
227
+ },
228
+ patterns: {
229
+ type: 'string',
230
+ description: 'Content for patterns.md (conventions, patterns, standards)',
231
+ },
232
+ },
233
+ required: ['repo_path', 'context', 'dependency_map', 'patterns'],
234
+ },
235
+ };
236
+ //# sourceMappingURL=save-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"save-context.js","sourceRoot":"","sources":["../../src/tools/save-context.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAEhE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AACpC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACjC,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAE9D;;GAEG;AACH,SAAS,UAAU,CAAC,IAAY;IAC9B,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;QAC1C,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,EAAE,CAAC,CAAA;IACrC,CAAC;IACD,OAAO,OAAO,CAAC,IAAI,CAAC,CAAA;AACtB,CAAC;AAkBD;;GAEG;AACH,SAAS,eAAe,CAAC,QAAgB;IACvC,IAAI,UAAU,CAAC,IAAI,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC,EAAE,CAAC;QAC1C,OAAO,QAAQ,CAAA;IACjB,CAAC;IACD,IAAI,UAAU,CAAC,IAAI,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC,EAAE,CAAC;QAC5C,OAAO,UAAU,CA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,EAAE;gBACd,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,iEAAiE;aAC/E;YACD,QAAQ,EAAE;gBACR,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,4DAA4D;aAC1E;SACF;QACD,QAAQ,EAAE,CAAC,WAAW,EAAE,SAAS,EAAE,gBAAgB,EAAE,UAAU,CAAC;KACjE;CACF,CAAA"}
@@ -0,0 +1,28 @@
1
+ export interface SetupRepoInput {
2
+ repo_path: string;
3
+ }
4
+ export interface SetupRepoOutput {
5
+ repo_path: string;
6
+ file_tree: string;
7
+ key_files: Array<{
8
+ path: string;
9
+ content: string;
10
+ }>;
11
+ instructions: string;
12
+ }
13
+ export declare function setupRepo(input: SetupRepoInput): Promise<SetupRepoOutput>;
14
+ export declare const setupRepoSchema: {
15
+ name: string;
16
+ description: string;
17
+ inputSchema: {
18
+ type: string;
19
+ properties: {
20
+ repo_path: {
21
+ type: string;
22
+ description: string;
23
+ };
24
+ };
25
+ required: string[];
26
+ };
27
+ };
28
+ //# sourceMappingURL=setup-repo.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setup-repo.d.ts","sourceRoot":"","sources":["../../src/tools/setup-repo.ts"],"names":[],"mappings":"AAgBA,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,KAAK,CAAC;QACf,IAAI,EAAE,MAAM,CAAA;QACZ,OAAO,EAAE,MAAM,CAAA;KAChB,CAAC,CAAA;IACF,YAAY,EAAE,MAAM,CAAA;CACrB;AAED,wBAAsB,SAAS,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC,CAmD/E;AAED,eAAO,MAAM,eAAe;;;;;;;;;;;;;CAc3B,CAAA"}
@@ -0,0 +1,73 @@
1
+ // MCP tool: setup_repo - scan repo and return data for agent to generate context
2
+ import { scanRepository, readFileContent } from '@agentbrain/core';
3
+ import { resolve } from 'node:path';
4
+ import { homedir } from 'node:os';
5
+ /**
6
+ * Expand path: handles ~, relative paths, etc.
7
+ */
8
+ function expandPath(path) {
9
+ if (path.startsWith('~/') || path === '~') {
10
+ return path.replace('~', homedir());
11
+ }
12
+ return resolve(path);
13
+ }
14
+ export async function setupRepo(input) {
15
+ const { repo_path } = input;
16
+ // Expand path to handle ~, relative paths, etc.
17
+ const expandedPath = expandPath(repo_path);
18
+ // Scan the repository to get relevant files
19
+ const scanResult = await scanRepository(expandedPath, { maxFiles: 30 });
20
+ // Build file tree visualization
21
+ const fileTree = scanResult.relevantFiles
22
+ .map((f) => `${f.path} (${f.language})`)
23
+ .join('\n');
24
+ // Read content of top files (prioritized by scan)
25
+ const keyFiles = [];
26
+ for (const file of scanResult.relevantFiles.slice(0, 30)) {
27
+ const content = await readFileContent(expandedPath, file.path);
28
+ if (content !== null) {
29
+ keyFiles.push({
30
+ path: file.path,
31
+ content,
32
+ });
33
+ }
34
+ }
35
+ // Instructions for the agent
36
+ const instructions = `Based on the file tree and key files above, generate:
37
+
38
+ 1. context.md — Architecture overview, key modules, entry points, what the codebase does, tech stack
39
+
40
+ 2. dependency-map.md — How modules relate to each other, data flow, service relationships
41
+
42
+ 3. patterns.md — Coding conventions, patterns used, naming conventions, error handling approach
43
+
44
+ Then call save_context() with all three documents.
45
+
46
+ Guidelines:
47
+ - Be concise but thorough
48
+ - Focus on what's unique to this codebase
49
+ - Include specific file paths and module names
50
+ - Identify the main entry points and core business logic
51
+ - Note any important patterns or conventions used consistently`;
52
+ return {
53
+ repo_path: expandedPath,
54
+ file_tree: fileTree,
55
+ key_files: keyFiles,
56
+ instructions,
57
+ };
58
+ }
59
+ export const setupRepoSchema = {
60
+ name: 'setup_repo',
61
+ description: 'Scan repository and return file tree + key file contents for agent-driven context generation. No API key required - pure file analysis. Use this when load_context indicates setup is needed.',
62
+ inputSchema: {
63
+ type: 'object',
64
+ properties: {
65
+ repo_path: {
66
+ type: 'string',
67
+ description: 'Absolute path to the repository',
68
+ },
69
+ },
70
+ required: ['repo_path'],
71
+ },
72
+ };
73
+ //# sourceMappingURL=setup-repo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setup-repo.js","sourceRoot":"","sources":["../../src/tools/setup-repo.ts"],"names":[],"mappings":"AAAA,iFAAiF;AAEjF,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAClE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAEjC;;GAEG;AACH,SAAS,UAAU,CAAC,IAAY;IAC9B,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;QAC1C,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,EAAE,CAAC,CAAA;IACrC,CAAC;IACD,OAAO,OAAO,CAAC,IAAI,CAAC,CAAA;AACtB,CAAC;AAgBD,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,KAAqB;IACnD,MAAM,EAAE,SAAS,EAAE,GAAG,KAAK,CAAA;IAE3B,gDAAgD;IAChD,MAAM,YAAY,GAAG,UAAU,CAAC,SAAS,CAAC,CAAA;IAE1C,4CAA4C;IAC5C,MAAM,UAAU,GAAG,MAAM,cAAc,CAAC,YAAY,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,CAAA;IAEvE,gCAAgC;IAChC,MAAM,QAAQ,GAAG,UAAU,CAAC,aAAa;SACtC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,QAAQ,GAAG,CAAC;SACvC,IAAI,CAAC,IAAI,CAAC,CAAA;IAEb,kDAAkD;IAClD,MAAM,QAAQ,GAA6C,EAAE,CAAA;IAE7D,KAAK,MAAM,IAAI,IAAI,UAAU,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC;QACzD,MAAM,OAAO,GAAG,MAAM,eAAe,CAAC,YAAY,EAAE,IAAI,CAAC,IAAI,CAAC,CAAA;QAC9D,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;YACrB,QAAQ,CAAC,IAAI,CAAC;gBACZ,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,OAAO;aACR,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;IAED,6BAA6B;IAC7B,MAAM,YAAY,GAAG;;;;;;;;;;;;;;;+DAewC,CAAA;IAE7D,OAAO;QACL,SAAS,EAAE,YAAY;QACvB,SAAS,EAAE,QAAQ;QACnB,SAAS,EAAE,QAAQ;QACnB,YAAY;KACb,CAAA;AACH,CAAC;AAED,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,IAAI,EAAE,YAAY;IAClB,WAAW,EACT,+LAA+L;IACjM,WAAW,EAAE;QACX,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,SAAS,EAAE;gBACT,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,iCAAiC;aAC/C;SACF;QACD,QAAQ,EAAE,CAAC,WAAW,CAAC;KACxB;CACF,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentbrain/mcp-server",
3
- "version": "1.4.36",
3
+ "version": "1.4.38",
4
4
  "description": "Model Context Protocol server for AgentBrain - connect Claude, Cursor, and Windsurf to repository intelligence",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -52,4 +52,4 @@
52
52
  "ts-jest": "^29.4.6",
53
53
  "typescript": "^5.7.2"
54
54
  }
55
- }
55
+ }