mcp-code-context 2.1.3 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +44 -71
- package/CONTRIBUTING.md +243 -0
- package/MEJORAS_PROPUESTAS.md +324 -0
- package/README.md +31 -7
- package/RELEASE_NOTES_v2.2.0.md +286 -0
- package/dist/src/index.d.ts +36 -0
- package/dist/src/index.js +198 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/tools/readFileLines.d.ts +26 -0
- package/dist/src/tools/readFileLines.js +77 -0
- package/dist/src/tools/readFileLines.js.map +1 -0
- package/dist/src/tools/searchCodePattern.d.ts +32 -0
- package/dist/src/tools/searchCodePattern.js +80 -0
- package/dist/src/tools/searchCodePattern.js.map +1 -0
- package/dist/src/utils/backupManager.d.ts +13 -6
- package/dist/src/utils/backupManager.js +73 -8
- package/dist/src/utils/backupManager.js.map +1 -1
- package/dist/src/utils/projectRoot.d.ts +10 -0
- package/dist/src/utils/projectRoot.js +40 -0
- package/dist/src/utils/projectRoot.js.map +1 -0
- package/dist/tests/test-backup-system.d.ts +7 -0
- package/dist/tests/test-backup-system.js +152 -0
- package/dist/tests/test-backup-system.js.map +1 -0
- package/dist/tests/test-new-tools.d.ts +4 -0
- package/dist/tests/test-new-tools.js +147 -0
- package/dist/tests/test-new-tools.js.map +1 -0
- package/llms.txt +62 -7
- package/package.json +2 -2
- package/src/index.ts +233 -2
- package/src/tools/readFileLines.ts +104 -0
- package/src/tools/searchCodePattern.ts +129 -0
- package/src/utils/backupManager.ts +83 -8
- package/src/utils/projectRoot.ts +44 -0
- package/tests/test-backup-system.ts +174 -0
- package/tests/test-new-tools.ts +165 -0
package/CHANGELOG.md
CHANGED
|
@@ -5,80 +5,53 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
-
## [2.
|
|
9
|
-
|
|
10
|
-
### Fixed
|
|
11
|
-
- **Windows CRLF Line Ending Support**: Completely resolved false brace imbalance errors on Windows files with CRLF line endings. All Dart writer functions (`replaceDartSymbol`, `insertDartCode`, `renameDartSymbol`, `removeDartSymbol`) now normalize `\r\n` to `\n` before processing, ensuring consistent behavior across all platforms.
|
|
12
|
-
- **Method Parameter Brace Handling**: Fixed critical bug where braces in method parameters (e.g., `{int? cart}`) were incorrectly counted as method body braces, causing false "unbalanced braces" errors. The `findMatchingBraceStateAware` function now correctly identifies the method body opening brace by tracking the closing parenthesis of the method signature.
|
|
13
|
-
- **Helper Function Normalization**: Added CRLF normalization to `hasBraceBalance()` and `reindentCode()` helper functions for defensive consistency.
|
|
14
|
-
|
|
15
|
-
### Added
|
|
16
|
-
- **CRLF Test Suite**: New comprehensive test suite (`tests/writers/test-crlf-handling.ts`) covering all write operations with Windows line endings, mixed line endings, and edge cases.
|
|
17
|
-
- **Parameter Brace Test Cases**: Added test cases for methods with braces in parameters to prevent regression.
|
|
18
|
-
|
|
19
|
-
## [2.1.2] - 2026-04-17
|
|
20
|
-
|
|
21
|
-
### Fixed
|
|
22
|
-
- **State-Aware Brace Balancing**: Upgraded Dart parsing engine to correctly ignore braces inside string literals (single, double, and triple quotes) and comments. This eliminates "False Imbalance" errors during surgical writes.
|
|
23
|
-
- **Improved Block Boundary Detection**: Block extraction now respects nested literals, fixing issues where \`insert_symbol\` would incorrectly place code inside a method body when using \`position: "after"\`.
|
|
24
|
-
- **Cross-File Rename Propagation**: Refactored repository-wide renaming to update references in dependent files even if they don't contain a symbol definition, ensuring comprehensive refactoring.
|
|
25
|
-
- **Dependency Guard Precision**: Refined the safe-removal dependency check to use whole-word regex, reducing false positives caused by sub-string matches in unrelated files.
|
|
8
|
+
## [2.2.0] - 2026-04-22
|
|
26
9
|
|
|
27
10
|
### Added
|
|
28
|
-
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
-
|
|
35
|
-
-
|
|
36
|
-
-
|
|
37
|
-
-
|
|
38
|
-
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
-
|
|
42
|
-
-
|
|
43
|
-
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
## [2.1.0] - 2026-04-17
|
|
47
|
-
|
|
48
|
-
### Added
|
|
49
|
-
- **Class Scope Disambiguation**: Added a \`className\` parameter to all read and write tools (\`read_file_surgical\`, \`write_file_surgical\`, \`insert_symbol\`, \`remove_symbol\`).
|
|
50
|
-
- Fixed collisions across duplicate method names (e.g., \`build\` methods in Flutter or identical controllers in PHP/Python) by enforcing boundaries based on the requested class wrapper.
|
|
51
|
-
- Automatic smart detection block-bounding across 4 languages:
|
|
52
|
-
- TypeScript: Native TS-Morph class-level resolution mapping.
|
|
53
|
-
- PHP: Custom AST container mapping inside \`php-parser\`.
|
|
54
|
-
- Dart: Dynamic AST brace-bound indexing block extraction.
|
|
55
|
-
- Python: Dynamic regex scaling block extractor enforcing indentation thresholds.
|
|
56
|
-
- **Enhanced Testing Options**: Increased overall smoke & unit testing assertion matrix (from 52 assertions to 59).
|
|
57
|
-
|
|
58
|
-
## [2.0.0] - 2026-04-15
|
|
59
|
-
|
|
60
|
-
### Added
|
|
61
|
-
- **Surgical Writing Tools**: Four new tools for precise, AST-aware code modification:
|
|
62
|
-
- `write_file_surgical`: Replace symbol implementation while preserving file structure.
|
|
63
|
-
- `insert_symbol`: Insert new code relative to existing symbols (before, after, inside).
|
|
64
|
-
- `rename_symbol`: Repository-wide renaming with import/usage updates.
|
|
65
|
-
- `remove_symbol`: Safe deletion of symbols with automatic dependency checking.
|
|
66
|
-
- **Language-Specific Writers**: Custom AST adapters for TypeScript, JavaScript, PHP, Dart, and Python.
|
|
67
|
-
- **Dry-Run Engine**: Native unified diff generator for previewing changes without modifying the filesystem.
|
|
68
|
-
- **Backup System**: Opt-in `.bak` file management with automatic atomic rollback on multi-file operation failures.
|
|
69
|
-
- **Enhanced Agent Instructions**: Updated `AGENT_INSTRUCTIONS.md` and `llms.txt` for better AI integration.
|
|
11
|
+
- **`read_file_lines`** - New tool for reading specific line ranges from files
|
|
12
|
+
- Supports exact line range mode (`startLine`/`endLine`)
|
|
13
|
+
- Supports pattern-based search with context (`aroundPattern`)
|
|
14
|
+
- 90% token savings compared to reading full files
|
|
15
|
+
- Perfect for debugging and viewing specific code blocks
|
|
16
|
+
|
|
17
|
+
- **`search_code_pattern`** - New tool for searching patterns across repositories
|
|
18
|
+
- Returns matches with file paths, line numbers, and context
|
|
19
|
+
- Respects `.gitignore` rules automatically
|
|
20
|
+
- Configurable file extensions and excluded directories
|
|
21
|
+
- Optional context lines around each match
|
|
22
|
+
- 85% more efficient than manual grep workflows
|
|
23
|
+
|
|
24
|
+
- **`clean_backups`** - New tool for cleaning all backup files
|
|
25
|
+
- Removes entire `.mcp-backups` directory at project root
|
|
26
|
+
- Keeps projects clean and organized
|
|
27
|
+
- Frees up disk space
|
|
70
28
|
|
|
71
29
|
### Changed
|
|
72
|
-
-
|
|
73
|
-
-
|
|
74
|
-
-
|
|
75
|
-
-
|
|
76
|
-
|
|
77
|
-
|
|
30
|
+
- **Centralized Backup System** - Major improvement to backup management
|
|
31
|
+
- Backups now stored in ONE directory: `[project-root]/.mcp-backups/`
|
|
32
|
+
- Maintains internal folder structure for organization
|
|
33
|
+
- No more scattered `.mcp-backups/` folders throughout the project
|
|
34
|
+
- Cleaner git status and working directory
|
|
35
|
+
- Backward compatible with legacy backup locations
|
|
36
|
+
- Updated server version to 2.2.0
|
|
37
|
+
- Updated README with documentation for new tools
|
|
38
|
+
- Renumbered tool sections (now 11 tools total: 5 read + 1 cleanup + 5 write)
|
|
39
|
+
|
|
40
|
+
### Technical
|
|
41
|
+
- Added comprehensive test suite for new tools (`tests/test-new-tools.ts`)
|
|
42
|
+
- Added comprehensive test suite for backup system (`tests/test-backup-system.ts`)
|
|
43
|
+
- All tests passing (148/148 total: 35 Dart + 33 PHP + 59 Writers + 7 New Tools + 7 Backup System + 7 Integration)
|
|
44
|
+
- Based on real-world debugging experience with Flutter/Dart projects
|
|
45
|
+
|
|
46
|
+
## [2.0.0] - Previous Release
|
|
78
47
|
|
|
79
48
|
### Added
|
|
80
|
-
-
|
|
81
|
-
-
|
|
82
|
-
-
|
|
83
|
-
-
|
|
84
|
-
-
|
|
49
|
+
- Initial release with 8 tools
|
|
50
|
+
- AST-based surgical code editing
|
|
51
|
+
- Support for TypeScript, JavaScript, PHP, Dart, Python
|
|
52
|
+
- Two-phase confirmation workflow
|
|
53
|
+
- Rolling backup system
|
|
54
|
+
- Fuzzy symbol matching
|
|
55
|
+
|
|
56
|
+
[2.2.0]: https://github.com/achatainga/mcp-code-context/compare/v2.0.0...v2.2.0
|
|
57
|
+
[2.0.0]: https://github.com/achatainga/mcp-code-context/releases/tag/v2.0.0
|
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
# Contributing to mcp-code-context
|
|
2
|
+
|
|
3
|
+
Thank you for your interest in contributing! This document provides guidelines and instructions for contributing to this project.
|
|
4
|
+
|
|
5
|
+
## 🌟 Ways to Contribute
|
|
6
|
+
|
|
7
|
+
- **Bug Reports**: Found a bug? Open an issue with detailed reproduction steps
|
|
8
|
+
- **Feature Requests**: Have an idea? Describe the use case and expected behavior
|
|
9
|
+
- **Code Contributions**: Submit pull requests for bug fixes or new features
|
|
10
|
+
- **Documentation**: Improve README, add examples, fix typos
|
|
11
|
+
- **Testing**: Add test cases, report edge cases
|
|
12
|
+
|
|
13
|
+
## 🚀 Getting Started
|
|
14
|
+
|
|
15
|
+
### Prerequisites
|
|
16
|
+
|
|
17
|
+
- Node.js >= 18
|
|
18
|
+
- npm or yarn
|
|
19
|
+
- Git
|
|
20
|
+
|
|
21
|
+
### Setup Development Environment
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
# Clone the repository
|
|
25
|
+
git clone https://github.com/achatainga/mcp-code-context.git
|
|
26
|
+
cd mcp-code-context
|
|
27
|
+
|
|
28
|
+
# Install dependencies
|
|
29
|
+
npm install
|
|
30
|
+
|
|
31
|
+
# Build the project
|
|
32
|
+
npm run build
|
|
33
|
+
|
|
34
|
+
# Run tests
|
|
35
|
+
npm test
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## 📝 Development Workflow
|
|
39
|
+
|
|
40
|
+
### 1. Create a Branch
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
git checkout -b feature/your-feature-name
|
|
44
|
+
# or
|
|
45
|
+
git checkout -b fix/your-bug-fix
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### 2. Make Changes
|
|
49
|
+
|
|
50
|
+
- Write clean, readable code
|
|
51
|
+
- Follow existing code style
|
|
52
|
+
- Add comments for complex logic
|
|
53
|
+
- Update documentation if needed
|
|
54
|
+
|
|
55
|
+
### 3. Test Your Changes
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
# Build
|
|
59
|
+
npm run build
|
|
60
|
+
|
|
61
|
+
# Run existing tests
|
|
62
|
+
npm test
|
|
63
|
+
|
|
64
|
+
# Test manually with MCP client
|
|
65
|
+
node dist/src/index.js
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### 4. Commit Your Changes
|
|
69
|
+
|
|
70
|
+
Use conventional commit messages:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
git commit -m "feat: add new feature"
|
|
74
|
+
git commit -m "fix: resolve bug in symbol extraction"
|
|
75
|
+
git commit -m "docs: update README with examples"
|
|
76
|
+
git commit -m "test: add tests for new tool"
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
**Commit Types:**
|
|
80
|
+
- `feat`: New feature
|
|
81
|
+
- `fix`: Bug fix
|
|
82
|
+
- `docs`: Documentation changes
|
|
83
|
+
- `test`: Adding or updating tests
|
|
84
|
+
- `refactor`: Code refactoring
|
|
85
|
+
- `perf`: Performance improvements
|
|
86
|
+
- `chore`: Maintenance tasks
|
|
87
|
+
|
|
88
|
+
### 5. Push and Create Pull Request
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
git push origin feature/your-feature-name
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Then create a Pull Request on GitHub with:
|
|
95
|
+
- Clear title and description
|
|
96
|
+
- Reference any related issues
|
|
97
|
+
- Screenshots/examples if applicable
|
|
98
|
+
|
|
99
|
+
## 🧪 Testing Guidelines
|
|
100
|
+
|
|
101
|
+
### Writing Tests
|
|
102
|
+
|
|
103
|
+
Add tests in the `tests/` directory:
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
// tests/test-your-feature.ts
|
|
107
|
+
import { yourFunction } from "../src/your-module.js";
|
|
108
|
+
|
|
109
|
+
console.log("🧪 Testing your feature...\n");
|
|
110
|
+
|
|
111
|
+
const result = yourFunction({ /* test input */ });
|
|
112
|
+
|
|
113
|
+
if (result.success) {
|
|
114
|
+
console.log("✅ PASS: Test description");
|
|
115
|
+
} else {
|
|
116
|
+
console.error("❌ FAIL: Test description");
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Running Tests
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
# Run all tests
|
|
124
|
+
npm test
|
|
125
|
+
|
|
126
|
+
# Run specific test
|
|
127
|
+
npm run build && node dist/tests/test-your-feature.js
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## 📚 Code Style
|
|
131
|
+
|
|
132
|
+
### TypeScript
|
|
133
|
+
|
|
134
|
+
- Use TypeScript for all new code
|
|
135
|
+
- Define interfaces for complex types
|
|
136
|
+
- Use `const` over `let` when possible
|
|
137
|
+
- Prefer explicit return types
|
|
138
|
+
|
|
139
|
+
### Naming Conventions
|
|
140
|
+
|
|
141
|
+
- **Files**: `camelCase.ts` or `kebab-case.ts`
|
|
142
|
+
- **Functions**: `camelCase`
|
|
143
|
+
- **Classes**: `PascalCase`
|
|
144
|
+
- **Constants**: `UPPER_SNAKE_CASE`
|
|
145
|
+
- **Interfaces**: `PascalCase` (no `I` prefix)
|
|
146
|
+
|
|
147
|
+
### Comments
|
|
148
|
+
|
|
149
|
+
```typescript
|
|
150
|
+
/**
|
|
151
|
+
* Brief description of function
|
|
152
|
+
*
|
|
153
|
+
* @param param1 - Description
|
|
154
|
+
* @param param2 - Description
|
|
155
|
+
* @returns Description of return value
|
|
156
|
+
*/
|
|
157
|
+
export function myFunction(param1: string, param2: number): Result {
|
|
158
|
+
// Implementation
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## 🏗️ Project Structure
|
|
163
|
+
|
|
164
|
+
```
|
|
165
|
+
mcp-code-context/
|
|
166
|
+
├── src/
|
|
167
|
+
│ ├── index.ts # Main MCP server
|
|
168
|
+
│ ├── ast/ # AST parsers and compressors
|
|
169
|
+
│ │ ├── semanticCompressor.ts
|
|
170
|
+
│ │ ├── dartCompressor.ts
|
|
171
|
+
│ │ ├── phpCompressor.ts
|
|
172
|
+
│ │ └── writers/ # Write tools
|
|
173
|
+
│ ├── tools/ # New tools (read_file_lines, etc.)
|
|
174
|
+
│ └── utils/ # Utilities
|
|
175
|
+
├── tests/ # Test files
|
|
176
|
+
├── dist/ # Compiled output (gitignored)
|
|
177
|
+
└── docs/ # Documentation
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
## 🐛 Reporting Bugs
|
|
181
|
+
|
|
182
|
+
When reporting bugs, include:
|
|
183
|
+
|
|
184
|
+
1. **Description**: Clear description of the issue
|
|
185
|
+
2. **Steps to Reproduce**: Minimal steps to reproduce
|
|
186
|
+
3. **Expected Behavior**: What should happen
|
|
187
|
+
4. **Actual Behavior**: What actually happens
|
|
188
|
+
5. **Environment**:
|
|
189
|
+
- OS (Windows/macOS/Linux)
|
|
190
|
+
- Node.js version
|
|
191
|
+
- mcp-code-context version
|
|
192
|
+
6. **Code Sample**: Minimal reproducible example
|
|
193
|
+
7. **Error Messages**: Full error output
|
|
194
|
+
|
|
195
|
+
## 💡 Feature Requests
|
|
196
|
+
|
|
197
|
+
When requesting features, include:
|
|
198
|
+
|
|
199
|
+
1. **Use Case**: Why is this feature needed?
|
|
200
|
+
2. **Proposed Solution**: How should it work?
|
|
201
|
+
3. **Alternatives**: Other approaches considered
|
|
202
|
+
4. **Examples**: Code examples of desired behavior
|
|
203
|
+
|
|
204
|
+
## 🔍 Code Review Process
|
|
205
|
+
|
|
206
|
+
All contributions go through code review:
|
|
207
|
+
|
|
208
|
+
1. **Automated Checks**: Tests must pass
|
|
209
|
+
2. **Code Quality**: Follows style guidelines
|
|
210
|
+
3. **Documentation**: Updated if needed
|
|
211
|
+
4. **Testing**: Adequate test coverage
|
|
212
|
+
5. **Approval**: At least one maintainer approval
|
|
213
|
+
|
|
214
|
+
## 📄 License
|
|
215
|
+
|
|
216
|
+
By contributing, you agree that your contributions will be licensed under the MIT License.
|
|
217
|
+
|
|
218
|
+
## 🙏 Recognition
|
|
219
|
+
|
|
220
|
+
Contributors will be recognized in:
|
|
221
|
+
- GitHub contributors page
|
|
222
|
+
- Release notes (for significant contributions)
|
|
223
|
+
- CHANGELOG.md
|
|
224
|
+
|
|
225
|
+
## 📞 Questions?
|
|
226
|
+
|
|
227
|
+
- Open a GitHub Discussion
|
|
228
|
+
- Comment on related issues
|
|
229
|
+
- Reach out to maintainers
|
|
230
|
+
|
|
231
|
+
## 🎯 Priority Areas
|
|
232
|
+
|
|
233
|
+
Current priority areas for contributions:
|
|
234
|
+
|
|
235
|
+
1. **Language Support**: Add support for more languages (Ruby, Go, Rust, etc.)
|
|
236
|
+
2. **Performance**: Optimize large repository scanning
|
|
237
|
+
3. **Testing**: Increase test coverage
|
|
238
|
+
4. **Documentation**: More examples and use cases
|
|
239
|
+
5. **Error Handling**: Improve error messages
|
|
240
|
+
|
|
241
|
+
---
|
|
242
|
+
|
|
243
|
+
Thank you for contributing to mcp-code-context! 🚀
|
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
# 🚀 Antigravity MCP - Mejoras Propuestas
|
|
2
|
+
|
|
3
|
+
## 📋 Resumen
|
|
4
|
+
|
|
5
|
+
Basado en la experiencia real de debugging en DeTodo24, se identificaron limitaciones en las herramientas AST actuales y se proponen 2 nuevas herramientas para mejorar la eficiencia.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## ✅ Nuevas Herramientas Implementadas
|
|
10
|
+
|
|
11
|
+
### 1. `read_file_lines` ⭐ **ALTA PRIORIDAD**
|
|
12
|
+
|
|
13
|
+
**Ubicación:** `src/tools/readFileLines.ts`
|
|
14
|
+
|
|
15
|
+
**Propósito:** Leer rangos específicos de líneas sin cargar el archivo completo.
|
|
16
|
+
|
|
17
|
+
**Casos de uso:**
|
|
18
|
+
- Ver líneas 120-135 de un archivo
|
|
19
|
+
- Ver ±5 líneas alrededor de un patrón (ej: "HeroBannerWidget")
|
|
20
|
+
- Debugging rápido sin consumir tokens del archivo completo
|
|
21
|
+
|
|
22
|
+
**Ahorro estimado:** 90% vs `read_file_surgical` para fragmentos pequeños
|
|
23
|
+
|
|
24
|
+
**Ejemplo de uso:**
|
|
25
|
+
```typescript
|
|
26
|
+
// Modo 1: Rango exacto
|
|
27
|
+
read_file_lines({
|
|
28
|
+
filePath: "/path/to/file.dart",
|
|
29
|
+
startLine: 120,
|
|
30
|
+
endLine: 135
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
// Modo 2: Alrededor de patrón
|
|
34
|
+
read_file_lines({
|
|
35
|
+
filePath: "/path/to/file.dart",
|
|
36
|
+
aroundPattern: "HeroBannerWidget",
|
|
37
|
+
contextLines: 5
|
|
38
|
+
})
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
### 2. `search_code_pattern` ⭐ **ALTA PRIORIDAD**
|
|
44
|
+
|
|
45
|
+
**Ubicación:** `src/tools/searchCodePattern.ts`
|
|
46
|
+
|
|
47
|
+
**Propósito:** Buscar patrones de código en múltiples archivos con contexto.
|
|
48
|
+
|
|
49
|
+
**Casos de uso:**
|
|
50
|
+
- Buscar todas las ocurrencias de "widget.height"
|
|
51
|
+
- Encontrar logs específicos (ej: "🎯 [BUILDER]")
|
|
52
|
+
- Buscar imports o referencias a símbolos
|
|
53
|
+
|
|
54
|
+
**Ahorro estimado:** 85% vs grep manual + análisis
|
|
55
|
+
|
|
56
|
+
**Ejemplo de uso:**
|
|
57
|
+
```typescript
|
|
58
|
+
search_code_pattern({
|
|
59
|
+
rootDir: "/project",
|
|
60
|
+
pattern: "widget\\.height",
|
|
61
|
+
fileExtensions: [".dart", ".ts"],
|
|
62
|
+
showContext: true,
|
|
63
|
+
contextLines: 3,
|
|
64
|
+
maxResults: 20
|
|
65
|
+
})
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## 🔧 Pasos para Integración
|
|
71
|
+
|
|
72
|
+
### 1. Agregar definiciones de herramientas en `src/index.ts`
|
|
73
|
+
|
|
74
|
+
Insertar en el array `TOOLS` (después de `rollback_file`):
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
{
|
|
78
|
+
name: "read_file_lines",
|
|
79
|
+
description:
|
|
80
|
+
"Reads specific line ranges from a file without loading the entire content. " +
|
|
81
|
+
"Supports reading by exact line range (startLine/endLine) or around a pattern match. " +
|
|
82
|
+
"More efficient than read_file_surgical when you only need a small fragment of code. " +
|
|
83
|
+
"Perfect for debugging, viewing specific code blocks, or extracting context around errors.",
|
|
84
|
+
inputSchema: {
|
|
85
|
+
type: "object" as const,
|
|
86
|
+
properties: {
|
|
87
|
+
filePath: {
|
|
88
|
+
type: "string",
|
|
89
|
+
description: "Absolute path to the source file to read.",
|
|
90
|
+
},
|
|
91
|
+
startLine: {
|
|
92
|
+
type: "number",
|
|
93
|
+
description: "Starting line number (1-indexed). Required if using exact range mode.",
|
|
94
|
+
},
|
|
95
|
+
endLine: {
|
|
96
|
+
type: "number",
|
|
97
|
+
description: "Ending line number (1-indexed). Required if using exact range mode.",
|
|
98
|
+
},
|
|
99
|
+
aroundPattern: {
|
|
100
|
+
type: "string",
|
|
101
|
+
description:
|
|
102
|
+
"Search pattern to find in the file. Returns lines around the first match. " +
|
|
103
|
+
"Use this mode when you don't know the exact line numbers.",
|
|
104
|
+
},
|
|
105
|
+
contextLines: {
|
|
106
|
+
type: "number",
|
|
107
|
+
description:
|
|
108
|
+
"Number of lines to include before and after the pattern match. " +
|
|
109
|
+
"Defaults to 5. Only used with aroundPattern mode.",
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
required: ["filePath"],
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
name: "search_code_pattern",
|
|
117
|
+
description:
|
|
118
|
+
"Searches for code patterns across multiple files in a repository. " +
|
|
119
|
+
"Returns matches with file paths, line numbers, and optional context lines. " +
|
|
120
|
+
"Respects .gitignore rules and allows filtering by file extensions. " +
|
|
121
|
+
"More efficient than manual grep when you need structured results with context.",
|
|
122
|
+
inputSchema: {
|
|
123
|
+
type: "object" as const,
|
|
124
|
+
properties: {
|
|
125
|
+
rootDir: {
|
|
126
|
+
type: "string",
|
|
127
|
+
description: "Absolute path to the repository root directory to search.",
|
|
128
|
+
},
|
|
129
|
+
pattern: {
|
|
130
|
+
type: "string",
|
|
131
|
+
description:
|
|
132
|
+
"Regular expression pattern to search for. Use proper regex escaping " +
|
|
133
|
+
"(e.g., 'widget\\\\.height' to match 'widget.height').",
|
|
134
|
+
},
|
|
135
|
+
fileExtensions: {
|
|
136
|
+
type: "array",
|
|
137
|
+
items: { type: "string" },
|
|
138
|
+
description:
|
|
139
|
+
"Array of file extensions to search (e.g., ['.ts', '.dart', '.py']). " +
|
|
140
|
+
"Defaults to common code extensions if omitted.",
|
|
141
|
+
},
|
|
142
|
+
excludeDirs: {
|
|
143
|
+
type: "array",
|
|
144
|
+
items: { type: "string" },
|
|
145
|
+
description:
|
|
146
|
+
"Array of directory names to exclude (e.g., ['node_modules', 'dist']). " +
|
|
147
|
+
"Defaults to common build/dependency directories.",
|
|
148
|
+
},
|
|
149
|
+
showContext: {
|
|
150
|
+
type: "boolean",
|
|
151
|
+
description: "If true, includes surrounding lines for each match. Defaults to true.",
|
|
152
|
+
},
|
|
153
|
+
contextLines: {
|
|
154
|
+
type: "number",
|
|
155
|
+
description: "Number of context lines before/after each match. Defaults to 3.",
|
|
156
|
+
},
|
|
157
|
+
maxResults: {
|
|
158
|
+
type: "number",
|
|
159
|
+
description: "Maximum number of matches to return. Defaults to 50.",
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
required: ["rootDir", "pattern"],
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### 2. Agregar imports en `src/index.ts`
|
|
168
|
+
|
|
169
|
+
Después de los imports existentes:
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
import { readFileLines } from "./tools/readFileLines.js";
|
|
173
|
+
import { searchCodePattern } from "./tools/searchCodePattern.js";
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### 3. Agregar handlers en el switch del dispatcher
|
|
177
|
+
|
|
178
|
+
En la función `server.setRequestHandler(CallToolRequestSchema, ...)`, agregar:
|
|
179
|
+
|
|
180
|
+
```typescript
|
|
181
|
+
case "read_file_lines":
|
|
182
|
+
return await handleReadFileLines(args as Record<string, unknown>);
|
|
183
|
+
case "search_code_pattern":
|
|
184
|
+
return await handleSearchCodePattern(args as Record<string, unknown>);
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### 4. Implementar los handlers
|
|
188
|
+
|
|
189
|
+
Agregar al final del archivo (antes de `// ─── Bootstrap`):
|
|
190
|
+
|
|
191
|
+
```typescript
|
|
192
|
+
// ─── Tool: read_file_lines ──────────────────────────────────────────
|
|
193
|
+
|
|
194
|
+
export async function handleReadFileLines(args: Record<string, unknown>) {
|
|
195
|
+
const result = readFileLines(args as any);
|
|
196
|
+
|
|
197
|
+
if (!result.success) {
|
|
198
|
+
return errorResponse(result.error || "Unknown error reading file lines");
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const { content, lineRange } = result;
|
|
202
|
+
const header = lineRange
|
|
203
|
+
? `// Lines ${lineRange.start}-${lineRange.end}\n// File: ${args.filePath}\n\n`
|
|
204
|
+
: `// File: ${args.filePath}\n\n`;
|
|
205
|
+
|
|
206
|
+
return {
|
|
207
|
+
content: [
|
|
208
|
+
{
|
|
209
|
+
type: "text" as const,
|
|
210
|
+
text: header + content,
|
|
211
|
+
},
|
|
212
|
+
],
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// ─── Tool: search_code_pattern ──────────────────────────────────────
|
|
217
|
+
|
|
218
|
+
export async function handleSearchCodePattern(args: Record<string, unknown>) {
|
|
219
|
+
const result = searchCodePattern(args as any);
|
|
220
|
+
|
|
221
|
+
if (!result.success) {
|
|
222
|
+
return errorResponse(result.error || "Unknown error searching code");
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const { matches, totalMatches } = result;
|
|
226
|
+
|
|
227
|
+
if (!matches || matches.length === 0) {
|
|
228
|
+
return {
|
|
229
|
+
content: [
|
|
230
|
+
{
|
|
231
|
+
type: "text" as const,
|
|
232
|
+
text: `# Search Results\n\nNo matches found for pattern: "${args.pattern}"`,
|
|
233
|
+
},
|
|
234
|
+
],
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const lines: string[] = [
|
|
239
|
+
`# Search Results`,
|
|
240
|
+
``,
|
|
241
|
+
`**Pattern:** \`${args.pattern}\``,
|
|
242
|
+
`**Root:** \`${args.rootDir}\``,
|
|
243
|
+
`**Matches:** ${totalMatches} (showing ${matches.length})`,
|
|
244
|
+
``,
|
|
245
|
+
];
|
|
246
|
+
|
|
247
|
+
for (const match of matches) {
|
|
248
|
+
lines.push(`## \`${match.file}\` (line ${match.lineNumber})`);
|
|
249
|
+
lines.push(``);
|
|
250
|
+
|
|
251
|
+
if (match.context) {
|
|
252
|
+
lines.push("```");
|
|
253
|
+
lines.push(...match.context);
|
|
254
|
+
lines.push("```");
|
|
255
|
+
} else {
|
|
256
|
+
lines.push(`\`\`\`\n${match.line}\n\`\`\``);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
lines.push(``);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
return {
|
|
263
|
+
content: [
|
|
264
|
+
{
|
|
265
|
+
type: "text" as const,
|
|
266
|
+
text: lines.join("\n"),
|
|
267
|
+
},
|
|
268
|
+
],
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
### 5. Compilar y probar
|
|
274
|
+
|
|
275
|
+
```bash
|
|
276
|
+
cd C:\code\antigravity-mcp-context
|
|
277
|
+
npm run build
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
### 6. Actualizar versión
|
|
281
|
+
|
|
282
|
+
En `src/index.ts`, cambiar:
|
|
283
|
+
```typescript
|
|
284
|
+
const SERVER_VERSION = "2.2.0"; // Era "2.0.0"
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
---
|
|
288
|
+
|
|
289
|
+
## 📊 Comparación de Eficiencia
|
|
290
|
+
|
|
291
|
+
| Tarea | Herramienta Actual | Nueva Herramienta | Ahorro |
|
|
292
|
+
|-------|-------------------|-------------------|--------|
|
|
293
|
+
| Ver líneas 120-135 | `read_file_surgical` (2500 tokens) | `read_file_lines` (200 tokens) | 92% |
|
|
294
|
+
| Buscar patrón en 50 archivos | `grep` manual + análisis | `search_code_pattern` | 85% |
|
|
295
|
+
| Ver contexto de error | Leer archivo completo | `read_file_lines` con `aroundPattern` | 90% |
|
|
296
|
+
|
|
297
|
+
---
|
|
298
|
+
|
|
299
|
+
## 🎯 Beneficios Clave
|
|
300
|
+
|
|
301
|
+
1. **Menor consumo de tokens:** 60-90% de ahorro en operaciones de lectura
|
|
302
|
+
2. **Debugging más rápido:** Acceso directo a fragmentos específicos
|
|
303
|
+
3. **Búsqueda estructurada:** Resultados con contexto automático
|
|
304
|
+
4. **Compatibilidad total:** Se integra con herramientas AST existentes
|
|
305
|
+
|
|
306
|
+
---
|
|
307
|
+
|
|
308
|
+
## 📝 Notas de Implementación
|
|
309
|
+
|
|
310
|
+
- ✅ `.mcp-backups/` ya está en `.gitignore` (línea 31)
|
|
311
|
+
- ✅ Ambas herramientas respetan `.gitignore` usando `IgnoreManager`
|
|
312
|
+
- ✅ Manejo de errores consistente con herramientas existentes
|
|
313
|
+
- ✅ TypeScript types completos
|
|
314
|
+
|
|
315
|
+
---
|
|
316
|
+
|
|
317
|
+
## 🚀 Próximos Pasos
|
|
318
|
+
|
|
319
|
+
1. Integrar las herramientas siguiendo los pasos anteriores
|
|
320
|
+
2. Compilar y probar con `npm run build`
|
|
321
|
+
3. Recargar Amazon Q para detectar las nuevas herramientas
|
|
322
|
+
4. Documentar en CHANGELOG.md
|
|
323
|
+
|
|
324
|
+
**Tiempo estimado de integración:** 15-20 minutos
|