mcp-code-context 3.5.2 → 3.5.3

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 (55) hide show
  1. package/CHANGELOG.md +3 -3
  2. package/HIRE_ME.md +234 -0
  3. package/README.md +433 -304
  4. package/SECURITY.md +14 -14
  5. package/SPONSORS.md +104 -0
  6. package/dist/src/core/engine.d.ts +1 -1
  7. package/dist/src/core/engine.js +1 -1
  8. package/dist/src/core/validator.d.ts +1 -1
  9. package/dist/src/core/validator.js +3 -3
  10. package/dist/src/core/validator.js.map +1 -1
  11. package/dist/src/index.d.ts +1 -1
  12. package/dist/src/index.js +2 -2
  13. package/dist/src/operations/compress.d.ts +1 -1
  14. package/dist/src/operations/compress.js +1 -1
  15. package/dist/src/operations/confirmationStore.d.ts +1 -1
  16. package/dist/src/operations/confirmationStore.js +1 -1
  17. package/dist/src/operations/read.d.ts +1 -1
  18. package/dist/src/operations/read.js +9 -1
  19. package/dist/src/operations/read.js.map +1 -1
  20. package/dist/src/operations/write.d.ts +2 -2
  21. package/dist/src/operations/write.js +2 -2
  22. package/dist/src/parsers/base.d.ts +1 -1
  23. package/dist/src/parsers/base.js +1 -1
  24. package/dist/src/parsers/dartTreeSitter.d.ts +1 -1
  25. package/dist/src/parsers/dartTreeSitter.js +1 -1
  26. package/dist/src/parsers/php.d.ts +1 -1
  27. package/dist/src/parsers/php.js +1 -1
  28. package/dist/src/parsers/python.d.ts +1 -1
  29. package/dist/src/parsers/python.js +1 -1
  30. package/dist/src/parsers/registry.d.ts +1 -1
  31. package/dist/src/parsers/registry.js +1 -1
  32. package/dist/src/parsers/typescript.d.ts +1 -1
  33. package/dist/src/parsers/typescript.js +1 -1
  34. package/dist/src/utils/auditLogger.d.ts +1 -1
  35. package/dist/src/utils/auditLogger.js +1 -1
  36. package/dist/src/utils/backupManager.d.ts +1 -1
  37. package/dist/src/utils/backupManager.js +1 -1
  38. package/dist/src/utils/constants.d.ts +1 -1
  39. package/dist/src/utils/constants.js +1 -1
  40. package/dist/src/utils/diff.d.ts +1 -1
  41. package/dist/src/utils/diff.js +1 -1
  42. package/dist/src/utils/fileLock.d.ts +1 -1
  43. package/dist/src/utils/fileLock.js +1 -1
  44. package/dist/src/utils/rateLimiter.d.ts +1 -1
  45. package/dist/src/utils/rateLimiter.js +1 -1
  46. package/dist/src/utils/safeRegex.d.ts +1 -1
  47. package/dist/src/utils/safeRegex.js +1 -1
  48. package/dist/src/utils/streaming.d.ts +1 -1
  49. package/dist/src/utils/streaming.js +1 -1
  50. package/dist/src/utils/telemetry.d.ts +1 -1
  51. package/dist/src/utils/telemetry.js +1 -1
  52. package/llms.txt +5 -5
  53. package/package.json +17 -2
  54. package/CHANGELOG_v3.2.0.md +0 -196
  55. package/CHANGELOG_v3.3.0.md +0 -266
