fileditor-mcp 1.0.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.
@@ -0,0 +1,976 @@
1
+ # MCP 文件操作工具集文档
2
+
3
+ ## 工具概述
4
+
5
+ 本文档描述了符合 MCP (Model Context Protocol) 规范的文件操作工具集,包含 7 个核心工具用于工作区管理和文件的读取、写入、修改、搜索操作。
6
+
7
+ ## 🔒 安全特性
8
+
9
+ - **工作区隔离**: 必须先调用 `set_workspace` 设置工作区根目录
10
+ - **路径安全**: 所有文件操作严格限制在设置的工作区内,防止目录遍历攻击
11
+ - **相对路径支持**: 相对路径自动基于工作区根目录解析
12
+
13
+ **⚠️ 重要**: 在进行任何文件操作前,必须先调用 `set_workspace` 工具设置工作区根目录,否则所有操作将被拒绝。
14
+
15
+ **实现状态**:
16
+ - ✅ `set_workspace` - 已实现(工作区设置)
17
+ - ✅ `read_files` - 已实现
18
+ - ✅ `write_files` - 已实现
19
+ - ✅ `list_files` - 已实现
20
+ - ✅ `insert_contents` - 已实现
21
+ - ✅ `apply_diffs` - 已实现
22
+ - ✅ `search_and_replace` - 已实现
23
+
24
+ ---
25
+
26
+ ## 0. `set_workspace` (设置工作区)
27
+
28
+ **描述**: 设置工作区根目录,所有后续的文件操作都将基于此目录。相对路径将自动解析为工作区内的路径,绝对路径必须在工作区范围内。
29
+
30
+ **MCP 调用格式**:
31
+ ```json
32
+ {
33
+ "name": "set_workspace",
34
+ "arguments": {
35
+ "path": "/absolute/path/to/workspace"
36
+ }
37
+ }
38
+ ```
39
+
40
+ **返回值示例**:
41
+ ```json
42
+ {
43
+ "content": [
44
+ {
45
+ "type": "text",
46
+ "text": "Successfully set workspace root to: /Users/username/projects/my-project"
47
+ }
48
+ ]
49
+ }
50
+ ```
51
+
52
+ ---
53
+
54
+ ## 1. `read_files` (读取文件)
55
+
56
+ **描述**: 读取指定文件的全部或部分内容,支持单文件或多文件同时读取。返回内容带有行号显示(格式:`行号 | 内容`),便于其他工具操作时定位行号。
57
+
58
+ **MCP 调用格式**:
59
+ ```json
60
+ {
61
+ "name": "read_files",
62
+ "arguments": {
63
+ "path": "文件路径 或 文件路径数组",
64
+ "line_range": "起始行-结束行" // 可选,仅适用于单文件,格式如 "1-50"
65
+ }
66
+ }
67
+ ```
68
+
69
+ **参数 Schema**:
70
+ ```json
71
+ {
72
+ "type": "object",
73
+ "properties": {
74
+ "path": {
75
+ "oneOf": [
76
+ {
77
+ "type": "string",
78
+ "description": "要读取的单个文件路径"
79
+ },
80
+ {
81
+ "type": "array",
82
+ "items": {
83
+ "type": "string"
84
+ },
85
+ "description": "要读取的多个文件路径数组"
86
+ }
87
+ ]
88
+ },
89
+ "line_range": {
90
+ "type": "string",
91
+ "description": "可选的行范围,格式为 '起始行-结束行'(仅适用于单文件)",
92
+ "pattern": "^\\d+-\\d+$"
93
+ }
94
+ },
95
+ "required": ["path"]
96
+ }
97
+ ```
98
+
99
+ **使用示例**:
100
+
101
+ *单文件读取:*
102
+ ```json
103
+ {
104
+ "name": "read_files",
105
+ "arguments": {
106
+ "path": "src/main/java/com/example/lsmtree/MemTable.java"
107
+ }
108
+ }
109
+ ```
110
+
111
+ **返回值示例**:
112
+ ```json
113
+ {
114
+ "content": [
115
+ {
116
+ "type": "text",
117
+ "text": "1 | package com.example.lsmtree;\n2 | \n3 | import java.util.*;\n4 | \n5 | public class MemTable {\n6 | // 类内容...\n7 | }"
118
+ }
119
+ ]
120
+ }
121
+ ```
122
+
123
+ *多文件读取:*
124
+ ```json
125
+ {
126
+ "name": "read_files",
127
+ "arguments": {
128
+ "path": ["package.json", "README.md"]
129
+ }
130
+ }
131
+ ```
132
+
133
+ **返回值示例**:
134
+ ```json
135
+ {
136
+ "content": [
137
+ {
138
+ "type": "text",
139
+ "text": "Successfully read 2 file(s):\n\n=== package.json (25 lines) ===\n{\n \"name\": \"fileditor-mcp\",\n \"version\": \"1.0.0\",\n ...\n}\n\n=== README.md (15 lines) ===\n# FileEditor MCP\n\nThis is a file editor...\n"
140
+ }
141
+ ]
142
+ }
143
+ ```
144
+
145
+ *单文件指定行范围:*
146
+ ```json
147
+ {
148
+ "name": "read_files",
149
+ "arguments": {
150
+ "path": "config.properties",
151
+ "line_range": "1-10"
152
+ }
153
+ }
154
+ ```
155
+
156
+ **返回值示例**:
157
+ ```json
158
+ {
159
+ "content": [
160
+ {
161
+ "type": "text",
162
+ "text": "# Configuration file\nserver.port=8080\ndb.url=localhost:3306\n..."
163
+ }
164
+ ]
165
+ }
166
+ ```
167
+
168
+ ---
169
+
170
+ ## 2. `write_files` (写入文件)
171
+
172
+ **描述**: 创建新文件或完全覆盖现有文件内容,支持单文件或多文件同时创建
173
+
174
+ **MCP 调用格式**:
175
+ ```json
176
+ {
177
+ "name": "write_files",
178
+ "arguments": {
179
+ "path": "文件路径" | ["路径1", "路径2", ...],
180
+ "content": "要写入的完整文件内容" | ["内容1", "内容2", ...],
181
+ "line_count": 文件总行数 | [行数1, 行数2, ...]
182
+ }
183
+ }
184
+ ```
185
+
186
+ **参数 Schema**:
187
+ ```json
188
+ {
189
+ "type": "object",
190
+ "properties": {
191
+ "path": {
192
+ "oneOf": [
193
+ {
194
+ "type": "string",
195
+ "description": "单个目标文件路径"
196
+ },
197
+ {
198
+ "type": "array",
199
+ "items": {"type": "string"},
200
+ "description": "多个目标文件路径数组"
201
+ }
202
+ ]
203
+ },
204
+ "content": {
205
+ "oneOf": [
206
+ {
207
+ "type": "string",
208
+ "description": "要写入的完整文件内容,适用于单文件或所有文件写入相同内容"
209
+ },
210
+ {
211
+ "type": "array",
212
+ "items": {"type": "string"},
213
+ "description": "每个文件对应的内容数组,适用于多文件不同内容"
214
+ }
215
+ ]
216
+ },
217
+ "line_count": {
218
+ "oneOf": [
219
+ {
220
+ "type": "integer",
221
+ "description": "文件内容的总行数,适用于单文件或所有文件相同行数",
222
+ "minimum": 0
223
+ },
224
+ {
225
+ "type": "array",
226
+ "items": {"type": "integer", "minimum": 0},
227
+ "description": "每个文件对应的行数数组,适用于多文件不同行数"
228
+ }
229
+ ]
230
+ }
231
+ },
232
+ "required": ["path", "content", "line_count"]
233
+ }
234
+ ```
235
+
236
+ **使用示例**:
237
+
238
+ *单文件写入*:
239
+ ```json
240
+ {
241
+ "name": "write_files",
242
+ "arguments": {
243
+ "path": "config/database.js",
244
+ "content": "export const config = {\n host: 'localhost',\n port: 3306\n};",
245
+ "line_count": 4
246
+ }
247
+ }
248
+ ```
249
+
250
+ *多文件相同内容写入*:
251
+ ```json
252
+ {
253
+ "name": "write_files",
254
+ "arguments": {
255
+ "path": ["config/dev.env", "config/test.env"],
256
+ "content": "NODE_ENV=development\nDEBUG=true",
257
+ "line_count": 2
258
+ }
259
+ }
260
+ ```
261
+
262
+ *多文件不同内容写入*:
263
+ ```json
264
+ {
265
+ "name": "write_files",
266
+ "arguments": {
267
+ "path": ["package.json", "README.md", ".gitignore"],
268
+ "content": [
269
+ "{\n \"name\": \"my-project\",\n \"version\": \"1.0.0\"\n}",
270
+ "# My Project\n\nA sample project",
271
+ "node_modules/\n*.log\n.env"
272
+ ],
273
+ "line_count": [4, 3, 3]
274
+ }
275
+ }
276
+ ```
277
+
278
+ **返回值示例**:
279
+
280
+ *单文件*:
281
+ ```json
282
+ {
283
+ "content": [
284
+ {
285
+ "type": "text",
286
+ "text": "File written successfully: config/database.js (4 lines)"
287
+ }
288
+ ]
289
+ }
290
+ ```
291
+
292
+ *多文件*:
293
+ ```json
294
+ {
295
+ "content": [
296
+ {
297
+ "type": "text",
298
+ "text": "Successfully wrote 3 files (10 total lines):\n - package.json (4 lines)\n - README.md (3 lines)\n - .gitignore (3 lines)"
299
+ }
300
+ ]
301
+ }
302
+ ```
303
+
304
+ ---
305
+
306
+ ## 3. `apply_diffs` (应用差异修改)
307
+
308
+ **描述**: 对现有文件进行精确的基于块的查找和替换操作。支持对单个文件进行单个或多个差异操作。处理多个差异时,工具自动处理行号偏移 - 所有 start_line 值应基于原始文件结构。默认以原子模式操作以确保批量操作安全。
309
+
310
+ **MCP 调用格式**:
311
+ ```json
312
+ {
313
+ "name": "apply_diffs",
314
+ "arguments": {
315
+ "path": "文件路径",
316
+ "search_content": "需要精确匹配的原始内容" | ["内容1", "内容2", ...],
317
+ "replace_content": "用于替换的新内容" | ["内容1", "内容2", ...],
318
+ "start_line": 起始行号 | [行号1, 行号2, ...],
319
+ "atomic": true/false, // 可选,默认为 true
320
+ "trim": true/false // 可选,默认为 false
321
+ }
322
+ }
323
+ ```
324
+
325
+ **参数 Schema**:
326
+ ```json
327
+ {
328
+ "type": "object",
329
+ "properties": {
330
+ "path": {
331
+ "type": "string",
332
+ "description": "要修改的文件路径"
333
+ },
334
+ "search_content": {
335
+ "oneOf": [
336
+ {
337
+ "type": "string",
338
+ "description": "需要精确匹配的原始内容(单个差异)"
339
+ },
340
+ {
341
+ "type": "array",
342
+ "items": {
343
+ "type": "string"
344
+ },
345
+ "description": "需要精确匹配的原始内容数组(多个差异)"
346
+ }
347
+ ]
348
+ },
349
+ "replace_content": {
350
+ "oneOf": [
351
+ {
352
+ "type": "string",
353
+ "description": "用于替换的新内容(单个差异)"
354
+ },
355
+ {
356
+ "type": "array",
357
+ "items": {
358
+ "type": "string"
359
+ },
360
+ "description": "用于替换的新内容数组(多个差异)"
361
+ }
362
+ ]
363
+ },
364
+ "start_line": {
365
+ "oneOf": [
366
+ {
367
+ "type": "integer",
368
+ "description": "搜索内容的起始行号(单个差异,从原始文件的1开始计数)",
369
+ "minimum": 1
370
+ },
371
+ {
372
+ "type": "array",
373
+ "items": {
374
+ "type": "integer",
375
+ "minimum": 1
376
+ },
377
+ "description": "搜索内容的起始行号数组(多个差异,所有行号都基于原始文件的1开始计数 - 工具在处理过程中自动处理行偏移调整)"
378
+ }
379
+ ]
380
+ },
381
+ "atomic": {
382
+ "type": "boolean",
383
+ "description": "是否使用原子模式(全部成功或全部失败)。为true时(默认),在应用任何差异之前验证所有差异。为false时,逐个应用差异,遇到失败时继续处理",
384
+ "default": true
385
+ },
386
+ "trim": {
387
+ "type": "boolean",
388
+ "description": "是否在比较 search_content 与文件内容时修剪每行的首尾空格。仅影响搜索和匹配过程 - replace_content 完全按提供的方式插入。默认为 false",
389
+ "default": false
390
+ }
391
+ },
392
+ "required": ["path", "search_content", "replace_content", "start_line"]
393
+ }
394
+ ```
395
+
396
+ **使用示例**:
397
+ ```json
398
+ {
399
+ "name": "apply_diffs",
400
+ "arguments": {
401
+ "path": "pom.xml",
402
+ "search_content": " <version>1.2.0</version>",
403
+ "replace_content": " <version>1.3.1</version>",
404
+ "start_line": 25
405
+ }
406
+ }
407
+ ```
408
+
409
+ **返回值示例**:
410
+ ```json
411
+ {
412
+ "content": [
413
+ {
414
+ "type": "text",
415
+ "text": "Successfully applied diff to pom.xml: replaced 1 line(s) at line 25. File now has 45 lines."
416
+ }
417
+ ]
418
+ }
419
+ ```
420
+
421
+ *多行替换示例:*
422
+ ```json
423
+ {
424
+ "name": "apply_diffs",
425
+ "arguments": {
426
+ "path": "config.js",
427
+ "search_content": "const config = {\n port: 3000,\n host: 'localhost'\n};",
428
+ "replace_content": "const config = {\n port: process.env.PORT || 8080,\n host: process.env.HOST || '0.0.0.0',\n ssl: process.env.SSL || false\n};",
429
+ "start_line": 10
430
+ }
431
+ }
432
+ ```
433
+
434
+ **返回值示例**:
435
+ ```json
436
+ {
437
+ "content": [
438
+ {
439
+ "type": "text",
440
+ "text": "Successfully applied diff to config.js: replaced 4 line(s) at line 10 (added 1 line(s)). File now has 26 lines."
441
+ }
442
+ ]
443
+ }
444
+ ```
445
+
446
+ *使用 trim 选项处理空格差异:*
447
+ ```json
448
+ {
449
+ "name": "apply_diffs",
450
+ "arguments": {
451
+ "path": "config.js",
452
+ "search_content": "console.log('Hello World');",
453
+ "replace_content": " console.log('Hello Universe');",
454
+ "start_line": 5,
455
+ "trim": true
456
+ }
457
+ }
458
+ ```
459
+
460
+ **返回值示例**:
461
+ ```json
462
+ {
463
+ "content": [
464
+ {
465
+ "type": "text",
466
+ "text": "Successfully applied diff to config.js: replaced 1 line(s) at line 5. File now has 25 lines."
467
+ }
468
+ ]
469
+ }
470
+ ```
471
+
472
+ *批量操作(原子模式):*
473
+ ```json
474
+ {
475
+ "name": "apply_diffs",
476
+ "arguments": {
477
+ "path": "main.js",
478
+ "search_content": [
479
+ " console.log('start');",
480
+ " return false;",
481
+ " console.log('end');"
482
+ ],
483
+ "replace_content": [
484
+ " console.log('application started');",
485
+ " return true;",
486
+ " console.log('application ended');"
487
+ ],
488
+ "start_line": [2, 15, 28],
489
+ "atomic": true
490
+ }
491
+ }
492
+ ```
493
+
494
+ **返回值示例**:
495
+ ```json
496
+ {
497
+ "content": [
498
+ {
499
+ "type": "text",
500
+ "text": "Batch diff operation (atomic) completed: 3/3 diffs applied successfully to main.js. File now has 30 lines.\n\nDetailed results:\n\nDiff 1:\n Status: success\n Start Line: 2\n Message: Replaced 1 line(s) at line 2\n\nDiff 2:\n Status: success\n Start Line: 15\n Message: Replaced 1 line(s) at line 15\n\nDiff 3:\n Status: success\n Start Line: 28\n Message: Replaced 1 line(s) at line 28"
501
+ }
502
+ ]
503
+ }
504
+ ```
505
+
506
+ ---
507
+
508
+ ## 4. `insert_contents` (插入内容)
509
+
510
+ **描述**: 在文件的指定位置插入新内容,支持单文件或多文件同时编辑。支持负数行号从文件末尾倒数计算插入位置(-1表示在最后一行前插入)
511
+
512
+ **MCP 调用格式**:
513
+ ```json
514
+ {
515
+ "name": "insert_contents",
516
+ "arguments": {
517
+ "path": "文件路径 或 文件路径数组",
518
+ "line": "行号 或 行号数组",
519
+ "content": "内容 或 内容数组"
520
+ }
521
+ }
522
+ ```
523
+
524
+ **参数 Schema**:
525
+ ```json
526
+ {
527
+ "type": "object",
528
+ "properties": {
529
+ "path": {
530
+ "oneOf": [
531
+ {
532
+ "type": "string",
533
+ "description": "单个目标文件路径"
534
+ },
535
+ {
536
+ "type": "array",
537
+ "items": {
538
+ "type": "string"
539
+ },
540
+ "description": "多个目标文件路径数组"
541
+ }
542
+ ]
543
+ },
544
+ "line": {
545
+ "oneOf": [
546
+ {
547
+ "type": "integer",
548
+ "description": "要插入的行号 (1-based, 0表示文件末尾),适用于单文件",
549
+ "minimum": 0
550
+ },
551
+ {
552
+ "type": "array",
553
+ "items": {
554
+ "type": "integer",
555
+ "minimum": 0
556
+ },
557
+ "description": "每个文件对应的行号数组,适用于多文件"
558
+ }
559
+ ]
560
+ },
561
+ "content": {
562
+ "oneOf": [
563
+ {
564
+ "type": "string",
565
+ "description": "要插入的内容,适用于单文件或所有文件插入相同内容"
566
+ },
567
+ {
568
+ "type": "array",
569
+ "items": {
570
+ "type": "string"
571
+ },
572
+ "description": "每个文件对应的内容数组,适用于多文件不同内容"
573
+ }
574
+ ]
575
+ }
576
+ },
577
+ "required": ["path", "line", "content"]
578
+ }
579
+ ```
580
+
581
+ **使用示例**:
582
+
583
+ *单文件插入:*
584
+ ```json
585
+ {
586
+ "name": "insert_contents",
587
+ "arguments": {
588
+ "path": "src/main/java/com/example/App.java",
589
+ "line": 3,
590
+ "content": "import java.util.ArrayList;"
591
+ }
592
+ }
593
+ ```
594
+
595
+ **返回值示例**:
596
+ ```json
597
+ {
598
+ "content": [
599
+ {
600
+ "type": "text",
601
+ "text": "Successfully inserted 1 line(s) at position 3 in src/main/java/com/example/App.java. File now has 25 lines."
602
+ }
603
+ ]
604
+ }
605
+ ```
606
+
607
+ *多文件相同位置插入相同内容:*
608
+ ```json
609
+ {
610
+ "name": "insert_contents",
611
+ "arguments": {
612
+ "path": ["file1.js", "file2.js", "file3.js"],
613
+ "line": 1,
614
+ "content": "// 添加的注释"
615
+ }
616
+ }
617
+ ```
618
+
619
+ **返回值示例**:
620
+ ```json
621
+ {
622
+ "content": [
623
+ {
624
+ "type": "text",
625
+ "text": "Successfully processed 3 file(s):\n\n✅ file1.js: Successfully inserted 1 line(s) at position 1 in file1.js. File now has 15 lines.\n✅ file2.js: Successfully inserted 1 line(s) at position 1 in file2.js. File now has 22 lines.\n✅ file3.js: Successfully inserted 1 line(s) at position 1 in file3.js. File now has 8 lines."
626
+ }
627
+ ]
628
+ }
629
+ ```
630
+
631
+ *多文件不同位置插入不同内容:*
632
+ ```json
633
+ {
634
+ "name": "insert_contents",
635
+ "arguments": {
636
+ "path": ["config.js", "utils.js", "main.js"],
637
+ "line": [1, 5, 0],
638
+ "content": [
639
+ "// 配置文件",
640
+ "// 工具函数",
641
+ "// 主程序入口"
642
+ ]
643
+ }
644
+ }
645
+ ```
646
+
647
+ **返回值示例**:
648
+ ```json
649
+ {
650
+ "content": [
651
+ {
652
+ "type": "text",
653
+ "text": "Successfully processed 3 file(s):\n\n✅ config.js: Successfully inserted 1 line(s) at position 1 in config.js. File now has 20 lines.\n✅ utils.js: Successfully inserted 1 line(s) at position 5 in utils.js. File now has 35 lines.\n✅ main.js: Successfully inserted 1 line(s) at position end of file in main.js. File now has 45 lines."
654
+ }
655
+ ]
656
+ }
657
+ ```
658
+
659
+ ---
660
+
661
+ ## 5. `search_and_replace` (查找并替换)
662
+
663
+ **描述**: 在单个文件中查找并替换文本或正则表达式
664
+
665
+ **MCP 调用格式**:
666
+ ```json
667
+ {
668
+ "name": "search_and_replace",
669
+ "arguments": {
670
+ "path": "文件路径",
671
+ "search": "要查找的文本或正则表达式",
672
+ "replace": "用于替换的文本",
673
+ "use_regex": true/false,
674
+ "ignore_case": true/false,
675
+ "start_line": 起始行,
676
+ "end_line": 结束行
677
+ }
678
+ }
679
+ ```
680
+
681
+ **参数 Schema**:
682
+ ```json
683
+ {
684
+ "type": "object",
685
+ "properties": {
686
+ "path": {
687
+ "type": "string",
688
+ "description": "目标文件路径"
689
+ },
690
+ "search": {
691
+ "type": "string",
692
+ "description": "要查找的文本或正则表达式"
693
+ },
694
+ "replace": {
695
+ "type": "string",
696
+ "description": "用于替换的文本"
697
+ },
698
+ "use_regex": {
699
+ "type": "boolean",
700
+ "description": "是否使用正则表达式进行搜索",
701
+ "default": false
702
+ },
703
+ "ignore_case": {
704
+ "type": "boolean",
705
+ "description": "是否忽略大小写进行搜索",
706
+ "default": false
707
+ },
708
+ "start_line": {
709
+ "type": "integer",
710
+ "description": "搜索范围的起始行",
711
+ "minimum": 1
712
+ },
713
+ "end_line": {
714
+ "type": "integer",
715
+ "description": "搜索范围的结束行",
716
+ "minimum": 1
717
+ }
718
+ },
719
+ "required": ["path", "search", "replace"]
720
+ }
721
+ ```
722
+
723
+ **使用示例**:
724
+ ```json
725
+ {
726
+ "name": "search_and_replace",
727
+ "arguments": {
728
+ "path": "src/main/resources/application.properties",
729
+ "search": "app.name",
730
+ "replace": "spring.application.name",
731
+ "use_regex": false
732
+ }
733
+ }
734
+ ```
735
+
736
+ **返回值示例**:
737
+ ```json
738
+ {
739
+ "content": [
740
+ {
741
+ "type": "text",
742
+ "text": "Successfully replaced 3 occurrence(s) in src/main/resources/application.properties"
743
+ }
744
+ ]
745
+ }
746
+ ```
747
+
748
+ *使用正则表达式:*
749
+ ```json
750
+ {
751
+ "name": "search_and_replace",
752
+ "arguments": {
753
+ "path": "config.js",
754
+ "search": "const\\s+(\\w+)\\s*=\\s*require\\(['\"]([^'\"]+)['\"]\\)",
755
+ "replace": "import $1 from '$2'",
756
+ "use_regex": true
757
+ }
758
+ }
759
+ ```
760
+
761
+ **返回值示例**:
762
+ ```json
763
+ {
764
+ "content": [
765
+ {
766
+ "type": "text",
767
+ "text": "Successfully replaced 5 occurrence(s) in config.js using regex pattern"
768
+ }
769
+ ]
770
+ }
771
+ ```
772
+
773
+ *指定行范围:*
774
+ ```json
775
+ {
776
+ "name": "search_and_replace",
777
+ "arguments": {
778
+ "path": "package.json",
779
+ "search": "1.0.0",
780
+ "replace": "1.1.0",
781
+ "start_line": 1,
782
+ "end_line": 10
783
+ }
784
+ }
785
+ ```
786
+
787
+ **返回值示例**:
788
+ ```json
789
+ {
790
+ "content": [
791
+ {
792
+ "type": "text",
793
+ "text": "Successfully replaced 1 occurrence(s) in package.json (lines 1-10)"
794
+ }
795
+ ]
796
+ }
797
+ ```
798
+
799
+ *忽略大小写搜索:*
800
+ ```json
801
+ {
802
+ "name": "search_and_replace",
803
+ "arguments": {
804
+ "path": "README.md",
805
+ "search": "hello",
806
+ "replace": "Hi",
807
+ "ignore_case": true
808
+ }
809
+ }
810
+ ```
811
+
812
+ **返回值示例**:
813
+ ```json
814
+ {
815
+ "content": [
816
+ {
817
+ "type": "text",
818
+ "text": "Successfully replaced 3 occurrence(s) in README.md (case-insensitive)"
819
+ }
820
+ ]
821
+ }
822
+ ```
823
+
824
+ ---
825
+
826
+ ## 6. `list_files` (列出文件)
827
+
828
+ **描述**: 列出指定目录中的文件和子目录
829
+
830
+ **MCP 调用格式**:
831
+ ```json
832
+ {
833
+ "name": "list_files",
834
+ "arguments": {
835
+ "path": "目录路径",
836
+ "recursive": true/false
837
+ }
838
+ }
839
+ ```
840
+
841
+ **参数 Schema**:
842
+ ```json
843
+ {
844
+ "type": "object",
845
+ "properties": {
846
+ "path": {
847
+ "type": "string",
848
+ "description": "要列出内容的目录路径"
849
+ },
850
+ "recursive": {
851
+ "type": "boolean",
852
+ "description": "是否递归列出子目录内容",
853
+ "default": false
854
+ }
855
+ },
856
+ "required": ["path"]
857
+ }
858
+ ```
859
+
860
+ **使用示例**:
861
+ ```json
862
+ {
863
+ "name": "list_files",
864
+ "arguments": {
865
+ "path": "src/main",
866
+ "recursive": false
867
+ }
868
+ }
869
+ ```
870
+
871
+ **返回值示例**:
872
+ ```json
873
+ {
874
+ "content": [
875
+ {
876
+ "type": "text",
877
+ "text": "directory: java\nfile: resources\nfile: webapp"
878
+ }
879
+ ]
880
+ }
881
+ ```
882
+
883
+ *递归列出文件:*
884
+ ```json
885
+ {
886
+ "name": "list_files",
887
+ "arguments": {
888
+ "path": "src",
889
+ "recursive": true
890
+ }
891
+ }
892
+ ```
893
+
894
+ **返回值示例**:
895
+ ```json
896
+ {
897
+ "content": [
898
+ {
899
+ "type": "text",
900
+ "text": "directory: main\ndirectory: main/java\nfile: main/java/App.java\nfile: main/java/Utils.java\ndirectory: main/resources\nfile: main/resources/config.properties\ndirectory: test\nfile: test/AppTest.java"
901
+ }
902
+ ]
903
+ }
904
+ ```
905
+
906
+ ---
907
+
908
+ ## 返回值格式
909
+
910
+ 所有工具的返回值都遵循 MCP 标准格式:
911
+
912
+ **成功响应格式**:
913
+ ```json
914
+ {
915
+ "content": [
916
+ {
917
+ "type": "text",
918
+ "text": "操作结果或文件内容"
919
+ }
920
+ ]
921
+ }
922
+ ```
923
+
924
+ **错误响应格式**:
925
+ ```json
926
+ {
927
+ "isError": true,
928
+ "content": [
929
+ {
930
+ "type": "text",
931
+ "text": "Error: 错误信息描述"
932
+ }
933
+ ]
934
+ }
935
+ ```
936
+
937
+ **常见错误示例**:
938
+
939
+ *文件不存在错误:*
940
+ ```json
941
+ {
942
+ "isError": true,
943
+ "content": [
944
+ {
945
+ "type": "text",
946
+ "text": "Error: File not found: nonexistent_file.txt"
947
+ }
948
+ ]
949
+ }
950
+ ```
951
+
952
+ *行号超出范围错误:*
953
+ ```json
954
+ {
955
+ "isError": true,
956
+ "content": [
957
+ {
958
+ "type": "text",
959
+ "text": "Error: Line number 50 exceeds file length (20 lines)"
960
+ }
961
+ ]
962
+ }
963
+ ```
964
+
965
+ *目录不存在错误:*
966
+ ```json
967
+ {
968
+ "isError": true,
969
+ "content": [
970
+ {
971
+ "type": "text",
972
+ "text": "Error: Directory not found: /nonexistent/path"
973
+ }
974
+ ]
975
+ }
976
+ ```