mcp-code-context 3.5.2 → 3.6.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 (83) hide show
  1. package/CHANGELOG.md +57 -3
  2. package/HIRE_ME.md +234 -0
  3. package/INSTRUCTIONS.md +274 -0
  4. package/README.md +486 -304
  5. package/SECURITY.md +14 -14
  6. package/SPONSORS.md +104 -0
  7. package/dist/src/core/cacheManager.d.ts +44 -0
  8. package/dist/src/core/cacheManager.js +255 -0
  9. package/dist/src/core/cacheManager.js.map +1 -0
  10. package/dist/src/core/engine.d.ts +1 -1
  11. package/dist/src/core/engine.js +1 -1
  12. package/dist/src/core/validator.d.ts +1 -1
  13. package/dist/src/core/validator.js +21 -9
  14. package/dist/src/core/validator.js.map +1 -1
  15. package/dist/src/index.d.ts +6 -1
  16. package/dist/src/index.js +197 -20
  17. package/dist/src/index.js.map +1 -1
  18. package/dist/src/operations/compress.d.ts +3 -1
  19. package/dist/src/operations/compress.js +47 -48
  20. package/dist/src/operations/compress.js.map +1 -1
  21. package/dist/src/operations/confirmationStore.d.ts +1 -1
  22. package/dist/src/operations/confirmationStore.js +1 -1
  23. package/dist/src/operations/read.d.ts +5 -1
  24. package/dist/src/operations/read.js +129 -60
  25. package/dist/src/operations/read.js.map +1 -1
  26. package/dist/src/operations/write.d.ts +2 -2
  27. package/dist/src/operations/write.js +83 -59
  28. package/dist/src/operations/write.js.map +1 -1
  29. package/dist/src/parsers/base.d.ts +1 -1
  30. package/dist/src/parsers/base.js +1 -1
  31. package/dist/src/parsers/dartTreeSitter.d.ts +1 -1
  32. package/dist/src/parsers/dartTreeSitter.js +1 -1
  33. package/dist/src/parsers/php.d.ts +1 -1
  34. package/dist/src/parsers/php.js +1 -1
  35. package/dist/src/parsers/python.d.ts +1 -1
  36. package/dist/src/parsers/python.js +1 -1
  37. package/dist/src/parsers/registry.d.ts +1 -1
  38. package/dist/src/parsers/registry.js +1 -1
  39. package/dist/src/parsers/typescript.d.ts +1 -1
  40. package/dist/src/parsers/typescript.js +1 -1
  41. package/dist/src/utils/auditLogger.d.ts +1 -1
  42. package/dist/src/utils/auditLogger.js +3 -2
  43. package/dist/src/utils/auditLogger.js.map +1 -1
  44. package/dist/src/utils/backupManager.d.ts +30 -9
  45. package/dist/src/utils/backupManager.js +75 -33
  46. package/dist/src/utils/backupManager.js.map +1 -1
  47. package/dist/src/utils/constants.d.ts +13 -2
  48. package/dist/src/utils/constants.js +21 -2
  49. package/dist/src/utils/constants.js.map +1 -1
  50. package/dist/src/utils/diff.d.ts +37 -7
  51. package/dist/src/utils/diff.js +91 -101
  52. package/dist/src/utils/diff.js.map +1 -1
  53. package/dist/src/utils/fileLock.d.ts +25 -50
  54. package/dist/src/utils/fileLock.js +66 -100
  55. package/dist/src/utils/fileLock.js.map +1 -1
  56. package/dist/src/utils/fileWalker.d.ts +28 -0
  57. package/dist/src/utils/fileWalker.js +57 -0
  58. package/dist/src/utils/fileWalker.js.map +1 -0
  59. package/dist/src/utils/fileWatcher.d.ts +23 -0
  60. package/dist/src/utils/fileWatcher.js +80 -0
  61. package/dist/src/utils/fileWatcher.js.map +1 -0
  62. package/dist/src/utils/fuzzySearch.d.ts +22 -0
  63. package/dist/src/utils/fuzzySearch.js +36 -0
  64. package/dist/src/utils/fuzzySearch.js.map +1 -0
  65. package/dist/src/utils/logger.d.ts +19 -0
  66. package/dist/src/utils/logger.js +50 -0
  67. package/dist/src/utils/logger.js.map +1 -0
  68. package/dist/src/utils/rateLimiter.d.ts +1 -1
  69. package/dist/src/utils/rateLimiter.js +1 -1
  70. package/dist/src/utils/safeRegex.d.ts +1 -1
  71. package/dist/src/utils/safeRegex.js +1 -1
  72. package/dist/src/utils/searchTools.d.ts +14 -0
  73. package/dist/src/utils/searchTools.js +94 -0
  74. package/dist/src/utils/searchTools.js.map +1 -0
  75. package/dist/src/utils/streaming.d.ts +1 -1
  76. package/dist/src/utils/streaming.js +1 -1
  77. package/dist/src/utils/telemetry.d.ts +1 -1
  78. package/dist/src/utils/telemetry.js +1 -1
  79. package/llms.txt +5 -5
  80. package/package.json +44 -11
  81. package/vitest.config.ts +37 -0
  82. package/CHANGELOG_v3.2.0.md +0 -196
  83. package/CHANGELOG_v3.3.0.md +0 -266