package/README.md CHANGED
@@ -1,304 +1,433 @@
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-passing-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.
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
+ ---
34
+
35
+ ## 💡 Why This Exists
36
+
37
+ 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.
38
+
39
+ 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**.
40
+
41
+ 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.
42
+
43
+ ---
44
+
45
+ ## The Problem
46
+
47
+ LLMs working with code face two bottlenecks:
48
+ 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.
49
+ 2. **Writing**: Rewriting entire files to change one function is error-prone, token-expensive, and risks corrupting unrelated code.
50
+
51
+ ## The Solution
52
+
53
+ `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.
54
+
55
+ | File | Original | Compressed | Reduction |
56
+ |------|----------|------------|-----------|
57
+ | PHP class (426 lines) | 426 | 60 | **85.9%** |
58
+ | Dart repository (230 lines) | 230 | 30 | **87.0%** |
59
+ | PHP config (68 lines) | 68 | 15 | **77.9%** |
60
+
61
+ ## Reliability & Testing
62
+
63
+ 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.
64
+
65
+ ## Features
66
+
67
+ ### Read
68
+ - 🌳 **AST-based compression** — Real Tree-sitter WASM parsers for TypeScript/JavaScript/Python/PHP/Dart. Zero regex-based parsing.
69
+ - 🔬 **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).
70
+ - 💥 **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.
71
+ - 📁 **Smart file walking** — Respects `.gitignore` and `.repomixignore` rules. Automatically excludes `node_modules`, `dist`, `vendor`, `.git`, etc.
72
+ - 📄 **Multi-format output** — XML (optimized for LLM consumption) or Markdown (human-readable).
73
+
74
+ ### Write
75
+ - ✏️ **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.
76
+ - ➕ **Precise code insertion** — Insert new code before/after a symbol, or inside a class at the start/end.
77
+ - 🔄 **Repository-wide rename** — Rename a symbol in its definition AND all files that import it, atomically.
78
+ - 🗑️ **Safe symbol removal** — Delete code with automatic dependency checking to prevent breakage.
79
+ - 🔍 **Mandatory dry-run flow** — Write tools return a preview diff and a `confirmationToken` by default. Changes are only applied after explicit confirmation.
80
+ - 💾 **Robust rolling backups** — Automatically keeps the last 5 versions of modified files in a hidden `.mcp-backups/` directory.
81
+ - ⏪ **Surgical rollback** — Revert files to any of the 5 previous states using the `rollback_file` tool.
82
+ - 🤖 **Fuzzy symbol matching** — When a symbol is not found, the server provides structured suggestions based on Levenshtein distance.
83
+ - 🔐 **Private symbol support** — Full support for `_` and `__` prefixed symbols in Dart and Python.
84
+
85
+ ## Supported Languages
86
+
87
+ | Language | Read (Compress + Extract) | Write (Replace + Insert + Rename + Remove) | Import Analysis |
88
+ |----------|---------------------------|---------------------------------------------|------------------|
89
+ | TypeScript / JavaScript | ✅ AST (Tree-sitter WASM) | ✅ AST (Tree-sitter WASM) | ✅ |
90
+ | PHP | ✅ AST (Tree-sitter WASM) | ✅ AST + line-splice | ✅ |
91
+ | Dart | ✅ AST (Tree-sitter WASM) | ✅ AST + line-splice | ✅ |
92
+ | Python | ✅ AST (Tree-sitter WASM) | ✅ Indentation-aware | ✅ |
93
+ | Others (JSON, YAML, CSS, etc.) | Passthrough / truncation | — | — |
94
+
95
+ ## ⚠️ Known Limitations
96
+
97
+ ### `rename_symbol` Tool
98
+
99
+ **Dart and Python**: Cross-file rename is **NOT supported** for `.dart`, `.py`, and `.pyi` files.
100
+
101
+ - **Reason**: No AST parser available for safe cross-file refactoring
102
+ - **Risk**: Regex-based rename may corrupt strings, comments, or unrelated code
103
+ - **Recommendation**: Use IDE refactoring tools instead:
104
+ - **Dart**: VS Code with Dart extension (F2 key) or IntelliJ IDEA
105
+ - **Python**: PyCharm, VS Code with Pylance (F2 key)
106
+ - **Alternative**: Use `write_file_surgical` to rename within a single file
107
+
108
+ **TypeScript, JavaScript, PHP**: Fully supported with AST-aware renaming ✅
109
+
110
+ ### `get_semantic_repo_map` Tool
111
+
112
+ - **Max files**: Limited to 500 files to prevent timeouts
113
+ - **Performance**: Synchronous I/O may take 10-30 seconds on large repositories
114
+ - **Recommendation**: Use `@folder` syntax to target specific directories
115
+
116
+ ### General
117
+
118
+ - **Validation**: No automatic syntax checking after edits. Always review diffs carefully before confirming.
119
+ - **Backups**: 5-version rolling backup system. Use `rollback_file` if something goes wrong.
120
+ - **Large files**: Files >10MB are skipped for safety.
121
+
122
+ ## Installation
123
+
124
+ ```bash
125
+ # Global installation (recommended)
126
+ npm install -g mcp-code-context
127
+
128
+ # Or use directly with npx (no installation)
129
+ npx -y mcp-code-context
130
+ ```
131
+
132
+ **Note**: Unlike v2.x, this version uses **web-tree-sitter (WASM)** instead of native bindings. No Visual Studio, Python, or node-gyp required!
133
+
134
+ ## Configuration
135
+
136
+ ### Claude Desktop
137
+
138
+ Add to your `claude_desktop_config.json`:
139
+
140
+ ```json
141
+ {
142
+ "mcpServers": {
143
+ "mcp-code-context": {
144
+ "command": "npx",
145
+ "args": ["-y", "mcp-code-context"]
146
+ }
147
+ }
148
+ }
149
+ ```
150
+
151
+ ### Cursor
152
+
153
+ Add to your Cursor MCP settings (`.cursor/mcp.json`):
154
+
155
+ ```json
156
+ {
157
+ "mcpServers": {
158
+ "mcp-code-context": {
159
+ "command": "npx",
160
+ "args": ["-y", "mcp-code-context"]
161
+ }
162
+ }
163
+ }
164
+ ```
165
+
166
+ ### Windsurf
167
+
168
+ Add to your Windsurf MCP config:
169
+
170
+ ```json
171
+ {
172
+ "mcpServers": {
173
+ "mcp-code-context": {
174
+ "command": "npx",
175
+ "args": ["-y", "mcp-code-context"]
176
+ }
177
+ }
178
+ }
179
+ ```
180
+
181
+ ### Amazon Q / Other MCP Clients
182
+
183
+ 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`.
184
+
185
+ ## Tools
186
+
187
+ ### Read Tools
188
+
189
+ #### 1. `get_semantic_repo_map`
190
+ Generate a compressed architectural overview of an entire repository.
191
+ - `directoryPath` (required) — Path to the repo root
192
+ - `format` (optional) — `"xml"` (default) or `"markdown"`
193
+
194
+ #### 2. `read_file_surgical`
195
+ Read a file, or extract only a specific named symbol. Returns structured suggestions if the symbol is missing.
196
+ - `filePath` (required) — Path to the source file
197
+ - `symbolName` (optional) — Name of a function, class, method, or type
198
+ - `className` (optional) — Scope the symbol to a specific class (to avoid duplicates)
199
+
200
+ #### 3. `analyze_impact`
201
+ Find all files that depend on a given file.
202
+ - `filePath` (required) — Path to the file being modified
203
+ - `rootDir` (optional) — Repository root (auto-detected)
204
+
205
+ #### 4. `read_file_lines`
206
+ Read specific line ranges from a file without loading the entire content. More efficient than `read_file_surgical` for small fragments.
207
+ - `filePath` (required) — Path to the source file
208
+ - `startLine` (optional) — Starting line number (1-indexed)
209
+ - `endLine` (optional) — Ending line number (1-indexed)
210
+ - `aroundPattern` (optional) — Search pattern to find and return surrounding lines
211
+ - `contextLines` (optional) — Number of lines before/after pattern (default: 5)
212
+
213
+ #### 5. `search_code_pattern`
214
+ Search for code patterns across multiple files with context. Respects `.gitignore` rules.
215
+ - `rootDir` (required) — Repository root directory
216
+ - `pattern` (required) — Regular expression pattern to search
217
+ - `fileExtensions` (optional) — Array of extensions to search (e.g., `[".ts", ".dart"]`)
218
+ - `excludeDirs` (optional) — Directories to exclude (default: `["node_modules", "dist", "build"]`)
219
+ - `showContext` (optional) — Include surrounding lines (default: true)
220
+ - `contextLines` (optional) — Number of context lines (default: 3)
221
+ - `maxResults` (optional) — Maximum matches to return (default: 50)
222
+
223
+ #### 6. `rollback_file`
224
+ Surgically restore a file to a previous state from the automated backup system.
225
+ - `filePath` (required) — Path to the file to restore
226
+ - `steps` (optional) — Number of versions to go back (1-5, default: 1)
227
+
228
+ #### 7. `clean_backups`
229
+ Remove all backup files for a project to keep the working directory clean.
230
+ - `projectRoot` (required) — Absolute path to the project root
231
+
232
+ **Note:** Backups are stored centrally at `[project-root]/.mcp-backups/` to keep your project organized.
233
+
234
+ ### Write Tools (Two-Phase Workflow)
235
+
236
+ All write tools follow a **Two-Phase Workflow**:
237
+ 1. **Call without token**: Returns a unified `diff` and a `confirmationToken`.
238
+ 2. **Call with token**: Set `confirm: true` and provide the token to apply the changes.
239
+
240
+ #### 8. `write_file_surgical`
241
+ Replace the full source code of a named symbol in a file.
242
+ - `filePath` (required) — Path to the file
243
+ - `symbolName` (required) — Symbol to replace
244
+ - `newContent` (required) — Replacement code (signature + body)
245
+ - `confirmationToken` (optional) — Token from Phase 1 to apply changes
246
+ - `confirm` (optional) — Set to `true` to apply
247
+ - `className` (optional) — Scope the symbol to a specific class
248
+
249
+ #### 9. `insert_symbol`
250
+ Insert new code at a precise location relative to an existing symbol.
251
+ - `filePath` (required) — Path to the file
252
+ - `code` (required) — Code to insert
253
+ - `anchorSymbol` (optional) — Symbol to position relative to
254
+ - `position` (optional) — `"before"`, `"after"`, `"inside_start"`, `"inside_end"`
255
+ - `className` (optional) — Scope the anchor to a specific class
256
+ - `confirmationToken`, `confirm` (optional)
257
+
258
+ #### 10. `rename_symbol`
259
+ Rename a symbol across the entire repository (definition + all usages).
260
+ - `filePath` (required) — File where the symbol is defined
261
+ - `oldName` (required) — Current name
262
+ - `newName` (required) — New name
263
+ - `rootDir` (optional) — Repository root
264
+ - `confirmationToken`, `confirm` (optional)
265
+
266
+ #### 11. `remove_symbol`
267
+ Safely remove a symbol from a file with dependency checking.
268
+ - `filePath` (required) — Path to the file
269
+ - `symbolName` (required) — Symbol to remove
270
+ - `className` (optional) — Scope the symbol to a specific class
271
+ - `force` (optional) — Skip dependency check
272
+ - `confirmationToken`, `confirm` (optional)
273
+
274
+ ## Recommended Workflow
275
+
276
+ 1. **Understand** → `get_semantic_repo_map` to see the architecture
277
+ 2. **Read** → `read_file_surgical` with symbol name for specific implementations
278
+ 3. **Assess** → `analyze_impact` before modifying shared files
279
+ 4. **Edit (Preview)** → Call write tools to generate a `diff` and `confirmationToken`
280
+ 5. **Confirm** → Call the same write tool with the token and `confirm: true` to apply
281
+ 6. **Recovery** → Use `rollback_file` if something goes wrong after confirmation
282
+
283
+ ---
284
+
285
+ ## 💰 Support This Project
286
+
287
+ ### Why Support?
288
+
289
+ 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.
290
+
291
+ **Current Reality**:
292
+ - ⏰ ~10 hours/week of maintenance
293
+ - 💵 ~$20/month in costs (npm, testing, domain)
294
+ - 🆓 100% free and open source (always will be)
295
+
296
+ If this tool saves you time or money, consider supporting its development.
297
+
298
+ ---
299
+
300
+ ### 💳 Ways to Support
301
+
302
+ #### 🔹 One-Time Donation
303
+
304
+ **Ko-fi** (PayPal + Cards, 0% fees)
305
+ [ko-fi.com/achatainga](https://ko-fi.com/achatainga)
306
+
307
+ **PayPal** (Direct)
308
+ [paypal.me/achatainga](https://paypal.me/achatainga)
309
+
310
+ **Binance (USDT)** (Crypto, lowest fees)
311
+ - **TRC20/ERC20**: `0xa68d53f7853ce0175eb96aaad4a30c068ca96444`
312
+ - **Binance Pay ID**: `367669339`
313
+
314
+ *Recommended: TRC20 for lower gas fees*
315
+
316
+ #### Suggested Amounts:
317
+ - ☕ **$5** - A coffee (1 hour of development)
318
+ - 🍕 **$25** - A pizza (testing a new language)
319
+ - 🚀 **$100** - Rocket fuel (major feature development)
320
+
321
+ ---
322
+
323
+ #### 🔹 Recurring Support
324
+
325
+ **Ko-fi Membership**
326
+ [ko-fi.com/achatainga/tiers](https://ko-fi.com/achatainga/tiers)
327
+
328
+ Monthly tiers:
329
+ - **$5/month** - Supporter (name in SPONSORS.md)
330
+ - **$25/month** - Contributor (priority support, early access)
331
+ - **$100/month** - Sponsor (feature requests, 1-on-1 consultation)
332
+
333
+ ---
334
+
335
+ #### 🔹 Hire Me
336
+
337
+ Need custom MCP tools or AI integrations?
338
+
339
+ - 💼 **Available for**: Freelance contracts
340
+ - 🌐 **Location**: Caracas, Venezuela (Remote)
341
+ - 💻 **Skills**: TypeScript, Node.js, MCP, AI/LLM integrations
342
+ - 💵 **Rate**: $50-75/hour
343
+
344
+ 📧 **Contact**: a.chataing.a@gmail.com
345
+ 📄 **Details**: [HIRE_ME.md](HIRE_ME.md)
346
+
347
+ ---
348
+
349
+ ### 📊 Transparency
350
+
351
+ I believe in radical transparency:
352
+
353
+ **Current Status**:
354
+ - 💰 Donations received: $0
355
+ - 💸 Expenses: $20/month (npm, testing)
356
+ - ⏰ Time invested: ~10 hours/week
357
+ - 📦 Downloads: 10,000+/month
358
+
359
+ *(Updated monthly)*
360
+
361
+ ---
362
+
363
+ ### 🏆 Hall of Fame
364
+
365
+ Thank you to these amazing supporters:
366
+
367
+ *(No sponsors yet - be the first!)*
368
+
369
+ See full list: [SPONSORS.md](SPONSORS.md)
370
+
371
+ ---
372
+
373
+ ### ❤️ Non-Financial Support
374
+
375
+ Can't donate? No problem! You can still help:
376
+
377
+ - ⭐ Star the repo on GitHub
378
+ - 🐛 Report bugs or suggest features
379
+ - 📝 Improve documentation
380
+ - 🗣️ Share with others who might benefit
381
+ - 💬 Join discussions and help other users
382
+
383
+ Every contribution matters, financial or not.
384
+
385
+ ---
386
+
387
+ ## Development
388
+
389
+ ```bash
390
+ # Build
391
+ npm run build
392
+
393
+ # Run tests
394
+ npm test
395
+
396
+ # Development (build + start)
397
+ npm run dev
398
+ ```
399
+
400
+ ## Technical Details
401
+
402
+ - **Transport:** stdio (JSON-RPC over stdin/stdout)
403
+ - **Runtime:** Node.js >= 18
404
+ - **Protocol:** [Model Context Protocol](https://modelcontextprotocol.io/)
405
+ - **AST Engines:** web-tree-sitter@0.25.1 (WASM) for TypeScript/JS/Python/PHP/Dart
406
+ - **Language Grammars:** tree-sitter-wasms@0.1.13 (ABI v15)
407
+ - **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.
409
+ - **Portability:** 100% WASM - no native dependencies, works on all platforms
410
+
411
+ ## Contributing
412
+
413
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
414
+
415
+ ## Security
416
+
417
+ See [SECURITY.md](SECURITY.md) for security policies and reporting vulnerabilities.
418
+
419
+ ## Troubleshooting
420
+
421
+ See [TROUBLESHOOTING.md](TROUBLESHOOTING.md) for common issues and solutions.
422
+
423
+ ## Changelog
424
+
425
+ See [CHANGELOG.md](CHANGELOG.md) for version history.
426
+
427
+ ## License
428
+
429
+ [MIT](LICENSE)
430
+
431
+ ---
432
+
433
+ **Built with ❤️ from Caracas, Venezuela 🇻🇪**