mcp-code-context 3.5.3 ā 3.6.1
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/CHANGELOG.md +96 -3
- package/INSTRUCTIONS.md +274 -0
- package/README.md +59 -6
- package/SECURITY.md +14 -14
- package/dist/src/core/cacheManager.d.ts +48 -0
- package/dist/src/core/cacheManager.js +255 -0
- package/dist/src/core/cacheManager.js.map +1 -0
- package/dist/src/core/engine.d.ts +1 -1
- package/dist/src/core/engine.js +1 -1
- package/dist/src/core/validator.d.ts +1 -1
- package/dist/src/core/validator.js +19 -7
- package/dist/src/core/validator.js.map +1 -1
- package/dist/src/index.d.ts +6 -1
- package/dist/src/index.js +227 -21
- package/dist/src/index.js.map +1 -1
- package/dist/src/operations/compress.d.ts +3 -1
- package/dist/src/operations/compress.js +47 -48
- package/dist/src/operations/compress.js.map +1 -1
- package/dist/src/operations/confirmationStore.d.ts +3 -1
- package/dist/src/operations/confirmationStore.js +2 -1
- package/dist/src/operations/confirmationStore.js.map +1 -1
- package/dist/src/operations/read.d.ts +7 -1
- package/dist/src/operations/read.js +115 -64
- package/dist/src/operations/read.js.map +1 -1
- package/dist/src/operations/write.d.ts +3 -2
- package/dist/src/operations/write.js +88 -59
- package/dist/src/operations/write.js.map +1 -1
- package/dist/src/parsers/base.d.ts +1 -1
- package/dist/src/parsers/base.js +1 -1
- package/dist/src/parsers/dartTreeSitter.d.ts +1 -1
- package/dist/src/parsers/dartTreeSitter.js +1 -1
- package/dist/src/parsers/php.d.ts +1 -1
- package/dist/src/parsers/php.js +1 -1
- package/dist/src/parsers/python.d.ts +1 -1
- package/dist/src/parsers/python.js +1 -1
- package/dist/src/parsers/registry.d.ts +1 -1
- package/dist/src/parsers/registry.js +1 -1
- package/dist/src/parsers/typescript.d.ts +1 -1
- package/dist/src/parsers/typescript.js +1 -1
- package/dist/src/utils/auditLogger.d.ts +1 -1
- package/dist/src/utils/auditLogger.js +3 -2
- package/dist/src/utils/auditLogger.js.map +1 -1
- package/dist/src/utils/backupManager.d.ts +30 -9
- package/dist/src/utils/backupManager.js +75 -33
- package/dist/src/utils/backupManager.js.map +1 -1
- package/dist/src/utils/constants.d.ts +13 -2
- package/dist/src/utils/constants.js +21 -2
- package/dist/src/utils/constants.js.map +1 -1
- package/dist/src/utils/diff.d.ts +37 -7
- package/dist/src/utils/diff.js +91 -101
- package/dist/src/utils/diff.js.map +1 -1
- package/dist/src/utils/fileLock.d.ts +25 -50
- package/dist/src/utils/fileLock.js +66 -100
- package/dist/src/utils/fileLock.js.map +1 -1
- package/dist/src/utils/fileWalker.d.ts +28 -0
- package/dist/src/utils/fileWalker.js +57 -0
- package/dist/src/utils/fileWalker.js.map +1 -0
- package/dist/src/utils/fileWatcher.d.ts +23 -0
- package/dist/src/utils/fileWatcher.js +80 -0
- package/dist/src/utils/fileWatcher.js.map +1 -0
- package/dist/src/utils/fuzzySearch.d.ts +22 -0
- package/dist/src/utils/fuzzySearch.js +36 -0
- package/dist/src/utils/fuzzySearch.js.map +1 -0
- package/dist/src/utils/logger.d.ts +19 -0
- package/dist/src/utils/logger.js +50 -0
- package/dist/src/utils/logger.js.map +1 -0
- package/dist/src/utils/rateLimiter.d.ts +1 -1
- package/dist/src/utils/rateLimiter.js +1 -1
- package/dist/src/utils/safeRegex.d.ts +1 -1
- package/dist/src/utils/safeRegex.js +1 -1
- package/dist/src/utils/searchTools.d.ts +14 -0
- package/dist/src/utils/searchTools.js +94 -0
- package/dist/src/utils/searchTools.js.map +1 -0
- package/dist/src/utils/streaming.d.ts +1 -1
- package/dist/src/utils/streaming.js +1 -1
- package/dist/src/utils/telemetry.d.ts +1 -1
- package/dist/src/utils/telemetry.js +1 -1
- package/llms.txt +5 -5
- package/package.json +28 -10
- package/vitest.config.ts +37 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,99 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
## [3.
|
|
3
|
+
## [3.6.1] - 2026-05-01
|
|
4
|
+
|
|
5
|
+
### š CRITICAL FIXES - Production Stability Release
|
|
6
|
+
|
|
7
|
+
**Emergency Update**: Resolved 3 critical production bugs causing data corruption, memory leaks, and race conditions.
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
|
|
11
|
+
#### Critical Bug Fixes
|
|
12
|
+
- **FIX #1: Double Cache Instance** ā Eliminated duplicate SQLite database instances in `read.ts` causing cache corruption. Cache now properly injected from `index.ts` singleton.
|
|
13
|
+
- **FIX #2: Memory Leak (Event Listeners)** ā Removed `process.on` listeners from `CacheManager` constructor. Each cache instance was registering global listeners, causing `MaxListenersExceededWarning` and memory exhaustion. Added global shutdown hook in `index.ts` instead.
|
|
14
|
+
- **FIX #3: TOCTOU Race Condition** ā Added `originalHash` verification in Phase 2 writes. Prevents silent data corruption when files are modified between dry-run (Phase 1) and confirmation (Phase 2).
|
|
15
|
+
|
|
16
|
+
### Added
|
|
17
|
+
- **Global Shutdown Hook**: Single `process.on` handler in `index.ts` persists all active caches on exit
|
|
18
|
+
- **persistOnExit() Method**: Public synchronous method for safe cache persistence during shutdown
|
|
19
|
+
- **originalHash Field**: Added to `WriteResult` interface for TOCTOU protection
|
|
20
|
+
- **8 Regression Tests**: Memory leak detection, cache injection validation, TOCTOU protection
|
|
21
|
+
|
|
22
|
+
### Changed
|
|
23
|
+
- **BREAKING**: `extractSymbol` now requires `cache` parameter (injected from caller)
|
|
24
|
+
- **BREAKING**: `WriteResult` interface includes optional `originalHash` field
|
|
25
|
+
- **BREAKING**: `PendingOperation` interface includes optional `originalHash` field
|
|
26
|
+
|
|
27
|
+
### Test Results
|
|
28
|
+
- 81/82 tests passing (99% success rate)
|
|
29
|
+
- Memory leak test: ā
PASSED (no listener accumulation)
|
|
30
|
+
- TOCTOU protection test: ā
PASSED (hash verification works)
|
|
31
|
+
- Cache injection test: ā
PASSED (no duplicate instances)
|
|
32
|
+
- 1 flaky performance test (timing variance, not a bug)
|
|
33
|
+
|
|
34
|
+
### Security
|
|
35
|
+
- ā
TOCTOU race condition eliminated
|
|
36
|
+
- ā
Memory leak prevention
|
|
37
|
+
- ā
Cache corruption prevention
|
|
38
|
+
|
|
39
|
+
### Migration from v3.6.0
|
|
40
|
+
- Update calls to `extractSymbol` to pass `cache` parameter
|
|
41
|
+
- No user-facing API changes (internal refactoring only)
|
|
42
|
+
- Rebuild recommended: `npm run rebuild`
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## [3.6.0] - 2026-04-30
|
|
47
|
+
|
|
48
|
+
### Added
|
|
49
|
+
|
|
50
|
+
#### Infrastructure
|
|
51
|
+
- **Persistent WASM SQLite Cache** (`sql.js`) ā <100ms cache hits, 10Ć faster on repeated reads. Debounced persistence (5s) prevents event loop blocking. OS temp cleanup recovery built-in.
|
|
52
|
+
- **Structured Logging** (`pino`) ā JSON to stderr (MCP-safe). Pretty-print in development, JSON in production. All `console.log/error` replaced.
|
|
53
|
+
- **File Watcher** (`chokidar`) ā Auto-invalidates cache on file changes. Configurable debounce (default 500ms). New MCP tools: `configure_file_watcher`, `get_file_watcher_status`.
|
|
54
|
+
- **Fuzzy Search** (`fuse.js`) ā Typo-tolerant search. Finds `authenticateUser` when searching `authUser`. Configurable threshold.
|
|
55
|
+
- **Pagination** ā `search_code_pattern` now defaults to 10 results (was 50) with `startIndex` parameter and result footer.
|
|
56
|
+
|
|
57
|
+
#### Testing (74 tests, 100% passing)
|
|
58
|
+
- **Vitest** test framework with V8 coverage
|
|
59
|
+
- Unit tests: parsers, diff, fileLock, backupManager, phase9 optimization
|
|
60
|
+
- Integration tests: full readāwriteārollback cycle, multi-process safety
|
|
61
|
+
- Performance tests: cache hit <100ms, search <2000ms
|
|
62
|
+
- Stress tests: 20 concurrent locks, 10K line files, OOM protection
|
|
63
|
+
|
|
64
|
+
#### Security Fixes (3 production stoppers resolved)
|
|
65
|
+
- **STOPPER #1**: `sanitizeRegexPattern` UUID bug fixed (`\\$&` replacement)
|
|
66
|
+
- **STOPPER #2**: Phase 2 re-acquires file lock before write (race condition eliminated)
|
|
67
|
+
- **STOPPER #3**: `SecurityValidator` applied in Phase 2 (defense in depth)
|
|
68
|
+
|
|
69
|
+
### Changed
|
|
70
|
+
- **Token Optimization**: Phase 2 confirmation no longer repeats diff (50-80% token reduction)
|
|
71
|
+
- **Auto-optimize output**: `get_semantic_repo_map` auto-disables symbols if >100 files or >1000 symbols
|
|
72
|
+
- **Filesystem locks**: `proper-lockfile` replaces in-memory locks (multi-process safe)
|
|
73
|
+
- **OS temp backups**: Backups moved from project root to `os.tmpdir()` (no hot-reload loops)
|
|
74
|
+
- **Myers diff**: `diff-match-patch` replaces custom O(nĆm) LCS (no OOM on large files)
|
|
75
|
+
- **Centralized `walkDir`**: Extracted to `src/utils/fileWalker.ts` (eliminated 3Ć duplication)
|
|
76
|
+
- **Pinned dependencies**: All `^` ranges replaced with exact versions for reproducible installs
|
|
77
|
+
|
|
78
|
+
### Fixed
|
|
79
|
+
- `analyzeImpact` regex patterns now use `safeRegex` (consistent ReDoS protection)
|
|
80
|
+
- `BackupManager.getBackupRoot` uses async `fs.mkdir` (no sync blocking)
|
|
81
|
+
- `validateRegexPattern` documented as best-effort (worker timeout is the real guarantee)
|
|
82
|
+
|
|
83
|
+
### Performance
|
|
84
|
+
- Cache hit: <100ms ā
|
|
85
|
+
- Parse file: <500ms ā
|
|
86
|
+
- Search (20 files): <2000ms ā
|
|
87
|
+
- Token savings: 50-80% ā
|
|
88
|
+
|
|
89
|
+
### Migration from v3.6.1
|
|
90
|
+
- Zero breaking changes
|
|
91
|
+
- New optional parameters: `fuzzyMatch`, `fuzzyThreshold`, `startIndex`, `maxDepth`, `includeSymbols`
|
|
92
|
+
- New tools: `configure_file_watcher`, `get_file_watcher_status`, `get_cache_stats`, `clear_cache`
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
## [3.6.1] - 2026-04-24
|
|
4
97
|
|
|
5
98
|
### š PRODUCTION HARDENING - Security & Infrastructure Complete
|
|
6
99
|
|
|
@@ -30,7 +123,7 @@
|
|
|
30
123
|
- **Security**: SecurityValidator enforced on all 13 handlers
|
|
31
124
|
- **Architecture**: Middleware pipeline (RateLimiter ā FileLock ā Execute ā AuditLog ā Telemetry)
|
|
32
125
|
- **Parsers**: Removed 300+ lines of duplicated replaceSymbol code
|
|
33
|
-
- **Version**: Synchronized all version strings to 3.
|
|
126
|
+
- **Version**: Synchronized all version strings to 3.6.1
|
|
34
127
|
|
|
35
128
|
### Performance
|
|
36
129
|
- Streaming I/O for files >5MB (prevents memory exhaustion)
|
|
@@ -49,7 +142,7 @@
|
|
|
49
142
|
- ā
All security tests passing
|
|
50
143
|
- ā
All rate limiter tests passing
|
|
51
144
|
- ā
All file lock tests passing
|
|
52
|
-
- ā
All v3.
|
|
145
|
+
- ā
All v3.6.1 feature tests passing
|
|
53
146
|
- ā
TypeScript: 0 compilation errors
|
|
54
147
|
- ā
Build: Clean production dist
|
|
55
148
|
|
package/INSTRUCTIONS.md
ADDED
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
# Instructions for AI Agents Using mcp-code-context
|
|
2
|
+
|
|
3
|
+
## šÆ Quick Start
|
|
4
|
+
|
|
5
|
+
This MCP server provides **surgical code editing** with Tree-sitter AST parsing. Use it to read and modify code with precision.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## š Essential Reading Workflow
|
|
10
|
+
|
|
11
|
+
### 1. Start with Repository Map
|
|
12
|
+
```
|
|
13
|
+
@mcp-code-context/get_semantic_repo_map
|
|
14
|
+
directoryPath: /absolute/path/to/project
|
|
15
|
+
projectRoot: /absolute/path/to/project
|
|
16
|
+
format: xml
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
**Why**: Get architectural overview before diving into files. Saves 80% tokens vs reading raw files.
|
|
20
|
+
|
|
21
|
+
### 2. Extract Specific Symbols
|
|
22
|
+
```
|
|
23
|
+
@mcp-code-context/read_file_surgical
|
|
24
|
+
filePath: /path/to/file.ts
|
|
25
|
+
projectRoot: /project/root
|
|
26
|
+
symbolName: functionName
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
**Why**: Read only what you need. If symbol not found, tool suggests available symbols.
|
|
30
|
+
|
|
31
|
+
### 3. Check Impact Before Editing
|
|
32
|
+
```
|
|
33
|
+
@mcp-code-context/analyze_impact
|
|
34
|
+
filePath: /path/to/file.ts
|
|
35
|
+
projectRoot: /project/root
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
**Why**: Know which files depend on what you're about to change.
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## āļø Essential Writing Workflow
|
|
43
|
+
|
|
44
|
+
### Two-Phase Pattern (ALWAYS FOLLOW)
|
|
45
|
+
|
|
46
|
+
**Phase 1: Preview**
|
|
47
|
+
```
|
|
48
|
+
@mcp-code-context/write_file_surgical
|
|
49
|
+
filePath: /path/to/file.ts
|
|
50
|
+
projectRoot: /project/root
|
|
51
|
+
symbolName: myFunction
|
|
52
|
+
newContent: "function myFunction() { return 42; }"
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
**Result**: Returns diff + confirmationToken
|
|
56
|
+
|
|
57
|
+
**Phase 2: Apply**
|
|
58
|
+
```
|
|
59
|
+
@mcp-code-context/write_file_surgical
|
|
60
|
+
filePath: /path/to/file.ts
|
|
61
|
+
projectRoot: /project/root
|
|
62
|
+
symbolName: myFunction
|
|
63
|
+
newContent: "function myFunction() { return 42; }"
|
|
64
|
+
confirm: true
|
|
65
|
+
confirmationToken: "TOKEN_FROM_PHASE_1"
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
**Result**: ā
Success. Changes applied to 1 file(s).
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## šØ Critical Rules
|
|
73
|
+
|
|
74
|
+
### 1. **ALWAYS Use projectRoot**
|
|
75
|
+
Every tool requires `projectRoot` for security. Use the project's root directory.
|
|
76
|
+
|
|
77
|
+
### 2. **NEVER Skip Phase 1**
|
|
78
|
+
Always preview diffs before applying. Tokens are stored in memory and expire on server restart.
|
|
79
|
+
|
|
80
|
+
### 3. **Use Surgical Tools, Not Full File Rewrites**
|
|
81
|
+
ā **Bad**: Read entire file, modify, write entire file
|
|
82
|
+
ā
**Good**: Use `write_file_surgical` to replace only the target symbol
|
|
83
|
+
|
|
84
|
+
### 4. **Check Dependencies First**
|
|
85
|
+
Before removing or renaming symbols, use `analyze_impact` to avoid breaking imports.
|
|
86
|
+
|
|
87
|
+
### 5. **Provide Complete Symbol Code**
|
|
88
|
+
When using `write_file_surgical`, include the full function/method signature + body:
|
|
89
|
+
```typescript
|
|
90
|
+
// ā
GOOD
|
|
91
|
+
newContent: "function hello(name: string): string {\n return `Hello, ${name}`;\n}"
|
|
92
|
+
|
|
93
|
+
// ā BAD (incomplete)
|
|
94
|
+
newContent: "return `Hello, ${name}`;"
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## š Advanced Search
|
|
100
|
+
|
|
101
|
+
### Pattern Search
|
|
102
|
+
```
|
|
103
|
+
@mcp-code-context/search_code_pattern
|
|
104
|
+
rootDir: /project/root
|
|
105
|
+
projectRoot: /project/root
|
|
106
|
+
pattern: "myFunction"
|
|
107
|
+
fileExtensions: [".ts", ".js"]
|
|
108
|
+
maxResults: 10
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Fuzzy Search (v3.6.1)
|
|
112
|
+
```
|
|
113
|
+
@mcp-code-context/search_code_pattern
|
|
114
|
+
rootDir: /project/root
|
|
115
|
+
projectRoot: /project/root
|
|
116
|
+
pattern: "authUser"
|
|
117
|
+
fuzzyMatch: true
|
|
118
|
+
fuzzyThreshold: 0.6
|
|
119
|
+
maxResults: 5
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
**Finds**: `authenticateUser`, `authorizeUser`, etc.
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## š”ļø Safety Features
|
|
127
|
+
|
|
128
|
+
### Automatic Backups
|
|
129
|
+
Every write creates a backup. Rollback if needed:
|
|
130
|
+
```
|
|
131
|
+
@mcp-code-context/rollback_file
|
|
132
|
+
filePath: /path/to/file.ts
|
|
133
|
+
projectRoot: /project/root
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Cache Management
|
|
137
|
+
```
|
|
138
|
+
@mcp-code-context/get_cache_stats
|
|
139
|
+
projectRoot: /project/root
|
|
140
|
+
|
|
141
|
+
@mcp-code-context/clear_cache
|
|
142
|
+
projectRoot: /project/root
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
## š” Pro Tips
|
|
148
|
+
|
|
149
|
+
### 1. **Use className for Method Scoping**
|
|
150
|
+
When a file has multiple classes with same method name:
|
|
151
|
+
```
|
|
152
|
+
@mcp-code-context/read_file_surgical
|
|
153
|
+
filePath: /path/to/file.ts
|
|
154
|
+
symbolName: render
|
|
155
|
+
className: MyComponent
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### 2. **Batch Operations with rename_symbol**
|
|
159
|
+
Rename across entire codebase in one operation:
|
|
160
|
+
```
|
|
161
|
+
@mcp-code-context/rename_symbol
|
|
162
|
+
filePath: /path/to/definition.ts
|
|
163
|
+
projectRoot: /project/root
|
|
164
|
+
oldName: oldFunction
|
|
165
|
+
newName: newFunction
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### 3. **Insert New Code Precisely**
|
|
169
|
+
```
|
|
170
|
+
@mcp-code-context/insert_symbol
|
|
171
|
+
filePath: /path/to/file.ts
|
|
172
|
+
projectRoot: /project/root
|
|
173
|
+
code: "private newMethod() { }"
|
|
174
|
+
anchorSymbol: existingMethod
|
|
175
|
+
position: after
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### 4. **Read Specific Lines Only**
|
|
179
|
+
```
|
|
180
|
+
@mcp-code-context/read_file_lines
|
|
181
|
+
filePath: /path/to/file.ts
|
|
182
|
+
projectRoot: /project/root
|
|
183
|
+
startLine: 100
|
|
184
|
+
endLine: 120
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
---
|
|
188
|
+
|
|
189
|
+
## ā ļø Common Mistakes
|
|
190
|
+
|
|
191
|
+
### ā Mistake 1: Forgetting projectRoot
|
|
192
|
+
```
|
|
193
|
+
// WRONG
|
|
194
|
+
@mcp-code-context/read_file_surgical
|
|
195
|
+
filePath: /path/to/file.ts
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### ā Mistake 2: Skipping Phase 1
|
|
199
|
+
```
|
|
200
|
+
// WRONG - No preview
|
|
201
|
+
@mcp-code-context/write_file_surgical
|
|
202
|
+
confirm: true
|
|
203
|
+
confirmationToken: "FAKE_TOKEN"
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### ā Mistake 3: Incomplete Symbol Code
|
|
207
|
+
```
|
|
208
|
+
// WRONG - Missing function signature
|
|
209
|
+
newContent: "{ return 42; }"
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
### ā Mistake 4: Not Checking Impact
|
|
213
|
+
```
|
|
214
|
+
// WRONG - Removing without checking dependencies
|
|
215
|
+
@mcp-code-context/remove_symbol
|
|
216
|
+
symbolName: importantFunction
|
|
217
|
+
force: true
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
---
|
|
221
|
+
|
|
222
|
+
## š Performance Tips
|
|
223
|
+
|
|
224
|
+
1. **Use get_semantic_repo_map first** - 80% token savings
|
|
225
|
+
2. **Extract symbols, not full files** - 90% token savings
|
|
226
|
+
3. **Use fuzzy search for discovery** - Finds similar patterns
|
|
227
|
+
4. **Enable caching** - 10x faster repeated operations
|
|
228
|
+
5. **Paginate search results** - Default 10 results, use `startIndex` for more
|
|
229
|
+
|
|
230
|
+
---
|
|
231
|
+
|
|
232
|
+
## š Example Workflow
|
|
233
|
+
|
|
234
|
+
```
|
|
235
|
+
1. Get repo map
|
|
236
|
+
ā @mcp-code-context/get_semantic_repo_map
|
|
237
|
+
|
|
238
|
+
2. Find target symbol
|
|
239
|
+
ā @mcp-code-context/read_file_surgical
|
|
240
|
+
|
|
241
|
+
3. Check dependencies
|
|
242
|
+
ā @mcp-code-context/analyze_impact
|
|
243
|
+
|
|
244
|
+
4. Preview changes (Phase 1)
|
|
245
|
+
ā @mcp-code-context/write_file_surgical
|
|
246
|
+
|
|
247
|
+
5. Review diff, then apply (Phase 2)
|
|
248
|
+
ā @mcp-code-context/write_file_surgical (with token)
|
|
249
|
+
|
|
250
|
+
6. Verify or rollback if needed
|
|
251
|
+
ā @mcp-code-context/rollback_file
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
---
|
|
255
|
+
|
|
256
|
+
## š v3.6.1 Features
|
|
257
|
+
|
|
258
|
+
- ā
**Fuzzy Search**: Find similar patterns with typo tolerance
|
|
259
|
+
- ā
**Pagination**: Default 10 results, use `startIndex` for more
|
|
260
|
+
- ā
**Token Optimization**: Phase 2 no longer repeats diff (97% savings)
|
|
261
|
+
- ā
**Auto-Optimize**: Large repos automatically disable symbols
|
|
262
|
+
- ā
**File Watcher**: Auto-invalidate cache on file changes
|
|
263
|
+
- ā
**Persistent Cache**: 10x faster with sql.js WASM SQLite
|
|
264
|
+
|
|
265
|
+
---
|
|
266
|
+
|
|
267
|
+
## š Full Documentation
|
|
268
|
+
|
|
269
|
+
See `llms.txt` for complete API reference and technical details.
|
|
270
|
+
|
|
271
|
+
---
|
|
272
|
+
|
|
273
|
+
**Version**: 3.6.1
|
|
274
|
+
**Last Updated**: May 1, 2026
|
package/README.md
CHANGED
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
[](https://www.npmjs.com/package/mcp-code-context)
|
|
5
5
|
[](https://www.npmjs.com/package/mcp-code-context)
|
|
6
6
|
[]()
|
|
7
|
-
[]()
|
|
8
8
|
[](https://ko-fi.com/achatainga)
|
|
9
9
|
[](https://paypal.me/achatainga)
|
|
10
10
|
|
|
11
|
-
> MCP server with **Tree-sitter WASM parsers** for 100% AST accuracy. Zero native dependencies.
|
|
11
|
+
> MCP server with **Tree-sitter WASM parsers** for 100% AST accuracy. Zero native dependencies. Production-ready with persistent caching, structured logging, fuzzy search, and multi-process safety.
|
|
12
12
|
|
|
13
13
|
## š Quick Start (Claude Desktop)
|
|
14
14
|
|
|
@@ -30,6 +30,8 @@
|
|
|
30
30
|
|
|
31
31
|
Works with **Claude Desktop**, **Cursor**, **Windsurf**, **GitHub Copilot**, **Amazon Q**, and any [Model Context Protocol](https://modelcontextprotocol.io/) compatible client.
|
|
32
32
|
|
|
33
|
+
š **For AI Agents**: See [INSTRUCTIONS.md](INSTRUCTIONS.md) for essential usage patterns and best practices.
|
|
34
|
+
|
|
33
35
|
---
|
|
34
36
|
|
|
35
37
|
## š” Why This Exists
|
|
@@ -64,6 +66,20 @@ Built to be robust and precise. Both read and write engines are tested against r
|
|
|
64
66
|
|
|
65
67
|
## Features
|
|
66
68
|
|
|
69
|
+
### What's New in v3.6.1
|
|
70
|
+
|
|
71
|
+
| Feature | Description |
|
|
72
|
+
|---------|-------------|
|
|
73
|
+
| ā” **Persistent Cache** | WASM SQLite cache ā <100ms hits, 10Ć faster on repeated reads |
|
|
74
|
+
| š **Structured Logging** | pino JSON logging to stderr (MCP-safe, never pollutes stdio) |
|
|
75
|
+
| šļø **File Watcher** | chokidar auto-invalidates cache on file changes |
|
|
76
|
+
| š **Fuzzy Search** | fuse.js finds `authUser` when you search `authenticateUser` |
|
|
77
|
+
| š **Pagination** | Search defaults to 10 results with `startIndex` for navigation |
|
|
78
|
+
| š **Multi-process Safe** | Filesystem locks via `proper-lockfile` (was in-memory) |
|
|
79
|
+
| š¾ **OS Temp Backups** | Backups in `os.tmpdir()` ā no more hot-reload loops |
|
|
80
|
+
| š§Ŗ **74 Tests** | Unit + integration + performance + stress tests |
|
|
81
|
+
| šÆ **Token Savings** | 50-80% reduction: compact diffs, no Phase 2 repeat, auto-optimize output |
|
|
82
|
+
|
|
67
83
|
### Read
|
|
68
84
|
- š³ **AST-based compression** ā Real Tree-sitter WASM parsers for TypeScript/JavaScript/Python/PHP/Dart. Zero regex-based parsing.
|
|
69
85
|
- š¬ **Surgical symbol extraction** ā Extract a single function, class, or method from a file by name. Use `className` to scope disambiguation (e.g., getting multiple `build()` methods in Dart).
|
|
@@ -107,6 +123,8 @@ Built to be robust and precise. Both read and write engines are tested against r
|
|
|
107
123
|
|
|
108
124
|
**TypeScript, JavaScript, PHP**: Fully supported with AST-aware renaming ā
|
|
109
125
|
|
|
126
|
+
**Note**: While the definition file uses pure AST replacement, dependent files (imports) are updated using regex word-boundaries. Review the generated diffs carefully to ensure strings or comments sharing the same name aren't unintentionally modified.
|
|
127
|
+
|
|
110
128
|
### `get_semantic_repo_map` Tool
|
|
111
129
|
|
|
112
130
|
- **Max files**: Limited to 500 files to prevent timeouts
|
|
@@ -216,9 +234,10 @@ Search for code patterns across multiple files with context. Respects `.gitignor
|
|
|
216
234
|
- `pattern` (required) ā Regular expression pattern to search
|
|
217
235
|
- `fileExtensions` (optional) ā Array of extensions to search (e.g., `[".ts", ".dart"]`)
|
|
218
236
|
- `excludeDirs` (optional) ā Directories to exclude (default: `["node_modules", "dist", "build"]`)
|
|
219
|
-
- `
|
|
220
|
-
- `
|
|
221
|
-
- `
|
|
237
|
+
- `maxResults` (optional) ā Maximum matches per page (default: 10)
|
|
238
|
+
- `startIndex` (optional) ā Pagination offset (default: 0)
|
|
239
|
+
- `fuzzyMatch` (optional) ā Enable fuzzy/typo-tolerant matching (default: false)
|
|
240
|
+
- `fuzzyThreshold` (optional) ā Fuzzy sensitivity 0.0ā1.0 (default: 0.4)
|
|
222
241
|
|
|
223
242
|
#### 6. `rollback_file`
|
|
224
243
|
Surgically restore a file to a previous state from the automated backup system.
|
|
@@ -404,9 +423,16 @@ npm run dev
|
|
|
404
423
|
- **Protocol:** [Model Context Protocol](https://modelcontextprotocol.io/)
|
|
405
424
|
- **AST Engines:** web-tree-sitter@0.25.1 (WASM) for TypeScript/JS/Python/PHP/Dart
|
|
406
425
|
- **Language Grammars:** tree-sitter-wasms@0.1.13 (ABI v15)
|
|
426
|
+
- **Cache:** sql.js@1.14.1 (WASM SQLite, zero native deps)
|
|
427
|
+
- **Logging:** pino@10.3.1 (JSON to stderr, MCP-safe)
|
|
428
|
+
- **File Watcher:** chokidar@5.0.0 (auto cache invalidation)
|
|
429
|
+
- **Fuzzy Search:** fuse.js@7.3.0 (typo-tolerant matching)
|
|
430
|
+
- **File Locking:** proper-lockfile@4.1.2 (multi-process safe, OS temp)
|
|
431
|
+
- **Diff:** diff-match-patch@1.0.5 (Myers algorithm, O(n+d²))
|
|
407
432
|
- **Ignore Engine:** `ignore` npm package (full .gitignore spec support)
|
|
408
|
-
- **Safety Features:** Mandatory two-phase confirmation, rolling 5-version backups, fuzzy matching, dependency checking, surgical restoration.
|
|
433
|
+
- **Safety Features:** Mandatory two-phase confirmation, rolling 5-version backups, fuzzy matching, dependency checking, surgical restoration, ReDoS protection via worker_threads.
|
|
409
434
|
- **Portability:** 100% WASM - no native dependencies, works on all platforms
|
|
435
|
+
- **Tests:** 74 passing (unit + integration + performance + stress)
|
|
410
436
|
|
|
411
437
|
## Contributing
|
|
412
438
|
|
|
@@ -420,6 +446,33 @@ See [SECURITY.md](SECURITY.md) for security policies and reporting vulnerabiliti
|
|
|
420
446
|
|
|
421
447
|
See [TROUBLESHOOTING.md](TROUBLESHOOTING.md) for common issues and solutions.
|
|
422
448
|
|
|
449
|
+
### Viewing Logs
|
|
450
|
+
|
|
451
|
+
Because MCP uses `stdout` for protocol communication, all logs are safely routed to `stderr`. You can view them in your client's log files:
|
|
452
|
+
|
|
453
|
+
- **Claude Desktop (macOS)**: `~/Library/Logs/Claude/mcp-server-mcp-code-context.log`
|
|
454
|
+
- **Claude Desktop (Windows)**: `%APPDATA%\Claude\logs\mcp-server-mcp-code-context.log`
|
|
455
|
+
- **Cursor**: `Output` panel ā Select `mcp-code-context` from the dropdown
|
|
456
|
+
|
|
457
|
+
**Environment Variables** (optional):
|
|
458
|
+
|
|
459
|
+
```json
|
|
460
|
+
{
|
|
461
|
+
"mcpServers": {
|
|
462
|
+
"mcp-code-context": {
|
|
463
|
+
"command": "npx",
|
|
464
|
+
"args": ["-y", "mcp-code-context"],
|
|
465
|
+
"env": {
|
|
466
|
+
"NODE_ENV": "development",
|
|
467
|
+
"LOG_LEVEL": "debug"
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
```
|
|
473
|
+
|
|
474
|
+
Supported `LOG_LEVEL` values: `fatal`, `error`, `warn`, `info`, `debug`, `trace` (default: `info`).
|
|
475
|
+
|
|
423
476
|
## Changelog
|
|
424
477
|
|
|
425
478
|
See [CHANGELOG.md](CHANGELOG.md) for version history.
|
package/SECURITY.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
# Security Policy - mcp-code-context v3.
|
|
1
|
+
# Security Policy - mcp-code-context v3.6.1
|
|
2
2
|
|
|
3
|
-
## š Security Improvements in v3.
|
|
3
|
+
## š Security Improvements in v3.6.1
|
|
4
4
|
|
|
5
5
|
This release addresses **all critical security vulnerabilities** from comprehensive adversarial audit, implements full middleware pipeline, and hardens all 13 tool handlers.
|
|
6
6
|
|
|
@@ -10,11 +10,11 @@ This release addresses **all critical security vulnerabilities** from comprehens
|
|
|
10
10
|
|
|
11
11
|
### 1. Path Traversal (HIGH)
|
|
12
12
|
**CVSS Score**: 8.1 (High)
|
|
13
|
-
**Status**: ā
FIXED in v3.2.0, **hardened in v3.
|
|
13
|
+
**Status**: ā
FIXED in v3.2.0, **hardened in v3.6.1**
|
|
14
14
|
|
|
15
15
|
**Description**: Path traversal check occurred BEFORE path normalization, allowing bypass with absolute paths.
|
|
16
16
|
|
|
17
|
-
**Fix**: Check boundary AFTER `path.resolve()` normalization. In v3.
|
|
17
|
+
**Fix**: Check boundary AFTER `path.resolve()` normalization. In v3.6.1, **all 13 handlers** now require `projectRoot` and validate via `SecurityValidator`.
|
|
18
18
|
|
|
19
19
|
---
|
|
20
20
|
|
|
@@ -40,7 +40,7 @@ This release addresses **all critical security vulnerabilities** from comprehens
|
|
|
40
40
|
|
|
41
41
|
### 4. ReDoS in searchPattern and readLines (MEDIUM)
|
|
42
42
|
**CVSS Score**: 5.3 (Medium)
|
|
43
|
-
**Status**: ā
FIXED in v3.
|
|
43
|
+
**Status**: ā
FIXED in v3.6.1
|
|
44
44
|
|
|
45
45
|
**Description**: User-provided regex patterns could cause catastrophic backtracking.
|
|
46
46
|
|
|
@@ -58,7 +58,7 @@ This release addresses **all critical security vulnerabilities** from comprehens
|
|
|
58
58
|
|
|
59
59
|
### 6. extractSymbol API Mismatch (CRITICAL)
|
|
60
60
|
**CVSS Score**: 9.0 (Critical)
|
|
61
|
-
**Status**: ā
FIXED in v3.
|
|
61
|
+
**Status**: ā
FIXED in v3.6.1
|
|
62
62
|
|
|
63
63
|
**Description**: `read.ts` passed `content` as `symbolName` and real `symbolName` as `className`. Symbol extraction was 100% broken.
|
|
64
64
|
|
|
@@ -68,7 +68,7 @@ This release addresses **all critical security vulnerabilities** from comprehens
|
|
|
68
68
|
|
|
69
69
|
### 7. Handlers Without Path Validation (HIGH)
|
|
70
70
|
**CVSS Score**: 8.5 (High)
|
|
71
|
-
**Status**: ā
FIXED in v3.
|
|
71
|
+
**Status**: ā
FIXED in v3.6.1
|
|
72
72
|
|
|
73
73
|
**Description**: `readLines`, `searchPattern`, `analyzeImpact`, `getSemanticRepoMap` had no path boundary check.
|
|
74
74
|
|
|
@@ -78,7 +78,7 @@ This release addresses **all critical security vulnerabilities** from comprehens
|
|
|
78
78
|
|
|
79
79
|
### 8. renameSymbol Arbitrary Write (HIGH)
|
|
80
80
|
**CVSS Score**: 8.0 (High)
|
|
81
|
-
**Status**: ā
FIXED in v3.
|
|
81
|
+
**Status**: ā
FIXED in v3.6.1
|
|
82
82
|
|
|
83
83
|
**Description**: `renameSymbol` wrote dependent files without SecurityValidator check, using non-atomic writes.
|
|
84
84
|
|
|
@@ -88,7 +88,7 @@ This release addresses **all critical security vulnerabilities** from comprehens
|
|
|
88
88
|
|
|
89
89
|
### 9. LCS Diff OOM (MEDIUM)
|
|
90
90
|
**CVSS Score**: 5.0 (Medium)
|
|
91
|
-
**Status**: ā
FIXED in v3.
|
|
91
|
+
**Status**: ā
FIXED in v3.6.1
|
|
92
92
|
|
|
93
93
|
**Description**: LCS diff algorithm is O(n²) memory ā 10K-line files cause OOM.
|
|
94
94
|
|
|
@@ -101,16 +101,16 @@ This release addresses **all critical security vulnerabilities** from comprehens
|
|
|
101
101
|
### Defense in Depth
|
|
102
102
|
|
|
103
103
|
1. **Input Validation**
|
|
104
|
-
- Path boundary enforcement on ALL handlers (v3.
|
|
104
|
+
- Path boundary enforcement on ALL handlers (v3.6.1)
|
|
105
105
|
- File size limits (10MB per file, 50MB total)
|
|
106
106
|
- Regex sanitization + timeout (1s limit)
|
|
107
107
|
|
|
108
|
-
2. **Two-Phase Write Workflow** (v3.
|
|
108
|
+
2. **Two-Phase Write Workflow** (v3.6.1)
|
|
109
109
|
- Phase 1: Dry-run returns diff + confirmation token
|
|
110
110
|
- Phase 2: Apply with token (5-minute expiry)
|
|
111
111
|
- Max 50 pending operations
|
|
112
112
|
|
|
113
|
-
3. **Middleware Pipeline** (v3.
|
|
113
|
+
3. **Middleware Pipeline** (v3.6.1)
|
|
114
114
|
- Rate limiting (token bucket per operation)
|
|
115
115
|
- File locking (prevents concurrent writes)
|
|
116
116
|
- Audit logging (persistent `.mcp-audit-logs/`)
|
|
@@ -160,7 +160,7 @@ node dist-tests/tests/test-security.js
|
|
|
160
160
|
- [x] Syntax validation
|
|
161
161
|
- [x] Bounded memory in compress
|
|
162
162
|
|
|
163
|
-
### v3.
|
|
163
|
+
### v3.6.1 ā
|
|
164
164
|
- [x] Regex timeout enforcement (safeRegexTest)
|
|
165
165
|
- [x] Rate limiting (token bucket)
|
|
166
166
|
- [x] File locking (concurrent write prevention)
|
|
@@ -174,4 +174,4 @@ node dist-tests/tests/test-security.js
|
|
|
174
174
|
---
|
|
175
175
|
|
|
176
176
|
**Last Updated**: 2026-04-24
|
|
177
|
-
**Version**: 3.
|
|
177
|
+
**Version**: 3.6.1
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cache Manager - v3.6.1
|
|
3
|
+
* WASM SQLite cache with debounced persistence
|
|
4
|
+
*/
|
|
5
|
+
export interface CachedFile {
|
|
6
|
+
filePath: string;
|
|
7
|
+
hash: string;
|
|
8
|
+
symbols: any[];
|
|
9
|
+
lastModified: number;
|
|
10
|
+
cachedAt: number;
|
|
11
|
+
}
|
|
12
|
+
export declare class CacheManager {
|
|
13
|
+
private db;
|
|
14
|
+
private dbPath;
|
|
15
|
+
private cacheDir;
|
|
16
|
+
private isDirty;
|
|
17
|
+
private persistTimer;
|
|
18
|
+
private initPromise;
|
|
19
|
+
private watcher;
|
|
20
|
+
private projectRoot;
|
|
21
|
+
constructor(projectRoot: string);
|
|
22
|
+
private init;
|
|
23
|
+
private initSchema;
|
|
24
|
+
get(filePath: string, currentHash: string): Promise<CachedFile | null>;
|
|
25
|
+
set(file: CachedFile): Promise<void>;
|
|
26
|
+
invalidate(filePath: string): Promise<void>;
|
|
27
|
+
clear(): Promise<void>;
|
|
28
|
+
getStats(): Promise<{
|
|
29
|
+
totalEntries: number;
|
|
30
|
+
totalSize: number;
|
|
31
|
+
oldestEntry: number | null;
|
|
32
|
+
newestEntry: number | null;
|
|
33
|
+
}>;
|
|
34
|
+
private schedulePersist;
|
|
35
|
+
private persist;
|
|
36
|
+
close(): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Synchronous persist for process exit handlers
|
|
39
|
+
* CRITICAL: Only call from global shutdown hooks
|
|
40
|
+
*/
|
|
41
|
+
persistOnExit(): void;
|
|
42
|
+
startWatcher(debounceMs?: number): void;
|
|
43
|
+
stopWatcher(): void;
|
|
44
|
+
getWatcherStatus(): {
|
|
45
|
+
isWatching: boolean;
|
|
46
|
+
watchedFiles: number;
|
|
47
|
+
};
|
|
48
|
+
}
|