@j0hanz/filesystem-mcp 1.19.0 → 2.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.
Files changed (301) hide show
  1. package/README.md +333 -838
  2. package/dist/cli-help.d.ts +3 -0
  3. package/dist/cli-help.d.ts.map +1 -0
  4. package/dist/cli-help.js +169 -0
  5. package/dist/cli-help.js.map +1 -0
  6. package/dist/cli.d.ts +28 -0
  7. package/dist/cli.d.ts.map +1 -0
  8. package/dist/cli.js +168 -123
  9. package/dist/cli.js.map +1 -0
  10. package/dist/core/concurrency.d.ts +70 -0
  11. package/dist/core/concurrency.d.ts.map +1 -0
  12. package/dist/core/concurrency.js +173 -0
  13. package/dist/core/concurrency.js.map +1 -0
  14. package/dist/core/config.d.ts +19 -0
  15. package/dist/core/config.d.ts.map +1 -0
  16. package/dist/core/config.js +11 -0
  17. package/dist/core/config.js.map +1 -0
  18. package/dist/core/cursor.d.ts +23 -0
  19. package/dist/core/cursor.d.ts.map +1 -0
  20. package/dist/core/cursor.js +62 -0
  21. package/dist/core/cursor.js.map +1 -0
  22. package/dist/core/errors.d.ts +96 -0
  23. package/dist/core/errors.d.ts.map +1 -0
  24. package/dist/core/errors.js +356 -0
  25. package/dist/core/errors.js.map +1 -0
  26. package/dist/core/file-uri.d.ts +24 -0
  27. package/dist/core/file-uri.d.ts.map +1 -0
  28. package/dist/core/file-uri.js +52 -0
  29. package/dist/core/file-uri.js.map +1 -0
  30. package/dist/core/fmt.d.ts +38 -0
  31. package/dist/core/fmt.d.ts.map +1 -0
  32. package/dist/core/fmt.js +109 -0
  33. package/dist/core/fmt.js.map +1 -0
  34. package/dist/core/fs.d.ts +108 -0
  35. package/dist/core/fs.d.ts.map +1 -0
  36. package/dist/core/fs.js +243 -0
  37. package/dist/core/fs.js.map +1 -0
  38. package/dist/core/glob.d.ts +41 -0
  39. package/dist/core/glob.d.ts.map +1 -0
  40. package/dist/core/glob.js +399 -0
  41. package/dist/core/glob.js.map +1 -0
  42. package/dist/core/input-required.d.ts +147 -0
  43. package/dist/core/input-required.d.ts.map +1 -0
  44. package/dist/core/input-required.js +261 -0
  45. package/dist/core/input-required.js.map +1 -0
  46. package/dist/core/mime.d.ts +15 -0
  47. package/dist/core/mime.d.ts.map +1 -0
  48. package/dist/core/mime.js +188 -0
  49. package/dist/core/mime.js.map +1 -0
  50. package/dist/core/observability.d.ts +10 -0
  51. package/dist/core/observability.d.ts.map +1 -0
  52. package/dist/core/observability.js +76 -0
  53. package/dist/core/observability.js.map +1 -0
  54. package/dist/core/page-store.d.ts +41 -0
  55. package/dist/core/page-store.d.ts.map +1 -0
  56. package/dist/core/page-store.js +74 -0
  57. package/dist/core/page-store.js.map +1 -0
  58. package/dist/core/path-completer.d.ts +10 -0
  59. package/dist/core/path-completer.d.ts.map +1 -0
  60. package/dist/core/path-completer.js +227 -0
  61. package/dist/core/path-completer.js.map +1 -0
  62. package/dist/core/path-discovery.d.ts +8 -0
  63. package/dist/core/path-discovery.d.ts.map +1 -0
  64. package/dist/core/path-discovery.js +105 -0
  65. package/dist/core/path-discovery.js.map +1 -0
  66. package/dist/core/path-utils.d.ts +9 -0
  67. package/dist/core/path-utils.d.ts.map +1 -0
  68. package/dist/core/path-utils.js +121 -0
  69. package/dist/core/path-utils.js.map +1 -0
  70. package/dist/core/path.d.ts +148 -0
  71. package/dist/core/path.d.ts.map +1 -0
  72. package/dist/core/path.js +674 -0
  73. package/dist/core/path.js.map +1 -0
  74. package/dist/core/primitives.d.ts +23 -0
  75. package/dist/core/primitives.d.ts.map +1 -0
  76. package/dist/core/primitives.js +54 -0
  77. package/dist/core/primitives.js.map +1 -0
  78. package/dist/core/read.d.ts +74 -0
  79. package/dist/core/read.d.ts.map +1 -0
  80. package/dist/core/read.js +562 -0
  81. package/dist/core/read.js.map +1 -0
  82. package/dist/core/schema.d.ts +139 -0
  83. package/dist/core/schema.d.ts.map +1 -0
  84. package/dist/core/schema.js +345 -0
  85. package/dist/core/schema.js.map +1 -0
  86. package/dist/core/search.d.ts +100 -0
  87. package/dist/core/search.d.ts.map +1 -0
  88. package/dist/core/search.js +248 -0
  89. package/dist/core/search.js.map +1 -0
  90. package/dist/core/sensitive.d.ts +6 -0
  91. package/dist/core/sensitive.d.ts.map +1 -0
  92. package/dist/core/sensitive.js +142 -0
  93. package/dist/core/sensitive.js.map +1 -0
  94. package/dist/core/store.d.ts +57 -0
  95. package/dist/core/store.d.ts.map +1 -0
  96. package/dist/core/store.js +162 -0
  97. package/dist/core/store.js.map +1 -0
  98. package/dist/core/util.d.ts +26 -0
  99. package/dist/core/util.d.ts.map +1 -0
  100. package/dist/core/util.js +66 -0
  101. package/dist/core/util.js.map +1 -0
  102. package/dist/core/watcher-registry.d.ts +68 -0
  103. package/dist/core/watcher-registry.d.ts.map +1 -0
  104. package/dist/core/watcher-registry.js +312 -0
  105. package/dist/core/watcher-registry.js.map +1 -0
  106. package/dist/http-policy.d.ts +121 -0
  107. package/dist/http-policy.d.ts.map +1 -0
  108. package/dist/http-policy.js +340 -0
  109. package/dist/http-policy.js.map +1 -0
  110. package/dist/index.d.ts +1 -0
  111. package/dist/index.d.ts.map +1 -0
  112. package/dist/index.js +77 -41
  113. package/dist/index.js.map +1 -0
  114. package/dist/instructions.d.ts +12 -0
  115. package/dist/instructions.d.ts.map +1 -0
  116. package/dist/instructions.js +71 -0
  117. package/dist/instructions.js.map +1 -0
  118. package/dist/prompts.d.ts +8 -6
  119. package/dist/prompts.d.ts.map +1 -0
  120. package/dist/prompts.js +74 -168
  121. package/dist/prompts.js.map +1 -0
  122. package/dist/resources.d.ts +73 -9
  123. package/dist/resources.d.ts.map +1 -0
  124. package/dist/resources.js +392 -163
  125. package/dist/resources.js.map +1 -0
  126. package/dist/server.d.ts +62 -1
  127. package/dist/server.d.ts.map +1 -0
  128. package/dist/server.js +139 -1
  129. package/dist/server.js.map +1 -0
  130. package/dist/tools/batch.d.ts +89 -0
  131. package/dist/tools/batch.d.ts.map +1 -0
  132. package/dist/tools/batch.js +157 -0
  133. package/dist/tools/batch.js.map +1 -0
  134. package/dist/tools/create.d.ts +2 -0
  135. package/dist/tools/create.d.ts.map +1 -0
  136. package/dist/tools/create.js +142 -0
  137. package/dist/tools/create.js.map +1 -0
  138. package/dist/tools/define.d.ts +110 -0
  139. package/dist/tools/define.d.ts.map +1 -0
  140. package/dist/tools/define.js +394 -0
  141. package/dist/tools/define.js.map +1 -0
  142. package/dist/tools/delete-file.d.ts +2 -4
  143. package/dist/tools/delete-file.d.ts.map +1 -0
  144. package/dist/tools/delete-file.js +330 -87
  145. package/dist/tools/delete-file.js.map +1 -0
  146. package/dist/tools/diff.d.ts +2 -0
  147. package/dist/tools/diff.d.ts.map +1 -0
  148. package/dist/tools/diff.js +94 -0
  149. package/dist/tools/diff.js.map +1 -0
  150. package/dist/tools/edit.d.ts +2 -0
  151. package/dist/tools/edit.d.ts.map +1 -0
  152. package/dist/tools/edit.js +442 -0
  153. package/dist/tools/edit.js.map +1 -0
  154. package/dist/tools/index.d.ts +26 -0
  155. package/dist/tools/index.d.ts.map +1 -0
  156. package/dist/tools/index.js +52 -0
  157. package/dist/tools/index.js.map +1 -0
  158. package/dist/tools/list.d.ts +2 -0
  159. package/dist/tools/list.d.ts.map +1 -0
  160. package/dist/tools/list.js +291 -0
  161. package/dist/tools/list.js.map +1 -0
  162. package/dist/tools/move.d.ts +2 -0
  163. package/dist/tools/move.d.ts.map +1 -0
  164. package/dist/tools/move.js +321 -0
  165. package/dist/tools/move.js.map +1 -0
  166. package/dist/tools/patch.d.ts +2 -0
  167. package/dist/tools/patch.d.ts.map +1 -0
  168. package/dist/tools/patch.js +155 -0
  169. package/dist/tools/patch.js.map +1 -0
  170. package/dist/tools/progress.d.ts +52 -0
  171. package/dist/tools/progress.d.ts.map +1 -0
  172. package/dist/tools/progress.js +172 -0
  173. package/dist/tools/progress.js.map +1 -0
  174. package/dist/tools/read.d.ts +2 -4
  175. package/dist/tools/read.d.ts.map +1 -0
  176. package/dist/tools/read.js +398 -152
  177. package/dist/tools/read.js.map +1 -0
  178. package/dist/tools/replace-in-files.d.ts +2 -4
  179. package/dist/tools/replace-in-files.d.ts.map +1 -0
  180. package/dist/tools/replace-in-files.js +435 -264
  181. package/dist/tools/replace-in-files.js.map +1 -0
  182. package/dist/tools/roots.d.ts +2 -4
  183. package/dist/tools/roots.d.ts.map +1 -0
  184. package/dist/tools/roots.js +29 -52
  185. package/dist/tools/roots.js.map +1 -0
  186. package/dist/tools/search-content.d.ts +2 -4
  187. package/dist/tools/search-content.d.ts.map +1 -0
  188. package/dist/tools/search-content.js +262 -228
  189. package/dist/tools/search-content.js.map +1 -0
  190. package/dist/tools/search-files.d.ts +2 -4
  191. package/dist/tools/search-files.d.ts.map +1 -0
  192. package/dist/tools/search-files.js +162 -161
  193. package/dist/tools/search-files.js.map +1 -0
  194. package/dist/tools/stat.d.ts +2 -4
  195. package/dist/tools/stat.d.ts.map +1 -0
  196. package/dist/tools/stat.js +202 -62
  197. package/dist/tools/stat.js.map +1 -0
  198. package/dist/transport/http.d.ts +5 -0
  199. package/dist/transport/http.d.ts.map +1 -0
  200. package/dist/transport/http.js +276 -0
  201. package/dist/transport/http.js.map +1 -0
  202. package/dist/transport/shared.d.ts +45 -0
  203. package/dist/transport/shared.d.ts.map +1 -0
  204. package/dist/transport/shared.js +65 -0
  205. package/dist/transport/shared.js.map +1 -0
  206. package/dist/transport/stdio.d.ts +32 -0
  207. package/dist/transport/stdio.d.ts.map +1 -0
  208. package/dist/transport/stdio.js +279 -0
  209. package/dist/transport/stdio.js.map +1 -0
  210. package/dist/transport.d.ts +5 -0
  211. package/dist/transport.d.ts.map +1 -0
  212. package/dist/transport.js +4 -0
  213. package/dist/transport.js.map +1 -0
  214. package/package.json +37 -46
  215. package/dist/assets/logo.svg +0 -35
  216. package/dist/completions.d.ts +0 -2
  217. package/dist/completions.js +0 -572
  218. package/dist/config.d.ts +0 -119
  219. package/dist/config.js +0 -31
  220. package/dist/lib/abort.d.ts +0 -7
  221. package/dist/lib/abort.js +0 -81
  222. package/dist/lib/constants.d.ts +0 -42
  223. package/dist/lib/constants.js +0 -313
  224. package/dist/lib/errors.d.ts +0 -28
  225. package/dist/lib/errors.js +0 -301
  226. package/dist/lib/file-operations/core.d.ts +0 -53
  227. package/dist/lib/file-operations/core.js +0 -144
  228. package/dist/lib/file-operations/metadata.d.ts +0 -77
  229. package/dist/lib/file-operations/metadata.js +0 -878
  230. package/dist/lib/file-operations/search.d.ts +0 -46
  231. package/dist/lib/file-operations/search.js +0 -1194
  232. package/dist/lib/file-operations/traversal.d.ts +0 -40
  233. package/dist/lib/file-operations/traversal.js +0 -310
  234. package/dist/lib/fs-helpers.d.ts +0 -46
  235. package/dist/lib/fs-helpers.js +0 -606
  236. package/dist/lib/globs.d.ts +0 -2
  237. package/dist/lib/globs.js +0 -19
  238. package/dist/lib/logger.d.ts +0 -27
  239. package/dist/lib/logger.js +0 -91
  240. package/dist/lib/observability.d.ts +0 -33
  241. package/dist/lib/observability.js +0 -373
  242. package/dist/lib/paths.d.ts +0 -35
  243. package/dist/lib/paths.js +0 -634
  244. package/dist/lib/resource-store.d.ts +0 -28
  245. package/dist/lib/resource-store.js +0 -195
  246. package/dist/lib/utils.d.ts +0 -7
  247. package/dist/lib/utils.js +0 -37
  248. package/dist/lib/zod-codecs.d.ts +0 -2
  249. package/dist/lib/zod-codecs.js +0 -18
  250. package/dist/pkg-info.d.ts +0 -7
  251. package/dist/pkg-info.js +0 -9
  252. package/dist/resources/generated-instructions.d.ts +0 -1
  253. package/dist/resources/generated-instructions.js +0 -105
  254. package/dist/resources/tool-catalog.d.ts +0 -2
  255. package/dist/resources/tool-catalog.js +0 -78
  256. package/dist/resources/tool-info.d.ts +0 -9
  257. package/dist/resources/tool-info.js +0 -206
  258. package/dist/resources/workflows.d.ts +0 -1
  259. package/dist/resources/workflows.js +0 -72
  260. package/dist/schemas.d.ts +0 -505
  261. package/dist/schemas.js +0 -676
  262. package/dist/server/bootstrap.d.ts +0 -6
  263. package/dist/server/bootstrap.js +0 -563
  264. package/dist/server/event-store.d.ts +0 -18
  265. package/dist/server/event-store.js +0 -71
  266. package/dist/server/roots-manager.d.ts +0 -28
  267. package/dist/server/roots-manager.js +0 -227
  268. package/dist/server/task-store.d.ts +0 -10
  269. package/dist/server/task-store.js +0 -91
  270. package/dist/tools/apply-patch.d.ts +0 -4
  271. package/dist/tools/apply-patch.js +0 -235
  272. package/dist/tools/calculate-hash.d.ts +0 -4
  273. package/dist/tools/calculate-hash.js +0 -187
  274. package/dist/tools/contract.d.ts +0 -50
  275. package/dist/tools/contract.js +0 -1
  276. package/dist/tools/create-directory.d.ts +0 -4
  277. package/dist/tools/create-directory.js +0 -68
  278. package/dist/tools/diff-files.d.ts +0 -4
  279. package/dist/tools/diff-files.js +0 -136
  280. package/dist/tools/edit-file.d.ts +0 -4
  281. package/dist/tools/edit-file.js +0 -256
  282. package/dist/tools/icons.d.ts +0 -15
  283. package/dist/tools/icons.js +0 -24
  284. package/dist/tools/list-directory.d.ts +0 -4
  285. package/dist/tools/list-directory.js +0 -218
  286. package/dist/tools/move-file.d.ts +0 -4
  287. package/dist/tools/move-file.js +0 -178
  288. package/dist/tools/read-multiple.d.ts +0 -4
  289. package/dist/tools/read-multiple.js +0 -207
  290. package/dist/tools/shared.d.ts +0 -172
  291. package/dist/tools/shared.js +0 -599
  292. package/dist/tools/stat-many.d.ts +0 -4
  293. package/dist/tools/stat-many.js +0 -104
  294. package/dist/tools/task-support.d.ts +0 -29
  295. package/dist/tools/task-support.js +0 -472
  296. package/dist/tools/tree.d.ts +0 -4
  297. package/dist/tools/tree.js +0 -102
  298. package/dist/tools/write-file.d.ts +0 -4
  299. package/dist/tools/write-file.js +0 -60
  300. package/dist/tools.d.ts +0 -5
  301. package/dist/tools.js +0 -54
