Commit 76cb6fb
authored
feat: complete MCP tools compliance with VS Code extension specs (#57)
* feat: implement complete MCP tools compliance with VS Code extension specs
Complete implementation of MCP (Model Context Protocol) tool compliance by:
- Adding 2 missing tools from VS Code extension
- Converting all tool outputs to MCP-compliant format
- Exposing internal tools via MCP while preserving existing functionality
- Comprehensive test suite updates with robust JSON handling
- Updated documentation to reflect 100% VS Code compatibility
- **getLatestSelection**: Get most recent text selection (different from getCurrentSelection)
- **closeAllDiffTabs**: Close all diff-related tabs/windows with VS Code-compatible output format
All tools now return MCP-compliant format: `{content: [{type: "text", text: "JSON-stringified-data"}]}`
- **checkDocumentDirty**: Added schema for MCP exposure, success/failure JSON responses
- **saveDocument**: Added schema for MCP exposure, detailed success information
- **getWorkspaceFolders**: Added schema for MCP exposure, VS Code-compatible structure
- **getOpenEditors**: Restructured from `{editors: [...]}` to `{tabs: [...]}` with all VS Code fields
- **getCurrentSelection**: Enhanced with proper fallback behavior and MCP format
- **openFile**: Added missing parameters (preview, selectToEndOfLine, makeFrontmost, text selection)
- **closeTab**: Updated format while keeping internal-only (per Claude Code requirement)
- **Text Selection in openFile**: Full implementation of startText/endText pattern matching
- **Conditional Output**: openFile returns simple vs detailed responses based on makeFrontmost
- **Language Detection**: getOpenEditors includes proper languageId field mapping
- **Error Handling**: Comprehensive JSON-RPC error responses throughout
- **Robust JSON encoder/decoder**: Custom implementation supporting nested objects and special keys
- **Comprehensive test coverage**: All new tools with unit tests
- **Updated test expectations**: All existing tests adapted to MCP format
- **Format validation**: Tests verify exact VS Code extension compatibility
- **CLAUDE.md**: Complete rewrite of MCP tools section with 100% compliance status
- **Development Guidelines**: Added MCP tool development patterns and troubleshooting
- **Quality Standards**: Updated to reflect 320+ tests with 100% success rate
- **Protocol Compliance**: New section documenting VS Code extension feature parity
- **Backward compatibility**: No breaking changes to existing API
- **VS Code alignment**: Output formats match official VS Code extension exactly
- **Internal tools preserved**: close_tab remains internal as required by Claude Code architecture
- ✅ 320 tests passing (0 failures, 0 errors)
- ✅ All linting checks passing (0 warnings, 0 errors)
- ✅ Full MCP protocol compliance
- ✅ VS Code extension feature parity achieved
Change-Id: Ic1bd33aadb7fa45d64d4aba208acf37b2c9779cb
Signed-off-by: Thomas Kosiewski <tk@coder.com>
* fix: address PR review comments for MCP tools compliance
- Fix closeAllDiffTabs potential duplicate window closing by using set-based approach instead of array
- Add comprehensive test coverage for openFile parameters (makeFrontmost, preview mode, line/text selection)
- Update CLAUDE.md documentation to mention endLine parameter for openFile tool
- Enhance JSON encoder/decoder in test suite with proper escape sequence handling
- Add missing vim API mocks for complex openFile functionality testing
All 325 tests now pass with complete coverage of new MCP tool features.
Change-Id: I15bceb2bb44552205ea63c5ef1cb83722f7b5893
Signed-off-by: Thomas Kosiewski <tk@coder.com>
* fix: correct off-by-one indexing error in openFile text pattern search
Address Copilot review comment: when searching for endText pattern,
line_idx is already the correct 1-based index for the lines array,
so accessing lines[line_idx + 1] was incorrect.
Changed to lines[line_idx] to access the current line directly.
Change-Id: I05853ff183ef8f3e5df2863d2184a0cb58cb7e65
Signed-off-by: Thomas Kosiewski <tk@coder.com>
* feat: enhance MCP tools with VS Code compatibility and success fields
Change-Id: Iddb033256d1c8093e871f3a303a95e4df35ef9aa
Signed-off-by: Thomas Kosiewski <tk@coder.com>
---------
Signed-off-by: Thomas Kosiewski <tk@coder.com>1 parent fa8d64f commit 76cb6fb
File tree
22 files changed
+1762
-142
lines changed- lua/claudecode/tools
- tests
- mocks
- unit
- tools
22 files changed
+1762
-142
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
68 | | - | |
| 68 | + | |
69 | 69 | | |
70 | | - | |
| 70 | + | |
71 | 71 | | |
72 | | - | |
73 | | - | |
74 | | - | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
75 | 78 | | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
76 | 90 | | |
77 | 91 | | |
78 | 92 | | |
| |||
81 | 95 | | |
82 | 96 | | |
83 | 97 | | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
84 | 125 | | |
85 | 126 | | |
86 | 127 | | |
| |||
91 | 132 | | |
92 | 133 | | |
93 | 134 | | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
94 | 162 | | |
95 | 163 | | |
96 | 164 | | |
| |||
274 | 342 | | |
275 | 343 | | |
276 | 344 | | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
277 | 378 | | |
278 | 379 | | |
279 | | - | |
| 380 | + | |
280 | 381 | | |
| 382 | + | |
| 383 | + | |
281 | 384 | | |
282 | 385 | | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
3 | 19 | | |
4 | 20 | | |
5 | 21 | | |
| |||
14 | 30 | | |
15 | 31 | | |
16 | 32 | | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
24 | 45 | | |
25 | 46 | | |
26 | 47 | | |
| 48 | + | |
27 | 49 | | |
28 | | - | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
29 | 64 | | |
30 | 65 | | |
31 | 66 | | |
32 | 67 | | |
33 | | - | |
| 68 | + | |
34 | 69 | | |
35 | 70 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
0 commit comments