package/README.md CHANGED
@@ -1,304 +1,486 @@
1
- # mcp-code-context
2
-
3
- [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
4
- [![Tests](https://img.shields.io/badge/tests-passing-success.svg)]()
5
- [![TypeScript](https://img.shields.io/badge/TypeScript-100%25-blue.svg)]()
6
- [![Version](https://img.shields.io/badge/version-3.1.0-blue.svg)]()
7
-
8
- > MCP server with **Tree-sitter WASM parsers** for 100% AST accuracy. Zero native dependencies.
9
-
10
- ## šŸš€ Quick Start (Claude Desktop)
11
-
12
- 1. **Install**: `npm install -g mcp-code-context`
13
- 2. **Configure**: Add to `claude_desktop_config.json`:
14
- ```json
15
- {
16
- "mcpServers": {
17
- "code-context": {
18
- "command": "npx",
19
- "args": ["-y", "mcp-code-context"]
20
- }
21
- }
22
- }
23
- ```
24
- 3. **Enjoy**: Use symbols like `@code-context` to map repos or edit code surgically.
25
-
26
- **No build tools required** - Works on Windows/Mac/Linux without Visual Studio, Python, or node-gyp.
27
-
28
- Works with **Claude Desktop**, **Cursor**, **Windsurf**, **GitHub Copilot**, **Amazon Q**, and any [Model Context Protocol](https://modelcontextprotocol.io/) compatible client.
29
-
30
- ## The Problem
31
-
32
- LLMs working with code face two bottlenecks:
33
- 1. **Reading**: Sending raw source files wastes the context window on function bodies and boilerplate. A 500-line file might contain only 30 lines of *structural* information the LLM needs.
34
- 2. **Writing**: Rewriting entire files to change one function is error-prone, token-expensive, and risks corrupting unrelated code.
35
-
36
- ## The Solution
37
-
38
- `mcp-code-context` provides **11 tools** — 5 for reading, 1 for cleanup, and 5 for writing — that operate at the **symbol level** (functions, classes, methods). Furthermore, tools support a `className` scope which correctly isolates identical symbol names in the same file (e.g. Flutter `build()` methods) to avoid reading or changing the wrong logic. Read tools extract structural skeletons. Write tools splice changes into the exact AST location.
39
-
40
- | File | Original | Compressed | Reduction |
41
- |------|----------|------------|-----------|
42
- | PHP class (426 lines) | 426 | 60 | **85.9%** |
43
- | Dart repository (230 lines) | 230 | 30 | **87.0%** |
44
- | PHP config (68 lines) | 68 | 15 | **77.9%** |
45
-
46
- ## Reliability & Testing
47
-
48
- Built to be robust and precise. Both read and write engines are tested against real-world, complex codebases (including nested generic types in Dart, complex interfaces in PHP, and multi-file rename operations) with a **100% test pass rate** across all languages and operations.
49
-
50
- ## Features
51
-
52
- ### Read
53
- - 🌳 **AST-based compression** — Real Tree-sitter WASM parsers for TypeScript/JavaScript/Python/PHP/Dart. Zero regex-based parsing.
54
- - šŸ”¬ **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).
55
- - šŸ’„ **Impact analysis** — Discover all files that depend on a given file before refactoring. Supports ES imports, CommonJS `require()`, Python imports, PHP `use`/`require_once`/`include`, and Dart imports.
56
- - šŸ“ **Smart file walking** — Respects `.gitignore` and `.repomixignore` rules. Automatically excludes `node_modules`, `dist`, `vendor`, `.git`, etc.
57
- - šŸ“„ **Multi-format output** — XML (optimized for LLM consumption) or Markdown (human-readable).
58
-
59
- ### Write
60
- - āœļø **Surgical symbol replacement** — Replace a function, method, or class body without touching the rest of the file. Narrow down the target using the `className` parameter.
61
- - āž• **Precise code insertion** — Insert new code before/after a symbol, or inside a class at the start/end.
62
- - šŸ”„ **Repository-wide rename** — Rename a symbol in its definition AND all files that import it, atomically.
63
- - šŸ—‘ļø **Safe symbol removal** — Delete code with automatic dependency checking to prevent breakage.
64
- - šŸ” **Mandatory dry-run flow** — Write tools return a preview diff and a `confirmationToken` by default. Changes are only applied after explicit confirmation.
65
- - šŸ’¾ **Robust rolling backups** — Automatically keeps the last 5 versions of modified files in a hidden `.mcp-backups/` directory.
66
- - āŖ **Surgical rollback** — Revert files to any of the 5 previous states using the new `rollback_file` tool.
67
- - šŸ¤– **Fuzzy symbol matching** — When a symbol is not found, the server provides structured suggestions based on Levenshtein distance.
68
- - šŸ” **Private symbol support** — Full support for `_` and `__` prefixed symbols in Dart and Python.
69
-
70
- ## Supported Languages
71
-
72
- | Language | Read (Compress + Extract) | Write (Replace + Insert + Rename + Remove) | Import Analysis |
73
- |----------|---------------------------|---------------------------------------------|------------------|
74
- | TypeScript / JavaScript | āœ… AST (Tree-sitter WASM) | āœ… AST (Tree-sitter WASM) | āœ… |
75
- | PHP | āœ… AST (Tree-sitter WASM) | āœ… AST + line-splice | āœ… |
76
- | Dart | āœ… AST (Tree-sitter WASM) | āœ… AST + line-splice | āœ… |
77
- | Python | āœ… AST (Tree-sitter WASM) | āœ… Indentation-aware | āœ… |
78
- | Others (JSON, YAML, CSS, etc.) | Passthrough / truncation | — | — |
79
-
80
- ## āš ļø Known Limitations
81
-
82
- ### `rename_symbol` Tool
83
-
84
- **Dart and Python**: Cross-file rename is **NOT supported** for `.dart`, `.py`, and `.pyi` files.
85
-
86
- - **Reason**: No AST parser available for safe cross-file refactoring
87
- - **Risk**: Regex-based rename may corrupt strings, comments, or unrelated code
88
- - **Recommendation**: Use IDE refactoring tools instead:
89
- - **Dart**: VS Code with Dart extension (F2 key) or IntelliJ IDEA
90
- - **Python**: PyCharm, VS Code with Pylance (F2 key)
91
- - **Alternative**: Use `write_file_surgical` to rename within a single file
92
-
93
- **TypeScript, JavaScript, PHP**: Fully supported with AST-aware renaming āœ…
94
-
95
- ### `get_semantic_repo_map` Tool
96
-
97
- - **Max files**: Limited to 500 files to prevent timeouts
98
- - **Performance**: Synchronous I/O may take 10-30 seconds on large repositories
99
- - **Recommendation**: Use `@folder` syntax to target specific directories
100
-
101
- ### General
102
-
103
- - **Validation**: No automatic syntax checking after edits. Always review diffs carefully before confirming.
104
- - **Backups**: 5-version rolling backup system. Use `rollback_file` if something goes wrong.
105
- - **Large files**: Files >10MB are skipped for safety.
106
-
107
- ## Installation
108
-
109
- ```bash
110
- # Clone the repository
111
- git clone https://github.com/YOUR_USERNAME/mcp-code-context.git
112
- cd mcp-code-context
113
-
114
- # Install dependencies (no build tools required!)
115
- npm install
116
-
117
- # Build
118
- npm run build
119
- ```
120
-
121
- **Note**: Unlike v2.x, this version uses **web-tree-sitter (WASM)** instead of native bindings. No Visual Studio, Python, or node-gyp required!
122
-
123
- ## Configuration
124
-
125
- ### Claude Desktop
126
-
127
- Add to your `claude_desktop_config.json`:
128
-
129
- ```json
130
- {
131
- "mcpServers": {
132
- "mcp-code-context": {
133
- "command": "node",
134
- "args": ["/absolute/path/to/mcp-code-context/dist/index.js"]
135
- }
136
- }
137
- }
138
- ```
139
-
140
- ### Cursor
141
-
142
- Add to your Cursor MCP settings (`.cursor/mcp.json`):
143
-
144
- ```json
145
- {
146
- "mcpServers": {
147
- "mcp-code-context": {
148
- "command": "node",
149
- "args": ["/absolute/path/to/mcp-code-context/dist/index.js"]
150
- }
151
- }
152
- }
153
- ```
154
-
155
- ### Windsurf
156
-
157
- Add to your Windsurf MCP config:
158
-
159
- ```json
160
- {
161
- "mcpServers": {
162
- "mcp-code-context": {
163
- "command": "node",
164
- "args": ["/absolute/path/to/mcp-code-context/dist/index.js"]
165
- }
166
- }
167
- }
168
- ```
169
-
170
- ### Amazon Q / Other MCP Clients
171
-
172
- Any MCP-compatible client can use this server. The transport is **stdio** (JSON-RPC over stdin/stdout). Point your client to `node dist/index.js`.
173
-
174
- ## Tools
175
-
176
- ### Read Tools
177
-
178
- #### 1. `get_semantic_repo_map`
179
- Generate a compressed architectural overview of an entire repository.
180
- - `directoryPath` (required) — Path to the repo root
181
- - `format` (optional) — `"xml"` (default) or `"markdown"`
182
-
183
- #### 2. `read_file_surgical`
184
- Read a file, or extract only a specific named symbol. Returns structured suggestions if the symbol is missing.
185
- - `filePath` (required) — Path to the source file
186
- - `symbolName` (optional) — Name of a function, class, method, or type
187
- - `className` (optional) — Scope the symbol to a specific class (to avoid duplicates)
188
-
189
- #### 3. `analyze_impact`
190
- Find all files that depend on a given file.
191
- - `filePath` (required) — Path to the file being modified
192
- - `rootDir` (optional) — Repository root (auto-detected)
193
-
194
- #### 4. `read_file_lines`
195
- Read specific line ranges from a file without loading the entire content. More efficient than `read_file_surgical` for small fragments.
196
- - `filePath` (required) — Path to the source file
197
- - `startLine` (optional) — Starting line number (1-indexed)
198
- - `endLine` (optional) — Ending line number (1-indexed)
199
- - `aroundPattern` (optional) — Search pattern to find and return surrounding lines
200
- - `contextLines` (optional) — Number of lines before/after pattern (default: 5)
201
-
202
- #### 5. `search_code_pattern`
203
- Search for code patterns across multiple files with context. Respects `.gitignore` rules.
204
- - `rootDir` (required) — Repository root directory
205
- - `pattern` (required) — Regular expression pattern to search
206
- - `fileExtensions` (optional) — Array of extensions to search (e.g., `[".ts", ".dart"]`)
207
- - `excludeDirs` (optional) — Directories to exclude (default: `["node_modules", "dist", "build"]`)
208
- - `showContext` (optional) — Include surrounding lines (default: true)
209
- - `contextLines` (optional) — Number of context lines (default: 3)
210
- - `maxResults` (optional) — Maximum matches to return (default: 50)
211
-
212
- #### 6. `rollback_file`
213
- Surgically restore a file to a previous state from the automated backup system.
214
- - `filePath` (required) — Path to the file to restore
215
- - `steps` (optional) — Number of versions to go back (1-5, default: 1)
216
-
217
- #### 7. `clean_backups`
218
- Remove all backup files for a project to keep the working directory clean.
219
- - `projectRoot` (required) — Absolute path to the project root
220
-
221
- **Note:** Backups are stored centrally at `[project-root]/.mcp-backups/` to keep your project organized.
222
-
223
- ### Write Tools (Phase 1: Preview)
224
-
225
- All write tools follow a **Two-Phase Workflow**:
226
- 1. **Call without token**: Returns a unified `diff` and a `confirmationToken`.
227
- 2. **Call with token**: Set `confirm: true` and provide the token to apply the changes.
228
-
229
- #### 7. `write_file_surgical`
230
- Replace the full source code of a named symbol in a file.
231
- - `filePath` (required) — Path to the file
232
- - `symbolName` (required) — Symbol to replace
233
- - `newContent` (required) — Replacement code (signature + body)
234
- - `confirmationToken` (optional) — Token from Phase 1 to apply changes
235
- - `confirm` (optional) — Set to `true` to apply
236
- - `className` (optional) — Scope the symbol to a specific class
237
-
238
- #### 8. `insert_symbol`
239
- Insert new code at a precise location relative to an existing symbol.
240
- - `filePath` (required) — Path to the file
241
- - `code` (required) — Code to insert
242
- - `anchorSymbol` (optional) — Symbol to position relative to
243
- - `position` (optional) — `"before"`, `"after"`, `"inside_start"`, `"inside_end"`
244
- - `className` (optional) — Scope the anchor to a specific class
245
- - `confirmationToken`, `confirm` (optional)
246
-
247
- #### 9. `rename_symbol`
248
- Rename a symbol across the entire repository (definition + all usages).
249
- - `filePath` (required) — File where the symbol is defined
250
- - `oldName` (required) — Current name
251
- - `newName` (required) — New name
252
- - `rootDir` (optional) — Repository root
253
- - `confirmationToken`, `confirm` (optional)
254
-
255
- #### 10. `remove_symbol`
256
- Safely remove a symbol from a file with dependency checking.
257
- - `filePath` (required) — Path to the file
258
- - `symbolName` (required) — Symbol to remove
259
- - `className` (optional) — Scope the symbol to a specific class
260
- - `force` (optional) — Skip dependency check
261
- - `confirmationToken`, `confirm` (optional)
262
-
263
- ## Recommended Workflow
264
-
265
- 1. **Understand** → `get_semantic_repo_map` to see the architecture
266
- 2. **Read** → `read_file_surgical` with symbol name for specific implementations
267
- 3. **Assess** → `analyze_impact` before modifying shared files
268
- 4. **Edit (Preview)** → Call write tools to generate a `diff` and `confirmationToken`
269
- 5. **Confim** → Call the same write tool with the token and `confirm: true` to apply
270
- 6. **Recovery** → Use `rollback_file` if something goes wrong after confirmation
271
-
272
- ## Development
273
-
274
- ```bash
275
- # Build
276
- npm run build
277
-
278
- # Run read tests (compression + extraction)
279
- npm run build && node dist/tests/test-dart.js && node dist/tests/test-php.js
280
-
281
- # Run write tests (replace, insert, rename, remove)
282
- npm run build && node dist/tests/writers/test-write-smoke.js
283
-
284
- # Run all tests
285
- npm run build && node dist/tests/test-dart.js && node dist/tests/test-php.js && node dist/tests/writers/test-write-smoke.js
286
-
287
- # Development (build + start)
288
- npm run dev
289
- ```
290
-
291
- ## Technical Details
292
-
293
- - **Transport:** stdio (JSON-RPC over stdin/stdout)
294
- - **Runtime:** Node.js >= 18
295
- - **Protocol:** [Model Context Protocol](https://modelcontextprotocol.io/)
296
- - **AST Engines:** web-tree-sitter@0.25.1 (WASM) for TypeScript/JS/Python/PHP/Dart
297
- - **Language Grammars:** tree-sitter-wasms@0.1.13 (ABI v15)
298
- - **Ignore Engine:** `ignore` npm package (full .gitignore spec support)
299
- - **Safety Features:** Mandatory two-phase confirmation, rolling 5-version backups, fuzzy matching, dependency checking, surgical restoration.
300
- - **Portability:** 100% WASM - no native dependencies, works on all platforms
301
-
302
- ## License
303
-
304
- [MIT](LICENSE)
1
+ # mcp-code-context
2
+
3
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
4
+ [![npm version](https://img.shields.io/npm/v/mcp-code-context.svg)](https://www.npmjs.com/package/mcp-code-context)
5
+ [![npm downloads](https://img.shields.io/npm/dm/mcp-code-context.svg)](https://www.npmjs.com/package/mcp-code-context)
6
+ [![TypeScript](https://img.shields.io/badge/TypeScript-100%25-blue.svg)]()
7
+ [![Tests](https://img.shields.io/badge/tests-74%20passing-success.svg)]()
8
+ [![Ko-fi](https://img.shields.io/badge/Support-Ko--fi-FF5E5B?logo=ko-fi)](https://ko-fi.com/achatainga)
9
+ [![PayPal](https://img.shields.io/badge/Donate-PayPal-00457C?logo=paypal)](https://paypal.me/achatainga)
10
+
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
+
13
+ ## šŸš€ Quick Start (Claude Desktop)
14
+
15
+ 1. **Install**: `npm install -g mcp-code-context`
16
+ 2. **Configure**: Add to `claude_desktop_config.json`:
17
+ ```json
18
+ {
19
+ "mcpServers": {
20
+ "code-context": {
21
+ "command": "npx",
22
+ "args": ["-y", "mcp-code-context"]
23
+ }
24
+ }
25
+ }
26
+ ```
27
+ 3. **Enjoy**: Use symbols like `@code-context` to map repos or edit code surgically.
28
+
29
+ **No build tools required** - Works on Windows/Mac/Linux without Visual Studio, Python, or node-gyp.
30
+
31
+ Works with **Claude Desktop**, **Cursor**, **Windsurf**, **GitHub Copilot**, **Amazon Q**, and any [Model Context Protocol](https://modelcontextprotocol.io/) compatible client.
32
+
33
+ šŸ“– **For AI Agents**: See [INSTRUCTIONS.md](INSTRUCTIONS.md) for essential usage patterns and best practices.
34
+
35
+ ---
36
+
37
+ ## šŸ’” Why This Exists
38
+
39
+ This tool was born out of necessity in **Caracas, Venezuela šŸ‡»šŸ‡Ŗ**, where economic limitations made every API token count. When you're choosing between groceries and Claude API credits, you learn to optimize fast.
40
+
41
+ What started as a personal script to compress context windows became a full MCP server when I realized others faced the same problem: **LLM APIs are expensive, and most tools waste tokens on boilerplate**.
42
+
43
+ If this tool saves you money or time, consider [supporting its development](#-support-this-project). Every contribution helps keep this project maintained and free for everyone.
44
+
45
+ ---
46
+
47
+ ## The Problem
48
+
49
+ LLMs working with code face two bottlenecks:
50
+ 1. **Reading**: Sending raw source files wastes the context window on function bodies and boilerplate. A 500-line file might contain only 30 lines of *structural* information the LLM needs.
51
+ 2. **Writing**: Rewriting entire files to change one function is error-prone, token-expensive, and risks corrupting unrelated code.
52
+
53
+ ## The Solution
54
+
55
+ `mcp-code-context` provides **13 tools** — 6 for reading, 2 for cleanup, and 5 for writing — that operate at the **symbol level** (functions, classes, methods). Furthermore, tools support a `className` scope which correctly isolates identical symbol names in the same file (e.g. Flutter `build()` methods) to avoid reading or changing the wrong logic. Read tools extract structural skeletons. Write tools splice changes into the exact AST location.
56
+
57
+ | File | Original | Compressed | Reduction |
58
+ |------|----------|------------|-----------|
59
+ | PHP class (426 lines) | 426 | 60 | **85.9%** |
60
+ | Dart repository (230 lines) | 230 | 30 | **87.0%** |
61
+ | PHP config (68 lines) | 68 | 15 | **77.9%** |
62
+
63
+ ## Reliability & Testing
64
+
65
+ Built to be robust and precise. Both read and write engines are tested against real-world, complex codebases (including nested generic types in Dart, complex interfaces in PHP, and multi-file rename operations) with a **100% test pass rate** across all languages and operations.
66
+
67
+ ## Features
68
+
69
+ ### What's New in v3.6.0
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
+
83
+ ### Read
84
+ - 🌳 **AST-based compression** — Real Tree-sitter WASM parsers for TypeScript/JavaScript/Python/PHP/Dart. Zero regex-based parsing.
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).
86
+ - šŸ’„ **Impact analysis** — Discover all files that depend on a given file before refactoring. Supports ES imports, CommonJS `require()`, Python imports, PHP `use`/`require_once`/`include`, and Dart imports.
87
+ - šŸ“ **Smart file walking** — Respects `.gitignore` and `.repomixignore` rules. Automatically excludes `node_modules`, `dist`, `vendor`, `.git`, etc.
88
+ - šŸ“„ **Multi-format output** — XML (optimized for LLM consumption) or Markdown (human-readable).
89
+
90
+ ### Write
91
+ - āœļø **Surgical symbol replacement** — Replace a function, method, or class body without touching the rest of the file. Narrow down the target using the `className` parameter.
92
+ - āž• **Precise code insertion** — Insert new code before/after a symbol, or inside a class at the start/end.
93
+ - šŸ”„ **Repository-wide rename** — Rename a symbol in its definition AND all files that import it, atomically.
94
+ - šŸ—‘ļø **Safe symbol removal** — Delete code with automatic dependency checking to prevent breakage.
95
+ - šŸ” **Mandatory dry-run flow** — Write tools return a preview diff and a `confirmationToken` by default. Changes are only applied after explicit confirmation.
96
+ - šŸ’¾ **Robust rolling backups** — Automatically keeps the last 5 versions of modified files in a hidden `.mcp-backups/` directory.
97
+ - āŖ **Surgical rollback** — Revert files to any of the 5 previous states using the `rollback_file` tool.
98
+ - šŸ¤– **Fuzzy symbol matching** — When a symbol is not found, the server provides structured suggestions based on Levenshtein distance.
99
+ - šŸ” **Private symbol support** — Full support for `_` and `__` prefixed symbols in Dart and Python.
100
+
101
+ ## Supported Languages
102
+
103
+ | Language | Read (Compress + Extract) | Write (Replace + Insert + Rename + Remove) | Import Analysis |
104
+ |----------|---------------------------|---------------------------------------------|------------------|
105
+ | TypeScript / JavaScript | āœ… AST (Tree-sitter WASM) | āœ… AST (Tree-sitter WASM) | āœ… |
106
+ | PHP | āœ… AST (Tree-sitter WASM) | āœ… AST + line-splice | āœ… |
107
+ | Dart | āœ… AST (Tree-sitter WASM) | āœ… AST + line-splice | āœ… |
108
+ | Python | āœ… AST (Tree-sitter WASM) | āœ… Indentation-aware | āœ… |
109
+ | Others (JSON, YAML, CSS, etc.) | Passthrough / truncation | — | — |
110
+
111
+ ## āš ļø Known Limitations
112
+
113
+ ### `rename_symbol` Tool
114
+
115
+ **Dart and Python**: Cross-file rename is **NOT supported** for `.dart`, `.py`, and `.pyi` files.
116
+
117
+ - **Reason**: No AST parser available for safe cross-file refactoring
118
+ - **Risk**: Regex-based rename may corrupt strings, comments, or unrelated code
119
+ - **Recommendation**: Use IDE refactoring tools instead:
120
+ - **Dart**: VS Code with Dart extension (F2 key) or IntelliJ IDEA
121
+ - **Python**: PyCharm, VS Code with Pylance (F2 key)
122
+ - **Alternative**: Use `write_file_surgical` to rename within a single file
123
+
124
+ **TypeScript, JavaScript, PHP**: Fully supported with AST-aware renaming āœ…
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
+
128
+ ### `get_semantic_repo_map` Tool
129
+
130
+ - **Max files**: Limited to 500 files to prevent timeouts
131
+ - **Performance**: Synchronous I/O may take 10-30 seconds on large repositories
132
+ - **Recommendation**: Use `@folder` syntax to target specific directories
133
+
134
+ ### General
135
+
136
+ - **Validation**: No automatic syntax checking after edits. Always review diffs carefully before confirming.
137
+ - **Backups**: 5-version rolling backup system. Use `rollback_file` if something goes wrong.
138
+ - **Large files**: Files >10MB are skipped for safety.
139
+
140
+ ## Installation
141
+
142
+ ```bash
143
+ # Global installation (recommended)
144
+ npm install -g mcp-code-context
145
+
146
+ # Or use directly with npx (no installation)
147
+ npx -y mcp-code-context
148
+ ```
149
+
150
+ **Note**: Unlike v2.x, this version uses **web-tree-sitter (WASM)** instead of native bindings. No Visual Studio, Python, or node-gyp required!
151
+
152
+ ## Configuration
153
+
154
+ ### Claude Desktop
155
+
156
+ Add to your `claude_desktop_config.json`:
157
+
158
+ ```json
159
+ {
160
+ "mcpServers": {
161
+ "mcp-code-context": {
162
+ "command": "npx",
163
+ "args": ["-y", "mcp-code-context"]
164
+ }
165
+ }
166
+ }
167
+ ```
168
+
169
+ ### Cursor
170
+
171
+ Add to your Cursor MCP settings (`.cursor/mcp.json`):
172
+
173
+ ```json
174
+ {
175
+ "mcpServers": {
176
+ "mcp-code-context": {
177
+ "command": "npx",
178
+ "args": ["-y", "mcp-code-context"]
179
+ }
180
+ }
181
+ }
182
+ ```
183
+
184
+ ### Windsurf
185
+
186
+ Add to your Windsurf MCP config:
187
+
188
+ ```json
189
+ {
190
+ "mcpServers": {
191
+ "mcp-code-context": {
192
+ "command": "npx",
193
+ "args": ["-y", "mcp-code-context"]
194
+ }
195
+ }
196
+ }
197
+ ```
198
+
199
+ ### Amazon Q / Other MCP Clients
200
+
201
+ Any MCP-compatible client can use this server. The transport is **stdio** (JSON-RPC over stdin/stdout). Point your client to `npx -y mcp-code-context`.
202
+
203
+ ## Tools
204
+
205
+ ### Read Tools
206
+
207
+ #### 1. `get_semantic_repo_map`
208
+ Generate a compressed architectural overview of an entire repository.
209
+ - `directoryPath` (required) — Path to the repo root
210
+ - `format` (optional) — `"xml"` (default) or `"markdown"`
211
+
212
+ #### 2. `read_file_surgical`
213
+ Read a file, or extract only a specific named symbol. Returns structured suggestions if the symbol is missing.
214
+ - `filePath` (required) — Path to the source file
215
+ - `symbolName` (optional) — Name of a function, class, method, or type
216
+ - `className` (optional) — Scope the symbol to a specific class (to avoid duplicates)
217
+
218
+ #### 3. `analyze_impact`
219
+ Find all files that depend on a given file.
220
+ - `filePath` (required) — Path to the file being modified
221
+ - `rootDir` (optional) — Repository root (auto-detected)
222
+
223
+ #### 4. `read_file_lines`
224
+ Read specific line ranges from a file without loading the entire content. More efficient than `read_file_surgical` for small fragments.
225
+ - `filePath` (required) — Path to the source file
226
+ - `startLine` (optional) — Starting line number (1-indexed)
227
+ - `endLine` (optional) — Ending line number (1-indexed)
228
+ - `aroundPattern` (optional) — Search pattern to find and return surrounding lines
229
+ - `contextLines` (optional) — Number of lines before/after pattern (default: 5)
230
+
231
+ #### 5. `search_code_pattern`
232
+ Search for code patterns across multiple files with context. Respects `.gitignore` rules.
233
+ - `rootDir` (required) — Repository root directory
234
+ - `pattern` (required) — Regular expression pattern to search
235
+ - `fileExtensions` (optional) — Array of extensions to search (e.g., `[".ts", ".dart"]`)
236
+ - `excludeDirs` (optional) — Directories to exclude (default: `["node_modules", "dist", "build"]`)
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)
241
+
242
+ #### 6. `rollback_file`
243
+ Surgically restore a file to a previous state from the automated backup system.
244
+ - `filePath` (required) — Path to the file to restore
245
+ - `steps` (optional) — Number of versions to go back (1-5, default: 1)
246
+
247
+ #### 7. `clean_backups`
248
+ Remove all backup files for a project to keep the working directory clean.
249
+ - `projectRoot` (required) — Absolute path to the project root
250
+
251
+ **Note:** Backups are stored centrally at `[project-root]/.mcp-backups/` to keep your project organized.
252
+
253
+ ### Write Tools (Two-Phase Workflow)
254
+
255
+ All write tools follow a **Two-Phase Workflow**:
256
+ 1. **Call without token**: Returns a unified `diff` and a `confirmationToken`.
257
+ 2. **Call with token**: Set `confirm: true` and provide the token to apply the changes.
258
+
259
+ #### 8. `write_file_surgical`
260
+ Replace the full source code of a named symbol in a file.
261
+ - `filePath` (required) — Path to the file
262
+ - `symbolName` (required) — Symbol to replace
263
+ - `newContent` (required) — Replacement code (signature + body)
264
+ - `confirmationToken` (optional) — Token from Phase 1 to apply changes
265
+ - `confirm` (optional) — Set to `true` to apply
266
+ - `className` (optional) — Scope the symbol to a specific class
267
+
268
+ #### 9. `insert_symbol`
269
+ Insert new code at a precise location relative to an existing symbol.
270
+ - `filePath` (required) — Path to the file
271
+ - `code` (required) — Code to insert
272
+ - `anchorSymbol` (optional) — Symbol to position relative to
273
+ - `position` (optional) — `"before"`, `"after"`, `"inside_start"`, `"inside_end"`
274
+ - `className` (optional) — Scope the anchor to a specific class
275
+ - `confirmationToken`, `confirm` (optional)
276
+
277
+ #### 10. `rename_symbol`
278
+ Rename a symbol across the entire repository (definition + all usages).
279
+ - `filePath` (required) — File where the symbol is defined
280
+ - `oldName` (required) — Current name
281
+ - `newName` (required) — New name
282
+ - `rootDir` (optional) — Repository root
283
+ - `confirmationToken`, `confirm` (optional)
284
+
285
+ #### 11. `remove_symbol`
286
+ Safely remove a symbol from a file with dependency checking.
287
+ - `filePath` (required) — Path to the file
288
+ - `symbolName` (required) — Symbol to remove
289
+ - `className` (optional) — Scope the symbol to a specific class
290
+ - `force` (optional) — Skip dependency check
291
+ - `confirmationToken`, `confirm` (optional)
292
+
293
+ ## Recommended Workflow
294
+
295
+ 1. **Understand** → `get_semantic_repo_map` to see the architecture
296
+ 2. **Read** → `read_file_surgical` with symbol name for specific implementations
297
+ 3. **Assess** → `analyze_impact` before modifying shared files
298
+ 4. **Edit (Preview)** → Call write tools to generate a `diff` and `confirmationToken`
299
+ 5. **Confirm** → Call the same write tool with the token and `confirm: true` to apply
300
+ 6. **Recovery** → Use `rollback_file` if something goes wrong after confirmation
301
+
302
+ ---
303
+
304
+ ## šŸ’° Support This Project
305
+
306
+ ### Why Support?
307
+
308
+ This tool was born in **Caracas, Venezuela šŸ‡»šŸ‡Ŗ**, where economic limitations mean every API token counts. What started as a personal script to save money on Claude API became a full MCP server when I realized others faced the same problem.
309
+
310
+ **Current Reality**:
311
+ - ā° ~10 hours/week of maintenance
312
+ - šŸ’µ ~$20/month in costs (npm, testing, domain)
313
+ - šŸ†“ 100% free and open source (always will be)
314
+
315
+ If this tool saves you time or money, consider supporting its development.
316
+
317
+ ---
318
+
319
+ ### šŸ’³ Ways to Support
320
+
321
+ #### šŸ”¹ One-Time Donation
322
+
323
+ **Ko-fi** (PayPal + Cards, 0% fees)
324
+ [ko-fi.com/achatainga](https://ko-fi.com/achatainga)
325
+
326
+ **PayPal** (Direct)
327
+ [paypal.me/achatainga](https://paypal.me/achatainga)
328
+
329
+ **Binance (USDT)** (Crypto, lowest fees)
330
+ - **TRC20/ERC20**: `0xa68d53f7853ce0175eb96aaad4a30c068ca96444`
331
+ - **Binance Pay ID**: `367669339`
332
+
333
+ *Recommended: TRC20 for lower gas fees*
334
+
335
+ #### Suggested Amounts:
336
+ - ā˜• **$5** - A coffee (1 hour of development)
337
+ - šŸ• **$25** - A pizza (testing a new language)
338
+ - šŸš€ **$100** - Rocket fuel (major feature development)
339
+
340
+ ---
341
+
342
+ #### šŸ”¹ Recurring Support
343
+
344
+ **Ko-fi Membership**
345
+ [ko-fi.com/achatainga/tiers](https://ko-fi.com/achatainga/tiers)
346
+
347
+ Monthly tiers:
348
+ - **$5/month** - Supporter (name in SPONSORS.md)
349
+ - **$25/month** - Contributor (priority support, early access)
350
+ - **$100/month** - Sponsor (feature requests, 1-on-1 consultation)
351
+
352
+ ---
353
+
354
+ #### šŸ”¹ Hire Me
355
+
356
+ Need custom MCP tools or AI integrations?
357
+
358
+ - šŸ’¼ **Available for**: Freelance contracts
359
+ - 🌐 **Location**: Caracas, Venezuela (Remote)
360
+ - šŸ’» **Skills**: TypeScript, Node.js, MCP, AI/LLM integrations
361
+ - šŸ’µ **Rate**: $50-75/hour
362
+
363
+ šŸ“§ **Contact**: a.chataing.a@gmail.com
364
+ šŸ“„ **Details**: [HIRE_ME.md](HIRE_ME.md)
365
+
366
+ ---
367
+
368
+ ### šŸ“Š Transparency
369
+
370
+ I believe in radical transparency:
371
+
372
+ **Current Status**:
373
+ - šŸ’° Donations received: $0
374
+ - šŸ’ø Expenses: $20/month (npm, testing)
375
+ - ā° Time invested: ~10 hours/week
376
+ - šŸ“¦ Downloads: 10,000+/month
377
+
378
+ *(Updated monthly)*
379
+
380
+ ---
381
+
382
+ ### šŸ† Hall of Fame
383
+
384
+ Thank you to these amazing supporters:
385
+
386
+ *(No sponsors yet - be the first!)*
387
+
388
+ See full list: [SPONSORS.md](SPONSORS.md)
389
+
390
+ ---
391
+
392
+ ### ā¤ļø Non-Financial Support
393
+
394
+ Can't donate? No problem! You can still help:
395
+
396
+ - ⭐ Star the repo on GitHub
397
+ - šŸ› Report bugs or suggest features
398
+ - šŸ“ Improve documentation
399
+ - šŸ—£ļø Share with others who might benefit
400
+ - šŸ’¬ Join discussions and help other users
401
+
402
+ Every contribution matters, financial or not.
403
+
404
+ ---
405
+
406
+ ## Development
407
+
408
+ ```bash
409
+ # Build
410
+ npm run build
411
+
412
+ # Run tests
413
+ npm test
414
+
415
+ # Development (build + start)
416
+ npm run dev
417
+ ```
418
+
419
+ ## Technical Details
420
+
421
+ - **Transport:** stdio (JSON-RPC over stdin/stdout)
422
+ - **Runtime:** Node.js >= 18
423
+ - **Protocol:** [Model Context Protocol](https://modelcontextprotocol.io/)
424
+ - **AST Engines:** web-tree-sitter@0.25.1 (WASM) for TypeScript/JS/Python/PHP/Dart
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²))
432
+ - **Ignore Engine:** `ignore` npm package (full .gitignore spec support)
433
+ - **Safety Features:** Mandatory two-phase confirmation, rolling 5-version backups, fuzzy matching, dependency checking, surgical restoration, ReDoS protection via worker_threads.
434
+ - **Portability:** 100% WASM - no native dependencies, works on all platforms
435
+ - **Tests:** 74 passing (unit + integration + performance + stress)
436
+
437
+ ## Contributing
438
+
439
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
440
+
441
+ ## Security
442
+
443
+ See [SECURITY.md](SECURITY.md) for security policies and reporting vulnerabilities.
444
+
445
+ ## Troubleshooting
446
+
447
+ See [TROUBLESHOOTING.md](TROUBLESHOOTING.md) for common issues and solutions.
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
+
476
+ ## Changelog
477
+
478
+ See [CHANGELOG.md](CHANGELOG.md) for version history.
479
+
480
+ ## License
481
+
482
+ [MIT](LICENSE)
483
+
484
+ ---
485
+
486
+ **Built with ā¤ļø from Caracas, Venezuela šŸ‡»šŸ‡Ŗ**