@@ -0,0 +1,442 @@
1
+ import { basename } from 'node:path';
2
+ import * as z from 'zod/v4';
3
+ import { createTwoFilesPatch, diffLines } from 'diff';
4
+ import { ErrorCode, FsError } from '../core/errors.js';
5
+ import { buildFileResourceLink, buildFileResourceUri } from '../core/file-uri.js';
6
+ import { detectMimeFromContent } from '../core/mime.js';
7
+ import { escapeRegexLiteral } from '../core/primitives.js';
8
+ import { countLines } from '../core/read.js';
9
+ import { defaultFalseBoolean, FileKind, isBlank, IsoDateTime, NonNegInt, OperationSummarySchema, PerFileErrorSchema, PositiveInt, RequiredPath, singleOrBatchAccessPaths, } from '../core/schema.js';
10
+ import { compileRegex, freeRegex } from '../core/search.js';
11
+ import { runOverPaths } from './batch.js';
12
+ import { defineTool } from './define.js';
13
+ const EditSpecSchema = z
14
+ .strictObject({
15
+ oldText: z
16
+ .string()
17
+ .min(1, 'oldText required')
18
+ .refine((val) => !isBlank(val), {
19
+ message: 'oldText cannot be empty or whitespace-only',
20
+ })
21
+ .describe('Exact literal text to locate in the file. Must include 3-5 lines of context to ensure uniqueness and avoid matching the wrong block.')
22
+ .meta({ examples: ['const x = 1;', 'function oldName('] }),
23
+ newText: z
24
+ .string()
25
+ .describe('Replacement text. Use an empty string to delete the matched oldText.')
26
+ .meta({ examples: ['const x = 2;', 'function newName(', ''] }),
27
+ })
28
+ // The one document in this server where a `$ref` pays: this subschema is used
29
+ // at both `edits` and `files[].edits`, so an `id` hoists it into `$defs` once
30
+ // instead of inlining ~1.3 kB twice. Shared schemas used once per document
31
+ // deliberately carry no `id` — there a `$ref` costs more than it saves.
32
+ .meta({ id: 'EditSpec' });
33
+ const MAX_MULTI_FILES = 5;
34
+ const MAX_EDITS_PER_FILE = 100;
35
+ const EditFileInputSchema = z
36
+ .strictObject({
37
+ path: RequiredPath.optional().describe('Single file path; mutually exclusive with files'),
38
+ edits: z
39
+ .array(EditSpecSchema)
40
+ .min(1)
41
+ .max(MAX_EDITS_PER_FILE)
42
+ .optional()
43
+ .describe('Replacements applied to path; not allowed when using files'),
44
+ files: z
45
+ .array(z.strictObject({
46
+ path: RequiredPath,
47
+ edits: z
48
+ .array(EditSpecSchema)
49
+ .min(1)
50
+ .max(MAX_EDITS_PER_FILE)
51
+ .describe('Replacements to apply to this specific file'),
52
+ }))
53
+ .min(1)
54
+ .max(MAX_MULTI_FILES)
55
+ .optional()
56
+ .describe('Per-file entries (batch mode)'),
57
+ dryRun: defaultFalseBoolean('Preview diffs without writing to disk (default: false = apply edits)'),
58
+ ignoreWhitespace: defaultFalseBoolean('Ignore leading/trailing whitespace differences when matching oldText'),
59
+ })
60
+ .superRefine((value, ctx) => {
61
+ const hasPath = value.path !== undefined;
62
+ const hasFiles = value.files !== undefined;
63
+ if (hasPath === hasFiles) {
64
+ ctx.addIssue({
65
+ code: 'custom',
66
+ path: ['path'],
67
+ message: "Provide exactly one of 'path' or 'files'",
68
+ input: value,
69
+ });
70
+ }
71
+ if (hasPath && value.edits === undefined) {
72
+ ctx.addIssue({
73
+ code: 'custom',
74
+ path: ['edits'],
75
+ message: "'edits' required when using 'path'",
76
+ input: value,
77
+ });
78
+ }
79
+ if (hasFiles && value.edits !== undefined) {
80
+ ctx.addIssue({
81
+ code: 'custom',
82
+ path: ['edits'],
83
+ message: "'edits' not allowed with 'files'; each file carries its own edits",
84
+ input: value,
85
+ });
86
+ }
87
+ })
88
+ // Mirror the superRefine on the wire: exactly one input mode, and single-file
89
+ // mode carries its own `edits`. Without `edits` in the first branch, `{ path }`
90
+ // alone validated against the published schema and was then rejected at
91
+ // runtime — the model had no way to see that coming.
92
+ .meta({ oneOf: [{ required: ['path', 'edits'] }, { required: ['files'] }] });
93
+ const PerFileResultSchema = z.strictObject({
94
+ path: z.string().describe('Resolved absolute path of the edited file'),
95
+ size: NonNegInt.describe('File size in bytes after edits'),
96
+ lineCount: NonNegInt.describe('Number of lines in the file after edits'),
97
+ mimeType: z.string().describe('Detected MIME type of the file'),
98
+ kind: FileKind.describe('Broad file kind: text, binary, image, audio, or pdf'),
99
+ resourceUri: z
100
+ .string()
101
+ .optional()
102
+ .describe('Resource URI pointing to the updated file content; omitted when no edit matched (appliedEdits is 0) and the file was left untouched'),
103
+ modified: IsoDateTime.describe('Last modification timestamp after edits (ISO 8601 UTC)'),
104
+ appliedEdits: NonNegInt.describe('Number of edits successfully applied'),
105
+ linesAdded: NonNegInt.optional().describe('Net lines added by all applied edits'),
106
+ linesRemoved: NonNegInt.optional().describe('Net lines removed by all applied edits'),
107
+ diff: z.string().optional().describe('Unified diff of all changes (present only in dryRun mode)'),
108
+ unmatchedEdits: z
109
+ .array(z.string())
110
+ .optional()
111
+ .describe('oldText values that did not match any content in the file'),
112
+ lineRange: z
113
+ .tuple([PositiveInt, PositiveInt])
114
+ .optional()
115
+ .describe('Line range [firstLine, lastLine] covering all applied edits'),
116
+ });
117
+ const EditPerPathSchema = z.strictObject({
118
+ path: z.string().describe('Requested file path'),
119
+ value: PerFileResultSchema.optional().describe('Edit result; present on success'),
120
+ error: PerFileErrorSchema.optional().describe('Error details; present on failure'),
121
+ });
122
+ const EditFileOutputSchema = z.strictObject({
123
+ results: z
124
+ .array(EditPerPathSchema)
125
+ .describe('Per-path edit results ordered to match the input paths'),
126
+ summary: OperationSummarySchema,
127
+ });
128
+ async function computeDiffStats(original, modified) {
129
+ return new Promise((resolve) => {
130
+ // Yield to the event loop so we don't completely block
131
+ setImmediate(() => {
132
+ diffLines(original, modified, {
133
+ callback: (changes) => {
134
+ let linesAdded = 0;
135
+ let linesRemoved = 0;
136
+ for (const part of changes) {
137
+ if (part.added)
138
+ linesAdded += part.count;
139
+ else if (part.removed)
140
+ linesRemoved += part.count;
141
+ }
142
+ resolve({ linesAdded, linesRemoved });
143
+ },
144
+ });
145
+ });
146
+ });
147
+ }
148
+ function findEditMatch(content, oldText, ignoreWhitespace, regexCache) {
149
+ if (ignoreWhitespace) {
150
+ // Make whitespace flexible (tolerate indentation/spacing differences)
151
+ // without letting it cross line boundaries: a whitespace run that contains
152
+ // a newline keeps at least one newline, so a single-line oldText cannot
153
+ // match across a newline and a multi-line oldText cannot collapse onto one
154
+ // line. Horizontal whitespace stays mandatory between word characters so
155
+ // adjacent identifiers are not merged.
156
+ const pattern = escapeRegexLiteral(oldText)
157
+ .replace(/[^\S\n]*\n\s*/g, '[^\\S\\n]*\\n+[^\\S\\n]*')
158
+ .replace(/(\w)[^\S\n]+(\w)/g, '$1[^\\S\\n]+$2')
159
+ .replace(/[^\S\n]+/g, '[^\\S\\n]*');
160
+ let regex = regexCache?.get(pattern);
161
+ if (!regex) {
162
+ regex = compileRegex(pattern, { caseSensitive: true });
163
+ regexCache?.set(pattern, regex);
164
+ }
165
+ // The compiled regex is global and may come from the cache, so lastIndex
166
+ // still points past the previous edit's match — reset before searching.
167
+ regex.lastIndex = 0;
168
+ const match = regex.exec(content);
169
+ if (match === null)
170
+ return undefined;
171
+ // RE2ExecArray types group 0 as optional. A successful match always has it;
172
+ // an empty one would name a zero-length span, which cannot be replaced.
173
+ const matched = match[0];
174
+ if (matched === undefined || matched.length === 0)
175
+ return undefined;
176
+ return {
177
+ startIndex: match.index,
178
+ length: matched.length,
179
+ };
180
+ }
181
+ const index = content.indexOf(oldText);
182
+ if (index === -1) {
183
+ return undefined;
184
+ }
185
+ return {
186
+ startIndex: index,
187
+ length: oldText.length,
188
+ };
189
+ }
190
+ function replaceEditMatch(content, match, newText) {
191
+ return (content.slice(0, match.startIndex) + newText + content.slice(match.startIndex + match.length));
192
+ }
193
+ /**
194
+ * Compute the 1-indexed line range of changed lines in `modified` relative to
195
+ * `original`, using a common-prefix/suffix line scan. This is a conservative
196
+ * bound (it widens to cover independent changes between matching bookends), but
197
+ * it is computed against the FINAL content so it is not skewed by earlier edits
198
+ * inserting or removing lines — which the per-edit merge could not account for.
199
+ */
200
+ function computeChangedLineRange(original, modified) {
201
+ const origLines = original.split('\n');
202
+ const modLines = modified.split('\n');
203
+ const minLen = Math.min(origLines.length, modLines.length);
204
+ let firstChanged = -1;
205
+ for (let i = 0; i < minLen; i++) {
206
+ if (origLines[i] !== modLines[i]) {
207
+ firstChanged = i;
208
+ break;
209
+ }
210
+ }
211
+ if (firstChanged === -1 && origLines.length === modLines.length)
212
+ return undefined;
213
+ if (firstChanged === -1)
214
+ firstChanged = minLen; // pure append/trim at the tail
215
+ let lastChangedMod = modLines.length - 1;
216
+ let lastChangedOrig = origLines.length - 1;
217
+ while (lastChangedMod > firstChanged &&
218
+ lastChangedOrig >= 0 &&
219
+ modLines[lastChangedMod] === origLines[lastChangedOrig]) {
220
+ lastChangedMod--;
221
+ lastChangedOrig--;
222
+ }
223
+ // When the modified content is a strict prefix of the original (a tail trim on
224
+ // a file with no final newline), the loop above never runs and lastChangedMod
225
+ // lands one below firstChanged. Clamp so the range is never inverted.
226
+ return [firstChanged + 1, Math.max(firstChanged, lastChangedMod) + 1];
227
+ }
228
+ function buildEditFileValue(validPath, meta, modified, result) {
229
+ return {
230
+ path: validPath,
231
+ size: meta.bytesWritten,
232
+ lineCount: meta.lineCount,
233
+ mimeType: meta.mimeType,
234
+ kind: meta.kind,
235
+ ...(meta.resourceUri !== undefined ? { resourceUri: meta.resourceUri } : {}),
236
+ modified,
237
+ appliedEdits: result.appliedEdits,
238
+ ...(result.appliedEdits > 0
239
+ ? { linesAdded: result.linesAdded, linesRemoved: result.linesRemoved }
240
+ : {}),
241
+ ...(result.unmatchedEdits.length > 0 ? { unmatchedEdits: result.unmatchedEdits } : {}),
242
+ ...(result.diff ? { diff: result.diff } : {}),
243
+ ...(result.lineRange ? { lineRange: result.lineRange } : {}),
244
+ };
245
+ }
246
+ async function finalizeEditResult(originalContent, updatedContent, appliedEdits, unmatchedEdits, lineRange) {
247
+ const { linesAdded, linesRemoved } = appliedEdits > 0
248
+ ? await computeDiffStats(originalContent, updatedContent)
249
+ : { linesAdded: 0, linesRemoved: 0 };
250
+ return {
251
+ content: updatedContent,
252
+ appliedEdits,
253
+ unmatchedEdits,
254
+ linesAdded,
255
+ linesRemoved,
256
+ ...(lineRange ? { lineRange } : {}),
257
+ };
258
+ }
259
+ function buildEditFileMetadata(content, validPath, appliedEdits, resourceStore) {
260
+ const bytesWritten = Buffer.byteLength(content, 'utf-8');
261
+ const lineCount = countLines(content);
262
+ const mimeInfo = detectMimeFromContent(validPath, content);
263
+ // Omitted rather than empty-stringed when nothing matched: `""` satisfied the
264
+ // schema's `string` and then failed every resources/read a client tried it on.
265
+ const resourceUri = appliedEdits > 0 ? buildFileResourceUri(validPath) : undefined;
266
+ const resourceLink = appliedEdits > 0 && resourceStore
267
+ ? buildFileResourceLink(validPath, mimeInfo.mimeType, bytesWritten)
268
+ : undefined;
269
+ return {
270
+ bytesWritten,
271
+ lineCount,
272
+ mimeType: mimeInfo.mimeType,
273
+ kind: mimeInfo.kind,
274
+ resourceUri,
275
+ resourceLink,
276
+ };
277
+ }
278
+ async function applyEdits(content, edits, ignoreWhitespace) {
279
+ let newContent = content;
280
+ let appliedEdits = 0;
281
+ const unmatchedEdits = [];
282
+ const regexCache = ignoreWhitespace ? new Map() : undefined;
283
+ try {
284
+ for (const edit of edits) {
285
+ const match = findEditMatch(newContent, edit.oldText, ignoreWhitespace, regexCache);
286
+ if (!match) {
287
+ unmatchedEdits.push(edit.oldText);
288
+ continue;
289
+ }
290
+ newContent = replaceEditMatch(newContent, match, edit.newText);
291
+ appliedEdits += 1;
292
+ }
293
+ }
294
+ finally {
295
+ // Every cached pattern owns wasm memory re2-wasm never reclaims on its own,
296
+ // and the cache does not outlive this call.
297
+ for (const cached of regexCache?.values() ?? [])
298
+ freeRegex(cached);
299
+ regexCache?.clear();
300
+ }
301
+ // Compute the line range against the final content so earlier edits whose
302
+ // lines were shifted by later edits are still covered.
303
+ const lineRange = appliedEdits > 0 ? computeChangedLineRange(content, newContent) : undefined;
304
+ return finalizeEditResult(content, newContent, appliedEdits, unmatchedEdits, lineRange);
305
+ }
306
+ async function handleEditFile(filePath, edits, options, ctx) {
307
+ const { validPath, content } = await ctx.fs.readEditableText(filePath, {
308
+ signal: ctx.signal,
309
+ });
310
+ const editResult = await applyEdits(content, edits, options.ignoreWhitespace);
311
+ if (options.dryRun) {
312
+ if (editResult.appliedEdits > 0) {
313
+ const label = basename(validPath);
314
+ editResult.diff = await new Promise((resolve) => {
315
+ createTwoFilesPatch(label, label, content, editResult.content, 'Original', 'Modified', {
316
+ callback: (res) => {
317
+ resolve(res ?? '');
318
+ },
319
+ });
320
+ });
321
+ }
322
+ // Nothing was written, so there is no updated content to point a
323
+ // resourceUri or a resource_link at — the file on disk is still the one the
324
+ // caller already has. Same rule the appliedEdits-is-0 case follows: no
325
+ // write, no link.
326
+ const meta = buildEditFileMetadata(editResult.content, validPath, 0, ctx.resourceStore);
327
+ return {
328
+ file: buildEditFileValue(validPath, meta, new Date().toISOString(), editResult),
329
+ ...(meta.resourceLink ? { resourceLink: meta.resourceLink } : {}),
330
+ };
331
+ }
332
+ if (editResult.unmatchedEdits.length > 0) {
333
+ throw new FsError(ErrorCode.INVALID_INPUT, `${editResult.unmatchedEdits.length} edit(s) failed to match. Verify oldText matches exact file content.`, filePath);
334
+ }
335
+ if (editResult.appliedEdits > 0) {
336
+ await ctx.fs.writeFile(filePath, editResult.content, {
337
+ encoding: 'utf-8',
338
+ signal: ctx.signal,
339
+ });
340
+ ctx.log?.('info', `edit: ${filePath} (${editResult.appliedEdits} edits, +${editResult.linesAdded}/-${editResult.linesRemoved})`, 'edit');
341
+ }
342
+ // `modified` is read from a post-write stat and is advisory: under a concurrent
343
+ // writer it may reflect that writer's mtime while `size`/content below come from
344
+ // this edit's atomic write. The file content itself is always consistent.
345
+ const { stats: fileStats } = await ctx.fs.stat(filePath, { signal: ctx.signal });
346
+ const meta = buildEditFileMetadata(editResult.content, validPath, editResult.appliedEdits, ctx.resourceStore);
347
+ return {
348
+ file: buildEditFileValue(validPath, meta, fileStats.mtime.toISOString(), editResult),
349
+ ...(meta.resourceLink ? { resourceLink: meta.resourceLink } : {}),
350
+ };
351
+ }
352
+ function formatEditSummary(results, dryRun) {
353
+ const tag = dryRun ? ' [dry run]' : '';
354
+ // Single-file failure: say why here rather than making the caller read
355
+ // structuredContent for the one message that can apply.
356
+ const [only] = results;
357
+ if (results.length === 1 && only?.error) {
358
+ return `edit: ${only.path} FAILED — ${only.error.message}${tag}`;
359
+ }
360
+ const tokens = results.map((r) => {
361
+ if (r.error)
362
+ return `${basename(r.path)} FAILED`;
363
+ const v = r.value;
364
+ if (!v)
365
+ return `${basename(r.path)} (no result)`;
366
+ if (v.unmatchedEdits && v.unmatchedEdits.length > 0)
367
+ return `${basename(v.path)} NO MATCH`;
368
+ const added = v.linesAdded ?? 0;
369
+ const removed = v.linesRemoved ?? 0;
370
+ if (added === 0 && removed === 0)
371
+ return `${basename(v.path)} (no change)`;
372
+ return `${basename(v.path)} +${String(added)} -${String(removed)}`;
373
+ });
374
+ const failed = results.filter((r) => r.error !== undefined).length;
375
+ const ok = results.length - failed;
376
+ const ratio = failed > 0 ? ` (${String(ok)}/${String(results.length)} ok)` : '';
377
+ return `edit: ${tokens.join(' · ')}${ratio}${tag}`;
378
+ }
379
+ export const EDIT = defineTool({
380
+ name: 'edit',
381
+ title: 'Edit Files',
382
+ description: 'Apply sequential literal string replacements to one or more files (max 5 files per call). ' +
383
+ 'Modes: single-file { path, edits } or per-file { files: [{ path, edits }] }. ' +
384
+ 'oldText must match file content exactly; include 3-5 lines of surrounding context to ensure uniqueness. ' +
385
+ 'Set dryRun=true to preview diffs without writing. ' +
386
+ 'For glob-based bulk regex replacement across many files, use replace_text instead.',
387
+ input: EditFileInputSchema,
388
+ output: EditFileOutputSchema,
389
+ // Same per-path union as read, plus diff, which is present only under dryRun.
390
+ publishOutputSchema: true,
391
+ annotations: {
392
+ readOnlyHint: false,
393
+ idempotentHint: false,
394
+ destructiveHint: true,
395
+ openWorldHint: false,
396
+ },
397
+ progress: (args) => {
398
+ const dryLabel = args.dryRun ? ' [dry run]' : '';
399
+ let subject;
400
+ if (args.path !== undefined) {
401
+ subject = basename(args.path);
402
+ }
403
+ else if (args.files !== undefined) {
404
+ subject = `${args.files.length} files`;
405
+ }
406
+ else {
407
+ subject = 'files';
408
+ }
409
+ return { label: `Edit${dryLabel}`, subject };
410
+ },
411
+ accessPaths: singleOrBatchAccessPaths,
412
+ run: async (args, ctx) => {
413
+ const sharedEdits = args.edits ?? [];
414
+ const batchInput = args.path !== undefined ? { path: args.path } : { files: args.files ?? [] };
415
+ const options = {
416
+ dryRun: args.dryRun,
417
+ ignoreWhitespace: args.ignoreWhitespace,
418
+ };
419
+ const batch = await runOverPaths(batchInput, ctx, ({ path, override }) => handleEditFile(path, override?.edits ?? sharedEdits, options, ctx), { defaultErrorCode: ErrorCode.UNKNOWN });
420
+ const perPathResults = [];
421
+ const resourceLinks = [];
422
+ for (const r of batch.results) {
423
+ if ('error' in r) {
424
+ perPathResults.push({ path: r.path, error: r.error });
425
+ continue;
426
+ }
427
+ perPathResults.push({ path: r.path, value: r.value.file });
428
+ if (r.value.resourceLink)
429
+ resourceLinks.push(r.value.resourceLink);
430
+ }
431
+ const summaryText = formatEditSummary(perPathResults, args.dryRun);
432
+ return {
433
+ structured: {
434
+ results: perPathResults,
435
+ summary: batch.summary,
436
+ },
437
+ text: summaryText,
438
+ ...(resourceLinks.length > 0 ? { resources: resourceLinks } : {}),
439
+ };
440
+ },
441
+ });
442
+ //# sourceMappingURL=edit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"edit.js","sourceRoot":"","sources":["../../src/tools/edit.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAEtD,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAClF,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,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,CAAC,cAAc,CAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,IAAI,WAAW,EAAE,OAAO,EAAE,GAAG,CAAC,EAC1F,EAAE,gBAAgB,EAAE,SAAS,CAAC,OAAO,EAAE,CACxC,CAAC;QAEF,MAAM,cAAc,GAAwC,EAAE,CAAC;QAC/D,MAAM,aAAa,GAAmB,EAAE,CAAC;QACzC,KAAK,MAAM,CAAC,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC;YAC9B,IAAI,OAAO,IAAI,CAAC,EAAE,CAAC;gBACjB,cAAc,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;gBACtD,SAAS;YACX,CAAC;YACD,cAAc,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;YAC3D,IAAI,CAAC,CAAC,KAAK,CAAC,YAAY;gBAAE,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;QACrE,CAAC;QAED,MAAM,WAAW,GAAG,iBAAiB,CAAC,cAAc,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QAEnE,OAAO;YACL,UAAU,EAAE;gBACV,OAAO,EAAE,cAAc;gBACvB,OAAO,EAAE,KAAK,CAAC,OAAO;aACvB;YACD,IAAI,EAAE,WAAW;YACjB,GAAG,CAAC,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,aAAa,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAClE,CAAC;IACJ,CAAC;CACF,CAAC,CAAC","sourcesContent":["import type { ContentBlock } from '@modelcontextprotocol/server';\n\nimport { basename } from 'node:path';\n\nimport * as z from 'zod/v4';\nimport { createTwoFilesPatch, diffLines } from 'diff';\n\nimport { ErrorCode, FsError } from '../core/errors.js';\nimport { buildFileResourceLink, buildFileResourceUri } from '../core/file-uri.js';\nimport { detectMimeFromContent } from '../core/mime.js';\nimport { escapeRegexLiteral } from '../core/primitives.js';\nimport { countLines } from '../core/read.js';\nimport {\n defaultFalseBoolean,\n FileKind,\n isBlank,\n IsoDateTime,\n NonNegInt,\n OperationSummarySchema,\n PerFileErrorSchema,\n PositiveInt,\n RequiredPath,\n singleOrBatchAccessPaths,\n} from '../core/schema.js';\nimport type { Regex } from '../core/search.js';\nimport { compileRegex, freeRegex } from '../core/search.js';\nimport type { ResourceStore } from '../core/store.js';\nimport { runOverPaths } from './batch.js';\nimport { defineTool, type ToolCtx } from './define.js';\n\nconst EditSpecSchema = z\n .strictObject({\n oldText: z\n .string()\n .min(1, 'oldText required')\n .refine((val) => !isBlank(val), {\n message: 'oldText cannot be empty or whitespace-only',\n })\n .describe(\n 'Exact literal text to locate in the file. Must include 3-5 lines of context to ensure uniqueness and avoid matching the wrong block.',\n )\n .meta({ examples: ['const x = 1;', 'function oldName('] }),\n newText: z\n .string()\n .describe('Replacement text. Use an empty string to delete the matched oldText.')\n .meta({ examples: ['const x = 2;', 'function newName(', ''] }),\n })\n // The one document in this server where a `$ref` pays: this subschema is used\n // at both `edits` and `files[].edits`, so an `id` hoists it into `$defs` once\n // instead of inlining ~1.3 kB twice. Shared schemas used once per document\n // deliberately carry no `id` — there a `$ref` costs more than it saves.\n .meta({ id: 'EditSpec' });\n\nconst MAX_MULTI_FILES = 5;\nconst MAX_EDITS_PER_FILE = 100;\n\nconst EditFileInputSchema = z\n .strictObject({\n path: RequiredPath.optional().describe('Single file path; mutually exclusive with files'),\n edits: z\n .array(EditSpecSchema)\n .min(1)\n .max(MAX_EDITS_PER_FILE)\n .optional()\n .describe('Replacements applied to path; not allowed when using files'),\n files: z\n .array(\n z.strictObject({\n path: RequiredPath,\n edits: z\n .array(EditSpecSchema)\n .min(1)\n .max(MAX_EDITS_PER_FILE)\n .describe('Replacements to apply to this specific file'),\n }),\n )\n .min(1)\n .max(MAX_MULTI_FILES)\n .optional()\n .describe('Per-file entries (batch mode)'),\n dryRun: defaultFalseBoolean(\n 'Preview diffs without writing to disk (default: false = apply edits)',\n ),\n ignoreWhitespace: defaultFalseBoolean(\n 'Ignore leading/trailing whitespace differences when matching oldText',\n ),\n })\n .superRefine((value, ctx) => {\n const hasPath = value.path !== undefined;\n const hasFiles = value.files !== undefined;\n if (hasPath === hasFiles) {\n ctx.addIssue({\n code: 'custom',\n path: ['path'],\n message: \"Provide exactly one of 'path' or 'files'\",\n input: value,\n });\n }\n if (hasPath && value.edits === undefined) {\n ctx.addIssue({\n code: 'custom',\n path: ['edits'],\n message: \"'edits' required when using 'path'\",\n input: value,\n });\n }\n if (hasFiles && value.edits !== undefined) {\n ctx.addIssue({\n code: 'custom',\n path: ['edits'],\n message: \"'edits' not allowed with 'files'; each file carries its own edits\",\n input: value,\n });\n }\n })\n // Mirror the superRefine on the wire: exactly one input mode, and single-file\n // mode carries its own `edits`. Without `edits` in the first branch, `{ path }`\n // alone validated against the published schema and was then rejected at\n // runtime — the model had no way to see that coming.\n .meta({ oneOf: [{ required: ['path', 'edits'] }, { required: ['files'] }] });\n\nconst PerFileResultSchema = z.strictObject({\n path: z.string().describe('Resolved absolute path of the edited file'),\n size: NonNegInt.describe('File size in bytes after edits'),\n lineCount: NonNegInt.describe('Number of lines in the file after edits'),\n mimeType: z.string().describe('Detected MIME type of the file'),\n kind: FileKind.describe('Broad file kind: text, binary, image, audio, or pdf'),\n resourceUri: z\n .string()\n .optional()\n .describe(\n 'Resource URI pointing to the updated file content; omitted when no edit matched (appliedEdits is 0) and the file was left untouched',\n ),\n modified: IsoDateTime.describe('Last modification timestamp after edits (ISO 8601 UTC)'),\n appliedEdits: NonNegInt.describe('Number of edits successfully applied'),\n linesAdded: NonNegInt.optional().describe('Net lines added by all applied edits'),\n linesRemoved: NonNegInt.optional().describe('Net lines removed by all applied edits'),\n diff: z.string().optional().describe('Unified diff of all changes (present only in dryRun mode)'),\n unmatchedEdits: z\n .array(z.string())\n .optional()\n .describe('oldText values that did not match any content in the file'),\n lineRange: z\n .tuple([PositiveInt, PositiveInt])\n .optional()\n .describe('Line range [firstLine, lastLine] covering all applied edits'),\n});\n\nconst EditPerPathSchema = z.strictObject({\n path: z.string().describe('Requested file path'),\n value: PerFileResultSchema.optional().describe('Edit result; present on success'),\n error: PerFileErrorSchema.optional().describe('Error details; present on failure'),\n});\n\nconst EditFileOutputSchema = z.strictObject({\n results: z\n .array(EditPerPathSchema)\n .describe('Per-path edit results ordered to match the input paths'),\n summary: OperationSummarySchema,\n});\n\ntype EditFileValue = z.infer<typeof PerFileResultSchema>;\n\ninterface TextRange {\n startIndex: number;\n length: number;\n}\n\ninterface EditResult {\n content: string;\n appliedEdits: number;\n unmatchedEdits: string[];\n linesAdded: number;\n linesRemoved: number;\n diff?: string;\n lineRange?: [number, number];\n}\n\nasync function computeDiffStats(\n original: string,\n modified: string,\n): Promise<{ linesAdded: number; linesRemoved: number }> {\n return new Promise((resolve) => {\n // Yield to the event loop so we don't completely block\n setImmediate(() => {\n diffLines(original, modified, {\n callback: (changes) => {\n let linesAdded = 0;\n let linesRemoved = 0;\n for (const part of changes) {\n if (part.added) linesAdded += part.count;\n else if (part.removed) linesRemoved += part.count;\n }\n resolve({ linesAdded, linesRemoved });\n },\n });\n });\n });\n}\n\nfunction findEditMatch(\n content: string,\n oldText: string,\n ignoreWhitespace: boolean,\n regexCache?: Map<string, Regex>,\n): TextRange | undefined {\n if (ignoreWhitespace) {\n // Make whitespace flexible (tolerate indentation/spacing differences)\n // without letting it cross line boundaries: a whitespace run that contains\n // a newline keeps at least one newline, so a single-line oldText cannot\n // match across a newline and a multi-line oldText cannot collapse onto one\n // line. Horizontal whitespace stays mandatory between word characters so\n // adjacent identifiers are not merged.\n const pattern = escapeRegexLiteral(oldText)\n .replace(/[^\\S\\n]*\\n\\s*/g, '[^\\\\S\\\\n]*\\\\n+[^\\\\S\\\\n]*')\n .replace(/(\\w)[^\\S\\n]+(\\w)/g, '$1[^\\\\S\\\\n]+$2')\n .replace(/[^\\S\\n]+/g, '[^\\\\S\\\\n]*');\n let regex = regexCache?.get(pattern);\n if (!regex) {\n regex = compileRegex(pattern, { caseSensitive: true });\n regexCache?.set(pattern, regex);\n }\n // The compiled regex is global and may come from the cache, so lastIndex\n // still points past the previous edit's match — reset before searching.\n regex.lastIndex = 0;\n const match = regex.exec(content);\n\n if (match === null) return undefined;\n // RE2ExecArray types group 0 as optional. A successful match always has it;\n // an empty one would name a zero-length span, which cannot be replaced.\n const matched = match[0];\n if (matched === undefined || matched.length === 0) return undefined;\n\n return {\n startIndex: match.index,\n length: matched.length,\n };\n }\n\n const index = content.indexOf(oldText);\n if (index === -1) {\n return undefined;\n }\n\n return {\n startIndex: index,\n length: oldText.length,\n };\n}\n\nfunction replaceEditMatch(content: string, match: TextRange, newText: string): string {\n return (\n content.slice(0, match.startIndex) + newText + content.slice(match.startIndex + match.length)\n );\n}\n\n/**\n * Compute the 1-indexed line range of changed lines in `modified` relative to\n * `original`, using a common-prefix/suffix line scan. This is a conservative\n * bound (it widens to cover independent changes between matching bookends), but\n * it is computed against the FINAL content so it is not skewed by earlier edits\n * inserting or removing lines — which the per-edit merge could not account for.\n */\nfunction computeChangedLineRange(original: string, modified: string): [number, number] | undefined {\n const origLines = original.split('\\n');\n const modLines = modified.split('\\n');\n const minLen = Math.min(origLines.length, modLines.length);\n\n let firstChanged = -1;\n for (let i = 0; i < minLen; i++) {\n if (origLines[i] !== modLines[i]) {\n firstChanged = i;\n break;\n }\n }\n if (firstChanged === -1 && origLines.length === modLines.length) return undefined;\n if (firstChanged === -1) firstChanged = minLen; // pure append/trim at the tail\n\n let lastChangedMod = modLines.length - 1;\n let lastChangedOrig = origLines.length - 1;\n while (\n lastChangedMod > firstChanged &&\n lastChangedOrig >= 0 &&\n modLines[lastChangedMod] === origLines[lastChangedOrig]\n ) {\n lastChangedMod--;\n lastChangedOrig--;\n }\n\n // When the modified content is a strict prefix of the original (a tail trim on\n // a file with no final newline), the loop above never runs and lastChangedMod\n // lands one below firstChanged. Clamp so the range is never inverted.\n return [firstChanged + 1, Math.max(firstChanged, lastChangedMod) + 1];\n}\n\nfunction buildEditFileValue(\n validPath: string,\n meta: EditFileMetadata,\n modified: string,\n result: EditResult,\n): EditFileValue {\n return {\n path: validPath,\n size: meta.bytesWritten,\n lineCount: meta.lineCount,\n mimeType: meta.mimeType,\n kind: meta.kind,\n ...(meta.resourceUri !== undefined ? { resourceUri: meta.resourceUri } : {}),\n modified,\n appliedEdits: result.appliedEdits,\n ...(result.appliedEdits > 0\n ? { linesAdded: result.linesAdded, linesRemoved: result.linesRemoved }\n : {}),\n ...(result.unmatchedEdits.length > 0 ? { unmatchedEdits: result.unmatchedEdits } : {}),\n ...(result.diff ? { diff: result.diff } : {}),\n ...(result.lineRange ? { lineRange: result.lineRange } : {}),\n };\n}\n\nasync function finalizeEditResult(\n originalContent: string,\n updatedContent: string,\n appliedEdits: number,\n unmatchedEdits: string[],\n lineRange: EditResult['lineRange'],\n): Promise<EditResult> {\n const { linesAdded, linesRemoved } =\n appliedEdits > 0\n ? await computeDiffStats(originalContent, updatedContent)\n : { linesAdded: 0, linesRemoved: 0 };\n\n return {\n content: updatedContent,\n appliedEdits,\n unmatchedEdits,\n linesAdded,\n linesRemoved,\n ...(lineRange ? { lineRange } : {}),\n };\n}\n\ninterface EditFileMetadata {\n bytesWritten: number;\n lineCount: number;\n mimeType: string;\n kind: FileKind;\n /** Undefined when no edit matched: there is no updated content to point at. */\n resourceUri: string | undefined;\n resourceLink: ContentBlock | undefined;\n}\n\nfunction buildEditFileMetadata(\n content: string,\n validPath: string,\n appliedEdits: number,\n resourceStore: ResourceStore | undefined,\n): EditFileMetadata {\n const bytesWritten = Buffer.byteLength(content, 'utf-8');\n const lineCount = countLines(content);\n const mimeInfo = detectMimeFromContent(validPath, content);\n // Omitted rather than empty-stringed when nothing matched: `\"\"` satisfied the\n // schema's `string` and then failed every resources/read a client tried it on.\n const resourceUri = appliedEdits > 0 ? buildFileResourceUri(validPath) : undefined;\n const resourceLink =\n appliedEdits > 0 && resourceStore\n ? buildFileResourceLink(validPath, mimeInfo.mimeType, bytesWritten)\n : undefined;\n return {\n bytesWritten,\n lineCount,\n mimeType: mimeInfo.mimeType,\n kind: mimeInfo.kind,\n resourceUri,\n resourceLink,\n };\n}\n\nasync function applyEdits(\n content: string,\n edits: z.infer<typeof EditSpecSchema>[],\n ignoreWhitespace: boolean,\n): Promise<EditResult> {\n let newContent = content;\n let appliedEdits = 0;\n const unmatchedEdits: string[] = [];\n const regexCache = ignoreWhitespace ? new Map<string, Regex>() : undefined;\n\n try {\n for (const edit of edits) {\n const match = findEditMatch(newContent, edit.oldText, ignoreWhitespace, regexCache);\n\n if (!match) {\n unmatchedEdits.push(edit.oldText);\n continue;\n }\n\n newContent = replaceEditMatch(newContent, match, edit.newText);\n appliedEdits += 1;\n }\n } finally {\n // Every cached pattern owns wasm memory re2-wasm never reclaims on its own,\n // and the cache does not outlive this call.\n for (const cached of regexCache?.values() ?? []) freeRegex(cached);\n regexCache?.clear();\n }\n\n // Compute the line range against the final content so earlier edits whose\n // lines were shifted by later edits are still covered.\n const lineRange = appliedEdits > 0 ? computeChangedLineRange(content, newContent) : undefined;\n\n return finalizeEditResult(content, newContent, appliedEdits, unmatchedEdits, lineRange);\n}\n\ninterface EditFileOptions {\n dryRun: boolean;\n ignoreWhitespace: boolean;\n}\n\nasync function handleEditFile(\n filePath: string,\n edits: z.infer<typeof EditSpecSchema>[],\n options: EditFileOptions,\n ctx: ToolCtx,\n): Promise<{ file: EditFileValue; resourceLink?: ContentBlock }> {\n const { validPath, content } = await ctx.fs.readEditableText(filePath, {\n signal: ctx.signal,\n });\n const editResult = await applyEdits(content, edits, options.ignoreWhitespace);\n\n if (options.dryRun) {\n if (editResult.appliedEdits > 0) {\n const label = basename(validPath);\n editResult.diff = await new Promise<string>((resolve) => {\n createTwoFilesPatch(label, label, content, editResult.content, 'Original', 'Modified', {\n callback: (res: string | undefined) => {\n resolve(res ?? '');\n },\n });\n });\n }\n\n // Nothing was written, so there is no updated content to point a\n // resourceUri or a resource_link at — the file on disk is still the one the\n // caller already has. Same rule the appliedEdits-is-0 case follows: no\n // write, no link.\n const meta = buildEditFileMetadata(editResult.content, validPath, 0, ctx.resourceStore);\n return {\n file: buildEditFileValue(validPath, meta, new Date().toISOString(), editResult),\n ...(meta.resourceLink ? { resourceLink: meta.resourceLink } : {}),\n };\n }\n\n if (editResult.unmatchedEdits.length > 0) {\n throw new FsError(\n ErrorCode.INVALID_INPUT,\n `${editResult.unmatchedEdits.length} edit(s) failed to match. Verify oldText matches exact file content.`,\n filePath,\n );\n }\n\n if (editResult.appliedEdits > 0) {\n await ctx.fs.writeFile(filePath, editResult.content, {\n encoding: 'utf-8',\n signal: ctx.signal,\n });\n ctx.log?.(\n 'info',\n `edit: ${filePath} (${editResult.appliedEdits} edits, +${editResult.linesAdded}/-${editResult.linesRemoved})`,\n 'edit',\n );\n }\n\n // `modified` is read from a post-write stat and is advisory: under a concurrent\n // writer it may reflect that writer's mtime while `size`/content below come from\n // this edit's atomic write. The file content itself is always consistent.\n const { stats: fileStats } = await ctx.fs.stat(filePath, { signal: ctx.signal });\n const meta = buildEditFileMetadata(\n editResult.content,\n validPath,\n editResult.appliedEdits,\n ctx.resourceStore,\n );\n return {\n file: buildEditFileValue(validPath, meta, fileStats.mtime.toISOString(), editResult),\n ...(meta.resourceLink ? { resourceLink: meta.resourceLink } : {}),\n };\n}\n\nfunction formatEditSummary(\n results: readonly z.infer<typeof EditPerPathSchema>[],\n dryRun: boolean,\n): string {\n const tag = dryRun ? ' [dry run]' : '';\n // Single-file failure: say why here rather than making the caller read\n // structuredContent for the one message that can apply.\n const [only] = results;\n if (results.length === 1 && only?.error) {\n return `edit: ${only.path} FAILED — ${only.error.message}${tag}`;\n }\n const tokens = results.map((r) => {\n if (r.error) return `${basename(r.path)} FAILED`;\n const v = r.value;\n if (!v) return `${basename(r.path)} (no result)`;\n if (v.unmatchedEdits && v.unmatchedEdits.length > 0) return `${basename(v.path)} NO MATCH`;\n const added = v.linesAdded ?? 0;\n const removed = v.linesRemoved ?? 0;\n if (added === 0 && removed === 0) return `${basename(v.path)} (no change)`;\n return `${basename(v.path)} +${String(added)} -${String(removed)}`;\n });\n\n const failed = results.filter((r) => r.error !== undefined).length;\n const ok = results.length - failed;\n const ratio = failed > 0 ? ` (${String(ok)}/${String(results.length)} ok)` : '';\n return `edit: ${tokens.join(' · ')}${ratio}${tag}`;\n}\n\nexport const EDIT = defineTool({\n name: 'edit',\n title: 'Edit Files',\n description:\n 'Apply sequential literal string replacements to one or more files (max 5 files per call). ' +\n 'Modes: single-file { path, edits } or per-file { files: [{ path, edits }] }. ' +\n 'oldText must match file content exactly; include 3-5 lines of surrounding context to ensure uniqueness. ' +\n 'Set dryRun=true to preview diffs without writing. ' +\n 'For glob-based bulk regex replacement across many files, use replace_text instead.',\n input: EditFileInputSchema,\n output: EditFileOutputSchema,\n // Same per-path union as read, plus diff, which is present only under dryRun.\n publishOutputSchema: true,\n annotations: {\n readOnlyHint: false,\n idempotentHint: false,\n destructiveHint: true,\n openWorldHint: false,\n },\n progress: (args) => {\n const dryLabel = args.dryRun ? ' [dry run]' : '';\n let subject: string;\n if (args.path !== undefined) {\n subject = basename(args.path);\n } else if (args.files !== undefined) {\n subject = `${args.files.length} files`;\n } else {\n subject = 'files';\n }\n return { label: `Edit${dryLabel}`, subject };\n },\n accessPaths: singleOrBatchAccessPaths,\n run: async (args, ctx) => {\n const sharedEdits = args.edits ?? [];\n const batchInput = args.path !== undefined ? { path: args.path } : { files: args.files ?? [] };\n\n const options: EditFileOptions = {\n dryRun: args.dryRun,\n ignoreWhitespace: args.ignoreWhitespace,\n };\n\n const batch = await runOverPaths<\n { edits: z.infer<typeof EditSpecSchema>[] },\n { file: EditFileValue; resourceLink?: ContentBlock }\n >(\n batchInput,\n ctx,\n ({ path, override }) => handleEditFile(path, override?.edits ?? sharedEdits, options, ctx),\n { defaultErrorCode: ErrorCode.UNKNOWN },\n );\n\n const perPathResults: z.infer<typeof EditPerPathSchema>[] = [];\n const resourceLinks: ContentBlock[] = [];\n for (const r of batch.results) {\n if ('error' in r) {\n perPathResults.push({ path: r.path, error: r.error });\n continue;\n }\n perPathResults.push({ path: r.path, value: r.value.file });\n if (r.value.resourceLink) resourceLinks.push(r.value.resourceLink);\n }\n\n const summaryText = formatEditSummary(perPathResults, args.dryRun);\n\n return {\n structured: {\n results: perPathResults,\n summary: batch.summary,\n },\n text: summaryText,\n ...(resourceLinks.length > 0 ? { resources: resourceLinks } : {}),\n };\n },\n});\n"]}
@@ -0,0 +1,26 @@
1
+ import type { McpServer } from '@modelcontextprotocol/server';
2
+ import type { PageSnapshotStore } from '../core/page-store.js';
3
+ import type { PathGuard } from '../core/path.js';
4
+ import type { ResourceStore } from '../core/store.js';
5
+ import type { DefinedTool } from './define.js';
6
+ import { LIST } from './list.js';
7
+ import { READ_FILE } from './read.js';
8
+ import { LIST_ALLOWED_DIRECTORIES } from './roots.js';
9
+ import { SEARCH_CONTENT } from './search-content.js';
10
+ import { SEARCH_FILES } from './search-files.js';
11
+ import { GET_FILE_INFO } from './stat.js';
12
+ export declare const ALL_TOOLS: readonly [DefinedTool, DefinedTool, DefinedTool, DefinedTool, DefinedTool, DefinedTool, DefinedTool, DefinedTool, DefinedTool, DefinedTool, DefinedTool, DefinedTool, DefinedTool];
13
+ export declare const MUTATING_TOOL_NAMES: Set<string>;
14
+ export declare const ALL_REGISTERED_TOOL_NAMES: readonly string[];
15
+ /** The tools a server registers at this setting — the one owner of the `--read-only` gate. */
16
+ export declare function registeredTools(readOnly: boolean): readonly DefinedTool[];
17
+ export { LIST, LIST_ALLOWED_DIRECTORIES, READ_FILE, SEARCH_CONTENT, SEARCH_FILES, GET_FILE_INFO };
18
+ interface ToolRegistrarDeps {
19
+ readonly server: McpServer;
20
+ readonly pathGuard: PathGuard;
21
+ readonly pageStore: PageSnapshotStore;
22
+ readonly resourceStore: ResourceStore;
23
+ readonly readOnly?: boolean;
24
+ }
25
+ export declare function registerTools(deps: ToolRegistrarDeps): void;
26
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAE9D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEtD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAI/C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGjC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,OAAO,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE1C,eAAO,MAAM,SAAS,oLAcZ,CAAC;AAEX,eAAO,MAAM,mBAAmB,aAE/B,CAAC;AAEF,eAAO,MAAM,yBAAyB,EAAE,SAAS,MAAM,EAAiC,CAAC;AAEzF,8FAA8F;AAC9F,wBAAgB,eAAe,CAAC,QAAQ,EAAE,OAAO,GAAG,SAAS,WAAW,EAAE,CAEzE;AAOD,OAAO,EAAE,IAAI,EAAE,wBAAwB,EAAE,SAAS,EAAE,cAAc,EAAE,YAAY,EAAE,aAAa,EAAE,CAAC;AAElG,UAAU,iBAAiB;IACzB,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC;IAC3B,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAC9B,QAAQ,CAAC,SAAS,EAAE,iBAAiB,CAAC;IACtC,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC;IACtC,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,iBAAiB,GAAG,IAAI,CAU3D"}
@@ -0,0 +1,52 @@
1
+ import { CREATE } from './create.js';
2
+ import { DELETE_FILE } from './delete-file.js';
3
+ import { DIFF } from './diff.js';
4
+ import { EDIT } from './edit.js';
5
+ import { LIST } from './list.js';
6
+ import { MOVE } from './move.js';
7
+ import { PATCH } from './patch.js';
8
+ import { READ_FILE } from './read.js';
9
+ import { SEARCH_AND_REPLACE } from './replace-in-files.js';
10
+ import { LIST_ALLOWED_DIRECTORIES } from './roots.js';
11
+ import { SEARCH_CONTENT } from './search-content.js';
12
+ import { SEARCH_FILES } from './search-files.js';
13
+ import { GET_FILE_INFO } from './stat.js';
14
+ export const ALL_TOOLS = [
15
+ CREATE,
16
+ DELETE_FILE,
17
+ DIFF,
18
+ EDIT,
19
+ LIST,
20
+ MOVE,
21
+ PATCH,
22
+ READ_FILE,
23
+ SEARCH_AND_REPLACE,
24
+ LIST_ALLOWED_DIRECTORIES,
25
+ SEARCH_CONTENT,
26
+ SEARCH_FILES,
27
+ GET_FILE_INFO,
28
+ ];
29
+ export const MUTATING_TOOL_NAMES = new Set(ALL_TOOLS.filter((t) => !t.annotations.readOnlyHint).map((t) => t.name));
30
+ export const ALL_REGISTERED_TOOL_NAMES = ALL_TOOLS.map((t) => t.name);
31
+ /** The tools a server registers at this setting — the one owner of the `--read-only` gate. */
32
+ export function registeredTools(readOnly) {
33
+ return readOnly ? ALL_TOOLS.filter((t) => !MUTATING_TOOL_NAMES.has(t.name)) : ALL_TOOLS;
34
+ }
35
+ // Re-exported so documentation surfaces quote `.name` off the definition rather
36
+ // than repeating the string. This module is the only owner of the inventory.
37
+ // Only the read-only tools are named individually: the mutating six are no
38
+ // longer listed by hand anywhere, so their names reach callers through
39
+ // MUTATING_TOOL_NAMES and ALL_TOOLS instead.
40
+ export { LIST, LIST_ALLOWED_DIRECTORIES, READ_FILE, SEARCH_CONTENT, SEARCH_FILES, GET_FILE_INFO };
41
+ export function registerTools(deps) {
42
+ const toolDeps = {
43
+ server: deps.server,
44
+ pathGuard: deps.pathGuard,
45
+ pageStore: deps.pageStore,
46
+ resourceStore: deps.resourceStore,
47
+ };
48
+ for (const tool of registeredTools(deps.readOnly ?? false)) {
49
+ tool.register(toolDeps);
50
+ }
51
+ }
52
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE1C,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,MAAM;IACN,WAAW;IACX,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ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,CAAC;IAC1B,CAAC;AACH,CAAC","sourcesContent":["import type { McpServer } from '@modelcontextprotocol/server';\n\nimport type { PageSnapshotStore } from '../core/page-store.js';\nimport type { PathGuard } from '../core/path.js';\nimport type { ResourceStore } from '../core/store.js';\nimport { CREATE } from './create.js';\nimport type { DefinedTool } from './define.js';\nimport { DELETE_FILE } from './delete-file.js';\nimport { DIFF } from './diff.js';\nimport { EDIT } from './edit.js';\nimport { LIST } from './list.js';\nimport { MOVE } from './move.js';\nimport { PATCH } from './patch.js';\nimport { READ_FILE } from './read.js';\nimport { SEARCH_AND_REPLACE } from './replace-in-files.js';\nimport { LIST_ALLOWED_DIRECTORIES } from './roots.js';\nimport { SEARCH_CONTENT } from './search-content.js';\nimport { SEARCH_FILES } from './search-files.js';\nimport { GET_FILE_INFO } from './stat.js';\n\nexport const ALL_TOOLS = [\n CREATE,\n DELETE_FILE,\n DIFF,\n EDIT,\n LIST,\n MOVE,\n PATCH,\n READ_FILE,\n SEARCH_AND_REPLACE,\n LIST_ALLOWED_DIRECTORIES,\n SEARCH_CONTENT,\n SEARCH_FILES,\n GET_FILE_INFO,\n] as const;\n\nexport const MUTATING_TOOL_NAMES = new Set(\n ALL_TOOLS.filter((t) => !t.annotations.readOnlyHint).map((t) => t.name),\n);\n\nexport const ALL_REGISTERED_TOOL_NAMES: readonly string[] = ALL_TOOLS.map((t) => t.name);\n\n/** The tools a server registers at this setting — the one owner of the `--read-only` gate. */\nexport function registeredTools(readOnly: boolean): readonly DefinedTool[] {\n return readOnly ? ALL_TOOLS.filter((t) => !MUTATING_TOOL_NAMES.has(t.name)) : ALL_TOOLS;\n}\n\n// Re-exported so documentation surfaces quote `.name` off the definition rather\n// than repeating the string. This module is the only owner of the inventory.\n// Only the read-only tools are named individually: the mutating six are no\n// longer listed by hand anywhere, so their names reach callers through\n// MUTATING_TOOL_NAMES and ALL_TOOLS instead.\nexport { LIST, LIST_ALLOWED_DIRECTORIES, READ_FILE, SEARCH_CONTENT, SEARCH_FILES, GET_FILE_INFO };\n\ninterface ToolRegistrarDeps {\n readonly server: McpServer;\n readonly pathGuard: PathGuard;\n readonly pageStore: PageSnapshotStore;\n readonly resourceStore: ResourceStore;\n readonly readOnly?: boolean;\n}\n\nexport function registerTools(deps: ToolRegistrarDeps): void {\n const toolDeps = {\n server: deps.server,\n pathGuard: deps.pathGuard,\n pageStore: deps.pageStore,\n resourceStore: deps.resourceStore,\n };\n for (const tool of registeredTools(deps.readOnly ?? false)) {\n tool.register(toolDeps);\n }\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export declare const LIST: import("./define.js").DefinedTool;
2
+ //# sourceMappingURL=list.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../src/tools/list.ts"],"names":[],"mappings":"AAuWA,eAAO,MAAM,IAAI,mCAiCf,CAAC"}