@j0hanz/filesystem-mcp 2.1.5 → 2.1.6

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 (112) hide show
  1. package/dist/cli.d.ts.map +1 -1
  2. package/dist/cli.js +6 -13
  3. package/dist/cli.js.map +1 -1
  4. package/dist/core/diff.d.ts +6 -0
  5. package/dist/core/diff.d.ts.map +1 -0
  6. package/dist/core/diff.js +21 -0
  7. package/dist/core/diff.js.map +1 -0
  8. package/dist/core/errors.d.ts +0 -20
  9. package/dist/core/errors.d.ts.map +1 -1
  10. package/dist/core/errors.js +9 -60
  11. package/dist/core/errors.js.map +1 -1
  12. package/dist/core/file-uri.d.ts +18 -2
  13. package/dist/core/file-uri.d.ts.map +1 -1
  14. package/dist/core/file-uri.js +34 -6
  15. package/dist/core/file-uri.js.map +1 -1
  16. package/dist/core/fs.d.ts +1 -2
  17. package/dist/core/fs.d.ts.map +1 -1
  18. package/dist/core/fs.js +3 -22
  19. package/dist/core/fs.js.map +1 -1
  20. package/dist/core/glob.d.ts +1 -6
  21. package/dist/core/glob.d.ts.map +1 -1
  22. package/dist/core/glob.js +0 -9
  23. package/dist/core/glob.js.map +1 -1
  24. package/dist/core/input-required.d.ts +2 -4
  25. package/dist/core/input-required.d.ts.map +1 -1
  26. package/dist/core/input-required.js +3 -4
  27. package/dist/core/input-required.js.map +1 -1
  28. package/dist/core/path-completer.d.ts.map +1 -1
  29. package/dist/core/path-completer.js +1 -6
  30. package/dist/core/path-completer.js.map +1 -1
  31. package/dist/core/path.d.ts +4 -8
  32. package/dist/core/path.d.ts.map +1 -1
  33. package/dist/core/path.js +13 -26
  34. package/dist/core/path.js.map +1 -1
  35. package/dist/core/primitives.d.ts +8 -2
  36. package/dist/core/primitives.d.ts.map +1 -1
  37. package/dist/core/primitives.js +10 -2
  38. package/dist/core/primitives.js.map +1 -1
  39. package/dist/core/read.d.ts +0 -15
  40. package/dist/core/read.d.ts.map +1 -1
  41. package/dist/core/read.js +12 -41
  42. package/dist/core/read.js.map +1 -1
  43. package/dist/core/schema.d.ts +1 -16
  44. package/dist/core/schema.d.ts.map +1 -1
  45. package/dist/core/schema.js +7 -41
  46. package/dist/core/schema.js.map +1 -1
  47. package/dist/core/search.d.ts +10 -3
  48. package/dist/core/search.d.ts.map +1 -1
  49. package/dist/core/search.js +19 -13
  50. package/dist/core/search.js.map +1 -1
  51. package/dist/core/sensitive.d.ts.map +1 -1
  52. package/dist/core/sensitive.js +7 -15
  53. package/dist/core/sensitive.js.map +1 -1
  54. package/dist/core/store.d.ts +0 -1
  55. package/dist/core/store.d.ts.map +1 -1
  56. package/dist/core/store.js +0 -1
  57. package/dist/core/store.js.map +1 -1
  58. package/dist/index.js +1 -8
  59. package/dist/index.js.map +1 -1
  60. package/dist/prompts.d.ts.map +1 -1
  61. package/dist/prompts.js +13 -28
  62. package/dist/prompts.js.map +1 -1
  63. package/dist/tools/batch.d.ts +5 -78
  64. package/dist/tools/batch.d.ts.map +1 -1
  65. package/dist/tools/batch.js +6 -115
  66. package/dist/tools/batch.js.map +1 -1
  67. package/dist/tools/create.d.ts.map +1 -1
  68. package/dist/tools/create.js +8 -18
  69. package/dist/tools/create.js.map +1 -1
  70. package/dist/tools/define.d.ts +1 -4
  71. package/dist/tools/define.d.ts.map +1 -1
  72. package/dist/tools/define.js +1 -22
  73. package/dist/tools/define.js.map +1 -1
  74. package/dist/tools/delete-file.d.ts.map +1 -1
  75. package/dist/tools/delete-file.js +6 -6
  76. package/dist/tools/delete-file.js.map +1 -1
  77. package/dist/tools/diff.d.ts.map +1 -1
  78. package/dist/tools/diff.js +3 -10
  79. package/dist/tools/diff.js.map +1 -1
  80. package/dist/tools/edit.d.ts.map +1 -1
  81. package/dist/tools/edit.js +39 -71
  82. package/dist/tools/edit.js.map +1 -1
  83. package/dist/tools/index.d.ts +0 -1
  84. package/dist/tools/index.d.ts.map +1 -1
  85. package/dist/tools/index.js +0 -1
  86. package/dist/tools/index.js.map +1 -1
  87. package/dist/tools/list.js +2 -1
  88. package/dist/tools/list.js.map +1 -1
  89. package/dist/tools/move.d.ts.map +1 -1
  90. package/dist/tools/move.js +162 -116
  91. package/dist/tools/move.js.map +1 -1
  92. package/dist/tools/patch.d.ts.map +1 -1
  93. package/dist/tools/patch.js +5 -23
  94. package/dist/tools/patch.js.map +1 -1
  95. package/dist/tools/read.d.ts.map +1 -1
  96. package/dist/tools/read.js +20 -21
  97. package/dist/tools/read.js.map +1 -1
  98. package/dist/tools/replace-in-files.d.ts.map +1 -1
  99. package/dist/tools/replace-in-files.js +23 -38
  100. package/dist/tools/replace-in-files.js.map +1 -1
  101. package/dist/tools/search-content.d.ts.map +1 -1
  102. package/dist/tools/search-content.js +10 -31
  103. package/dist/tools/search-content.js.map +1 -1
  104. package/dist/tools/search-files.d.ts.map +1 -1
  105. package/dist/tools/search-files.js +1 -2
  106. package/dist/tools/search-files.js.map +1 -1
  107. package/dist/tools/stat.d.ts.map +1 -1
  108. package/dist/tools/stat.js +4 -3
  109. package/dist/tools/stat.js.map +1 -1
  110. package/dist/transport/http-policy.js +1 -1
  111. package/dist/transport/http-policy.js.map +1 -1
  112. package/package.json +1 -1
@@ -1,29 +1,11 @@
1
- import type { InputRequiredResult } from '@modelcontextprotocol/server';
2
- import { ErrorCode } from '../core/errors.js';
1
+ import { ErrorCode, Problem } from '../core/errors.js';
3
2
  import type { ToolCtx } from './define.js';
4
- interface PerPathError {
5
- code: ErrorCode;
6
- message: string;
7
- path?: string;
8
- suggestion?: string;
9
- }
10
- /** One entry of a source→destination tool's `failures[]` — move's failure schema is the wire twin. */
11
- export interface PairFailureItem {
12
- source: string;
13
- destination: string;
14
- error: {
15
- code: string;
16
- message: string;
17
- path?: string | undefined;
18
- suggestion?: string | undefined;
19
- };
20
- }
21
3
  export type PerPathResult<T> = {
22
4
  path: string;
23
5
  value: T;
24
6
  } | {
25
7
  path: string;
26
- error: PerPathError;
8
+ error: Problem;
27
9
  };
28
10
  export interface BatchResult<T> {
29
11
  results: PerPathResult<T>[];
@@ -49,70 +31,15 @@ export declare function runOverPaths<TOverride, TPerPath>(args: BatchInput<TOver
49
31
  path: string;
50
32
  override?: TOverride;
51
33
  }, ctx: ToolCtx) => Promise<TPerPath>, options?: RunOverPathsOptions): Promise<BatchResult<TPerPath>>;
52
- /** The minimum a pair plan must expose for the shared driver to route it. */
53
- export interface PairPlan {
54
- readonly pair: {
55
- source: string;
56
- destination: string;
57
- };
58
- readonly validDest: string;
59
- readonly pending: boolean;
60
- }
61
- export type PairPlanResult<TPlan extends PairPlan> = {
62
- status: 'fail';
63
- failure: PairFailureItem;
64
- } | {
65
- status: 'noop';
66
- } | {
67
- status: 'plan';
68
- plan: TPlan;
69
- };
70
- /** A discriminated union, so the fold below narrows without a generic cast. */
71
- export type PairExecResult<TResult> = {
72
- readonly skipped: string;
73
- } | {
74
- readonly value: TResult;
75
- };
76
- export interface PairBatchOutcome<TResult> {
77
- results: TResult[];
78
- skipped: string[];
79
- failures: PairFailureItem[];
80
- }
81
34
  /**
82
35
  * A batch where every requested item failed produced no work at all, so it is a
83
- * failed call — `isError` must say so. Partial failure is deliberately NOT an
36
+ * failed call - `isError` must say so. Partial failure is deliberately NOT an
84
37
  * error: the per-item entries carry which failed, and the succeeded ones really
85
- * were done. A skipped item is work the caller asked to skip, not work that
86
- * failed — a self-move that was silently dropped means the call did something.
87
- * Zero items is not a failure either.
88
- *
89
- * Takes either count shape a batch tool holds at its return site: a `summary`
90
- * (`runOverPaths`, or the hand-built ones in `read`, `delete`, `replace_text`)
91
- * or a pair outcome (`runOverPairs`).
38
+ * were done. Zero items is not a failure either.
92
39
  */
93
- export declare function isTotalFailure(shape: {
40
+ export declare function isTotalFailure(summary: {
94
41
  readonly total: number;
95
42
  readonly failed: number;
96
- } | {
97
- readonly results: readonly unknown[];
98
- readonly skipped: readonly unknown[];
99
- readonly failures: readonly unknown[];
100
43
  }): boolean;
101
- export declare function pairFailure(pair: {
102
- source: string;
103
- destination: string;
104
- }, error: unknown): PairFailureItem;
105
- interface RunOverPairsOptions<TItem, TPlan extends PairPlan, TResult> {
106
- readonly op: 'copy' | 'move';
107
- readonly plan: (item: TItem) => Promise<PairPlanResult<TPlan>>;
108
- readonly execute: (plan: TPlan, pendingSorted: readonly string[]) => Promise<PairExecResult<TResult>>;
109
- }
110
- /**
111
- * The source→destination sibling of `runOverPaths`: plan every pair, fail closed
112
- * on a duplicated destination, round-trip the overwrite confirmations as one
113
- * set, then execute what survived in parallel. `copy` and `move` differ only in
114
- * their `plan` and `execute` callbacks.
115
- */
116
- export declare function runOverPairs<TItem, TPlan extends PairPlan, TResult>(items: readonly TItem[], ctx: ToolCtx, opts: RunOverPairsOptions<TItem, TPlan, TResult>): Promise<PairBatchOutcome<TResult> | InputRequiredResult>;
117
44
  export {};
118
45
  //# sourceMappingURL=batch.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"batch.d.ts","sourceRoot":"","sources":["../../src/tools/batch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAGxE,OAAO,EAAE,SAAS,EAAsC,MAAM,mBAAmB,CAAC;AAIlF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAE3C,UAAU,YAAY;IACpB,IAAI,EAAE,SAAS,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,sGAAsG;AACtG,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE;QACL,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;QAC1B,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;KACjC,CAAC;CACH;AAED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AE,MAAM,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,MAAM,EAAE,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,CAAC;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,CAAC,EAAE,CAAA;CAAE,CAAC;AAEvF,UAAU,mBAAmB;IAC3B,gBAAgB,CAAC,EAAE,SAAS,CAAC;CAC9B;AAeD,wBAAsB,YAAY,CAAC,SAAS,EAAE,QAAQ,EACpD,IAAI,EAAE,UAAU,CAAC,SAAS,CAAC,EAC3B,GAAG,EAAE,OAAO,EACZ,OAAO,EAAE,CAAC,IAAI,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,SAAS,CAAA;CAAE,EAAE,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,EAC1F,OAAO,CAAC,EAAE,mBAAmB,GAC5B,OAAO,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,CAoDhC;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE;IACtC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB,GAAG,OAAO,CAEV"}
@@ -1,7 +1,5 @@
1
1
  import { processInParallel } from '../core/concurrency.js';
2
- import { ErrorCode, FsError, Problem, rethrowIfAborted } from '../core/errors.js';
3
- import { choiceInput, pendingRoundTrip } from '../core/input-required.js';
4
- import { IS_CASE_INSENSITIVE_FS } from '../core/path-utils.js';
2
+ import { ErrorCode, FsError, Problem } from '../core/errors.js';
5
3
  import { PARALLEL_CONCURRENCY } from '../core/util.js';
6
4
  function normalizeBatchItems(args) {
7
5
  if ('path' in args)
@@ -36,7 +34,7 @@ export async function runOverPaths(args, ctx, perPath, options) {
36
34
  catch (error) {
37
35
  results[index] = {
38
36
  path: item.path,
39
- error: Problem.toPerFileError(error, defaultErrorCode, item.path),
37
+ error: Problem.fromUnknown(error, defaultErrorCode, item.path),
40
38
  };
41
39
  }
42
40
  finally {
@@ -56,118 +54,11 @@ export async function runOverPaths(args, ctx, perPath, options) {
56
54
  }
57
55
  /**
58
56
  * A batch where every requested item failed produced no work at all, so it is a
59
- * failed call — `isError` must say so. Partial failure is deliberately NOT an
57
+ * failed call - `isError` must say so. Partial failure is deliberately NOT an
60
58
  * error: the per-item entries carry which failed, and the succeeded ones really
61
- * were done. A skipped item is work the caller asked to skip, not work that
62
- * failed — a self-move that was silently dropped means the call did something.
63
- * Zero items is not a failure either.
64
- *
65
- * Takes either count shape a batch tool holds at its return site: a `summary`
66
- * (`runOverPaths`, or the hand-built ones in `read`, `delete`, `replace_text`)
67
- * or a pair outcome (`runOverPairs`).
59
+ * were done. Zero items is not a failure either.
68
60
  */
69
- export function isTotalFailure(shape) {
70
- if ('total' in shape)
71
- return shape.total > 0 && shape.failed === shape.total;
72
- return shape.failures.length > 0 && shape.results.length + shape.skipped.length === 0;
73
- }
74
- export function pairFailure(pair, error) {
75
- return {
76
- source: pair.source,
77
- destination: pair.destination,
78
- error: Problem.toPerFileError(error, ErrorCode.UNKNOWN, pair.source),
79
- };
80
- }
81
- /**
82
- * The source→destination sibling of `runOverPaths`: plan every pair, fail closed
83
- * on a duplicated destination, round-trip the overwrite confirmations as one
84
- * set, then execute what survived in parallel. `copy` and `move` differ only in
85
- * their `plan` and `execute` callbacks.
86
- */
87
- export async function runOverPairs(items, ctx, opts) {
88
- const verb = opts.op === 'copy' ? 'Copy' : 'Move';
89
- const { results: planned, errors: planErrors } = await processInParallel(items, opts.plan, PARALLEL_CONCURRENCY, ctx.signal);
90
- // plan callbacks are fail-closed (they return { status: 'fail' }, never
91
- // throw), so planErrors should always be empty. Surface the first rather
92
- // than silently dropping the item if a future plan callback violates that.
93
- const firstPlanError = planErrors[0];
94
- if (firstPlanError)
95
- throw firstPlanError.error;
96
- const failures = [];
97
- const candidates = [];
98
- for (const { value } of planned) {
99
- if (value.status === 'fail')
100
- failures.push(value.failure);
101
- else if (value.status === 'plan')
102
- candidates.push(value.plan);
103
- // 'noop' (self-copy / self-move) is silently skipped.
104
- }
105
- // Two sources targeting the same destination in one batch would otherwise
106
- // collapse to a single shared overwrite confirmation and let the second
107
- // one silently clobber the first's freshly-written content. Fail closed:
108
- // only the first plan per destination proceeds; later ones targeting the
109
- // same destination are reported as a per-item failure.
110
- const seenDest = new Set();
111
- const ready = [];
112
- for (const plan of candidates) {
113
- const destKey = IS_CASE_INSENSITIVE_FS ? plan.validDest.toLowerCase() : plan.validDest;
114
- if (seenDest.has(destKey)) {
115
- failures.push(pairFailure(plan.pair, new FsError(ErrorCode.INVALID_INPUT, `${verb} cancelled: another entry in this batch already targets destination "${plan.pair.destination}"`, plan.pair.destination)));
116
- continue;
117
- }
118
- seenDest.add(destKey);
119
- ready.push(plan);
120
- }
121
- const pendingSorted = ready
122
- .filter((p) => p.pending)
123
- .map((p) => p.validDest)
124
- .sort();
125
- if (pendingSorted.length > 0) {
126
- // Round 1 returns input_required; a retry whose verified state does not
127
- // bind this overwrite set throws (R9) via `pendingRoundTrip`.
128
- const round = await pendingRoundTrip({
129
- op: opts.op,
130
- pending: pendingSorted,
131
- requestState: ctx.requestState,
132
- clientCapabilities: ctx.clientCapabilities,
133
- buildInputs: (dests) => dests.map((dest, i) => choiceInput(`confirm_${i}`, opts.op === 'move'
134
- ? `"${dest}" already exists. Overwrite it?`
135
- : `Destination "${dest}" already exists. Overwrite it?`, [
136
- { value: 'overwrite', title: 'Overwrite' },
137
- { value: 'skip', title: 'Skip' },
138
- ])),
139
- });
140
- if (round !== undefined)
141
- return round;
142
- }
143
- const total = ready.length;
144
- let completed = 0;
145
- const tick = () => {
146
- completed += 1;
147
- ctx.onProgress?.({ current: completed, total });
148
- };
149
- const { results: execResults, errors: execErrors } = await processInParallel(ready, async (plan) => {
150
- try {
151
- return await opts.execute(plan, pendingSorted);
152
- }
153
- finally {
154
- tick();
155
- }
156
- }, PARALLEL_CONCURRENCY, ctx.signal);
157
- for (const { error, index } of execErrors) {
158
- rethrowIfAborted(error);
159
- const plan = ready[index];
160
- if (plan)
161
- failures.push(pairFailure(plan.pair, error));
162
- }
163
- const results = [];
164
- const skipped = [];
165
- for (const { value } of execResults) {
166
- if ('skipped' in value)
167
- skipped.push(value.skipped);
168
- else
169
- results.push(value.value);
170
- }
171
- return { results, skipped, failures };
61
+ export function isTotalFailure(summary) {
62
+ return summary.total > 0 && summary.failed === summary.total;
172
63
  }
173
64
  //# sourceMappingURL=batch.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"batch.js","sourceRoot":"","sources":["../../src/tools/batch.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAClF,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC1E,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAoCvD,SAAS,mBAAmB,CAC1B,IAA2B;IAE3B,IAAI,MAAM,IAAI,IAAI;QAAE,OAAO,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;IACjD,IAAI,OAAO,IAAI,IAAI;QAAE,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IACjE,IAAI,OAAO,IAAI,IAAI;QACjB,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;YAC5C,IAAI;YACJ,QAAQ,EAAE,IAAiB;SAC5B,CAAC,CAAC,CAAC;IACN,OAAO,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AAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;AACxC,CAAC","sourcesContent":["import type { InputRequiredResult } from '@modelcontextprotocol/server';\n\nimport { processInParallel } from '../core/concurrency.js';\nimport { ErrorCode, FsError, Problem, rethrowIfAborted } from '../core/errors.js';\nimport { choiceInput, pendingRoundTrip } from '../core/input-required.js';\nimport { IS_CASE_INSENSITIVE_FS } from '../core/path-utils.js';\nimport { PARALLEL_CONCURRENCY } from '../core/util.js';\nimport type { ToolCtx } from './define.js';\n\ninterface PerPathError {\n code: ErrorCode;\n message: string;\n path?: string;\n suggestion?: string;\n}\n\n/** One entry of a source→destination tool's `failures[]` — move's failure schema is the wire twin. */\nexport interface PairFailureItem {\n source: string;\n destination: string;\n error: {\n code: string;\n message: string;\n path?: string | undefined;\n suggestion?: string | undefined;\n };\n}\n\nexport type PerPathResult<T> = { path: string; value: T } | { path: string; error: PerPathError };\n\nexport interface BatchResult<T> {\n results: PerPathResult<T>[];\n summary: { total: number; succeeded: number; failed: number };\n}\n\ntype BatchInput<TOverride> =\n { path: string } | { paths: string[] } | { files: ({ path: string } & TOverride)[] };\n\ninterface RunOverPathsOptions {\n defaultErrorCode?: ErrorCode;\n}\n\nfunction normalizeBatchItems<TOverride>(\n args: BatchInput<TOverride>,\n): { path: string; override?: TOverride }[] {\n if ('path' in args) return [{ path: args.path }];\n if ('paths' in args) return args.paths.map((path) => ({ path }));\n if ('files' in args)\n return args.files.map(({ path, ...rest }) => ({\n path,\n override: rest as TOverride,\n }));\n return [];\n}\n\nexport async function runOverPaths<TOverride, TPerPath>(\n args: BatchInput<TOverride>,\n ctx: ToolCtx,\n perPath: (item: { path: string; override?: TOverride }, ctx: ToolCtx) => Promise<TPerPath>,\n options?: RunOverPathsOptions,\n): Promise<BatchResult<TPerPath>> {\n const items = normalizeBatchItems(args);\n if (items.length === 0) {\n throw new FsError(\n ErrorCode.INVALID_INPUT,\n \"runOverPaths: at least one of 'path', 'paths', or 'files' must be provided\",\n );\n }\n\n const defaultErrorCode = options?.defaultErrorCode ?? ErrorCode.UNKNOWN;\n\n const total = items.length;\n let completed = 0;\n const results: PerPathResult<TPerPath>[] = new Array<PerPathResult<TPerPath>>(total);\n\n const tick = (): void => {\n completed += 1;\n ctx.onProgress?.({ current: completed, total });\n };\n\n await processInParallel<\n { item: { path: string; override?: TOverride }; index: number },\n undefined\n >(\n items.map((item, index) => ({ item, index })),\n async ({ item, index }) => {\n try {\n const value = await perPath(item, ctx);\n results[index] = { path: item.path, value };\n } catch (error: unknown) {\n results[index] = {\n path: item.path,\n error: Problem.toPerFileError(error, defaultErrorCode, item.path),\n };\n } finally {\n tick();\n }\n return undefined;\n },\n PARALLEL_CONCURRENCY,\n ctx.signal,\n );\n\n let succeeded = 0;\n for (const result of results) {\n if (!('error' in result)) succeeded += 1;\n }\n\n return {\n results,\n summary: { total, succeeded, failed: total - succeeded },\n };\n}\n\n/** The minimum a pair plan must expose for the shared driver to route it. */\nexport interface PairPlan {\n readonly pair: { source: string; destination: string };\n readonly validDest: string;\n readonly pending: boolean;\n}\n\nexport type PairPlanResult<TPlan extends PairPlan> =\n | { status: 'fail'; failure: PairFailureItem }\n | { status: 'noop' }\n | { status: 'plan'; plan: TPlan };\n\n/** A discriminated union, so the fold below narrows without a generic cast. */\nexport type PairExecResult<TResult> = { readonly skipped: string } | { readonly value: TResult };\n\nexport interface PairBatchOutcome<TResult> {\n results: TResult[];\n skipped: string[];\n failures: PairFailureItem[];\n}\n\n/**\n * A batch where every requested item failed produced no work at all, so it is a\n * failed call — `isError` must say so. Partial failure is deliberately NOT an\n * error: the per-item entries carry which failed, and the succeeded ones really\n * were done. A skipped item is work the caller asked to skip, not work that\n * failed — a self-move that was silently dropped means the call did something.\n * Zero items is not a failure either.\n *\n * Takes either count shape a batch tool holds at its return site: a `summary`\n * (`runOverPaths`, or the hand-built ones in `read`, `delete`, `replace_text`)\n * or a pair outcome (`runOverPairs`).\n */\nexport function isTotalFailure(\n shape:\n | { readonly total: number; readonly failed: number }\n | {\n readonly results: readonly unknown[];\n readonly skipped: readonly unknown[];\n readonly failures: readonly unknown[];\n },\n): boolean {\n if ('total' in shape) return shape.total > 0 && shape.failed === shape.total;\n return shape.failures.length > 0 && shape.results.length + shape.skipped.length === 0;\n}\n\nexport function pairFailure(\n pair: { source: string; destination: string },\n error: unknown,\n): PairFailureItem {\n return {\n source: pair.source,\n destination: pair.destination,\n error: Problem.toPerFileError(error, ErrorCode.UNKNOWN, pair.source),\n };\n}\n\ninterface RunOverPairsOptions<TItem, TPlan extends PairPlan, TResult> {\n readonly op: 'copy' | 'move';\n readonly plan: (item: TItem) => Promise<PairPlanResult<TPlan>>;\n readonly execute: (\n plan: TPlan,\n pendingSorted: readonly string[],\n ) => Promise<PairExecResult<TResult>>;\n}\n\n/**\n * The source→destination sibling of `runOverPaths`: plan every pair, fail closed\n * on a duplicated destination, round-trip the overwrite confirmations as one\n * set, then execute what survived in parallel. `copy` and `move` differ only in\n * their `plan` and `execute` callbacks.\n */\nexport async function runOverPairs<TItem, TPlan extends PairPlan, TResult>(\n items: readonly TItem[],\n ctx: ToolCtx,\n opts: RunOverPairsOptions<TItem, TPlan, TResult>,\n): Promise<PairBatchOutcome<TResult> | InputRequiredResult> {\n const verb = opts.op === 'copy' ? 'Copy' : 'Move';\n\n const { results: planned, errors: planErrors } = await processInParallel(\n items,\n opts.plan,\n PARALLEL_CONCURRENCY,\n ctx.signal,\n );\n // plan callbacks are fail-closed (they return { status: 'fail' }, never\n // throw), so planErrors should always be empty. Surface the first rather\n // than silently dropping the item if a future plan callback violates that.\n const firstPlanError = planErrors[0];\n if (firstPlanError) throw firstPlanError.error;\n\n const failures: PairFailureItem[] = [];\n const candidates: TPlan[] = [];\n for (const { value } of planned) {\n if (value.status === 'fail') failures.push(value.failure);\n else if (value.status === 'plan') candidates.push(value.plan);\n // 'noop' (self-copy / self-move) is silently skipped.\n }\n\n // Two sources targeting the same destination in one batch would otherwise\n // collapse to a single shared overwrite confirmation and let the second\n // one silently clobber the first's freshly-written content. Fail closed:\n // only the first plan per destination proceeds; later ones targeting the\n // same destination are reported as a per-item failure.\n const seenDest = new Set<string>();\n const ready: TPlan[] = [];\n for (const plan of candidates) {\n const destKey = IS_CASE_INSENSITIVE_FS ? plan.validDest.toLowerCase() : plan.validDest;\n if (seenDest.has(destKey)) {\n failures.push(\n pairFailure(\n plan.pair,\n new FsError(\n ErrorCode.INVALID_INPUT,\n `${verb} cancelled: another entry in this batch already targets destination \"${plan.pair.destination}\"`,\n plan.pair.destination,\n ),\n ),\n );\n continue;\n }\n seenDest.add(destKey);\n ready.push(plan);\n }\n\n const pendingSorted = ready\n .filter((p) => p.pending)\n .map((p) => p.validDest)\n .sort();\n if (pendingSorted.length > 0) {\n // Round 1 returns input_required; a retry whose verified state does not\n // bind this overwrite set throws (R9) via `pendingRoundTrip`.\n const round = await pendingRoundTrip({\n op: opts.op,\n pending: pendingSorted,\n requestState: ctx.requestState,\n clientCapabilities: ctx.clientCapabilities,\n buildInputs: (dests) =>\n dests.map((dest, i) =>\n choiceInput(\n `confirm_${i}`,\n opts.op === 'move'\n ? `\"${dest}\" already exists. Overwrite it?`\n : `Destination \"${dest}\" already exists. Overwrite it?`,\n [\n { value: 'overwrite', title: 'Overwrite' },\n { value: 'skip', title: 'Skip' },\n ],\n ),\n ),\n });\n if (round !== undefined) return round;\n }\n\n const total = ready.length;\n let completed = 0;\n const tick = (): void => {\n completed += 1;\n ctx.onProgress?.({ current: completed, total });\n };\n const { results: execResults, errors: execErrors } = await processInParallel(\n ready,\n async (plan) => {\n try {\n return await opts.execute(plan, pendingSorted);\n } finally {\n tick();\n }\n },\n PARALLEL_CONCURRENCY,\n ctx.signal,\n );\n\n for (const { error, index } of execErrors) {\n rethrowIfAborted(error);\n const plan = ready[index];\n if (plan) failures.push(pairFailure(plan.pair, error));\n }\n\n const results: TResult[] = [];\n const skipped: string[] = [];\n for (const { value } of execResults) {\n if ('skipped' in value) skipped.push(value.skipped);\n else results.push(value.value);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EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,GAAG,SAAS,EAAE;KACzD,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,OAG9B;IACC,OAAO,OAAO,CAAC,KAAK,GAAG,CAAC,IAAI,OAAO,CAAC,MAAM,KAAK,OAAO,CAAC,KAAK,CAAC;AAC/D,CAAC","sourcesContent":["import { processInParallel } from '../core/concurrency.js';\nimport { ErrorCode, FsError, Problem } from '../core/errors.js';\nimport { PARALLEL_CONCURRENCY } from '../core/util.js';\nimport type { ToolCtx } from './define.js';\n\nexport type PerPathResult<T> = { path: string; value: T } | { path: string; error: Problem };\n\nexport interface BatchResult<T> {\n results: PerPathResult<T>[];\n summary: { total: number; succeeded: number; failed: number };\n}\n\ntype BatchInput<TOverride> =\n { path: string } | { paths: string[] } | { files: ({ path: string } & TOverride)[] };\n\ninterface RunOverPathsOptions {\n defaultErrorCode?: ErrorCode;\n}\n\nfunction normalizeBatchItems<TOverride>(\n args: BatchInput<TOverride>,\n): { path: string; override?: TOverride }[] {\n if ('path' in args) return [{ path: args.path }];\n if ('paths' in args) return args.paths.map((path) => ({ path }));\n if ('files' in args)\n return args.files.map(({ path, ...rest }) => ({\n path,\n override: rest as TOverride,\n }));\n return [];\n}\n\nexport async function runOverPaths<TOverride, TPerPath>(\n args: BatchInput<TOverride>,\n ctx: ToolCtx,\n perPath: (item: { path: string; override?: TOverride }, ctx: ToolCtx) => Promise<TPerPath>,\n options?: RunOverPathsOptions,\n): Promise<BatchResult<TPerPath>> {\n const items = normalizeBatchItems(args);\n if (items.length === 0) {\n throw new FsError(\n ErrorCode.INVALID_INPUT,\n \"runOverPaths: at least one of 'path', 'paths', or 'files' must be provided\",\n );\n }\n\n const defaultErrorCode = options?.defaultErrorCode ?? ErrorCode.UNKNOWN;\n\n const total = items.length;\n let completed = 0;\n const results: PerPathResult<TPerPath>[] = new Array<PerPathResult<TPerPath>>(total);\n\n const tick = (): void => {\n completed += 1;\n ctx.onProgress?.({ current: completed, total });\n };\n\n await processInParallel<\n { item: { path: string; override?: TOverride }; index: number },\n undefined\n >(\n items.map((item, index) => ({ item, index })),\n async ({ item, index }) => {\n try {\n const value = await perPath(item, ctx);\n results[index] = { path: item.path, value };\n } catch (error: unknown) {\n results[index] = {\n path: item.path,\n error: Problem.fromUnknown(error, defaultErrorCode, item.path),\n };\n } finally {\n tick();\n }\n return undefined;\n },\n PARALLEL_CONCURRENCY,\n ctx.signal,\n );\n\n let succeeded = 0;\n for (const result of results) {\n if (!('error' in result)) succeeded += 1;\n }\n\n return {\n results,\n summary: { total, succeeded, failed: total - succeeded },\n };\n}\n\n/**\n * A batch where every requested item failed produced no work at all, so it is a\n * failed call - `isError` must say so. Partial failure is deliberately NOT an\n * error: the per-item entries carry which failed, and the succeeded ones really\n * were done. Zero items is not a failure either.\n */\nexport function isTotalFailure(summary: {\n readonly total: number;\n readonly failed: number;\n}): boolean {\n return summary.total > 0 && summary.failed === summary.total;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../src/tools/create.ts"],"names":[],"mappings":"AAgEA,eAAO,MAAM,MAAM,mCA8FjB,CAAC"}
1
+ {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../src/tools/create.ts"],"names":[],"mappings":"AA8DA,eAAO,MAAM,MAAM,mCAsFjB,CAAC"}
@@ -1,9 +1,7 @@
1
1
  import { basename, dirname } from 'node:path';
2
2
  import * as z from 'zod/v4';
3
3
  import { ErrorCode } from '../core/errors.js';
4
- import { buildFileResourceLink, buildFileResourceUri } from '../core/file-uri.js';
5
- import { detectMimeFromContent } from '../core/mime.js';
6
- import { countLines } from '../core/read.js';
4
+ import { buildWrittenFileMeta } from '../core/file-uri.js';
7
5
  import { FileKind, IsoDateTime, NonNegInt, PathFailureSchema, RequiredPath, } from '../core/schema.js';
8
6
  import { getMaxTextFileSize } from '../core/util.js';
9
7
  import { isTotalFailure, runOverPaths } from './batch.js';
@@ -67,26 +65,18 @@ export const CREATE = defineTool({
67
65
  signal: ctx.signal,
68
66
  });
69
67
  const { stats: fileStats } = await ctx.fs.stat(path, { signal: ctx.signal });
70
- const bytesWritten = Buffer.byteLength(content, 'utf-8');
71
- const lineCount = countLines(content);
72
- const mimeInfo = detectMimeFromContent(validPath, content);
73
- const resourceUri = buildFileResourceUri(validPath);
68
+ const meta = buildWrittenFileMeta(validPath, content, ctx.resourceStore);
74
69
  const file = {
75
70
  path: validPath,
76
- size: bytesWritten,
77
- lineCount,
78
- mimeType: mimeInfo.mimeType,
79
- kind: mimeInfo.kind,
80
- resourceUri,
71
+ size: meta.size,
72
+ lineCount: meta.lineCount,
73
+ mimeType: meta.mimeType,
74
+ kind: meta.kind,
75
+ resourceUri: meta.resourceUri,
81
76
  created: fileStats.birthtime.toISOString(),
82
77
  modified: fileStats.mtime.toISOString(),
83
78
  };
84
- return ctx.resourceStore
85
- ? {
86
- file,
87
- resourceLink: buildFileResourceLink(validPath, mimeInfo.mimeType, bytesWritten),
88
- }
89
- : { file };
79
+ return meta.resourceLink ? { file, resourceLink: meta.resourceLink } : { file };
90
80
  }, { defaultErrorCode: ErrorCode.UNKNOWN });
91
81
  const results = [];
92
82
  const failures = [];
@@ -1 +1 @@
1
- {"version":3,"file":"create.js","sourceRoot":"","sources":["../../src/tools/create.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE9C,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAE5B,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAClF,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EACL,QAAQ,EACR,WAAW,EAC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AC,KAAK,CAAC,CAAC,CAAC,EAAE,IAAI,IAAI,EAAE,CAAC;YACrC,CAAC,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ;KAC3C,CAAC;IACF,gBAAgB,EAAE,SAAS,CAAC,OAAO;CACpC,CAAC,CAAC","sourcesContent":["import type { ContentBlock } from '@modelcontextprotocol/server';\n\nimport { basename, dirname } from 'node:path';\n\nimport * as z from 'zod/v4';\n\nimport { ErrorCode } from '../core/errors.js';\nimport { buildFileResourceLink, buildFileResourceUri } from '../core/file-uri.js';\nimport { detectMimeFromContent } from '../core/mime.js';\nimport { countLines } from '../core/read.js';\nimport {\n FileKind,\n IsoDateTime,\n NonNegInt,\n PathFailureSchema,\n RequiredPath,\n} from '../core/schema.js';\nimport { getMaxTextFileSize } from '../core/util.js';\nimport { isTotalFailure, runOverPaths } from './batch.js';\nimport { defineTool } from './define.js';\n\nconst CreateFileItemSchema = z.strictObject({\n path: RequiredPath.describe('Absolute path where the file will be created'),\n content: z\n .string()\n .refine((val) => val.length <= getMaxTextFileSize(), {\n message: 'Content exceeds maximum allowed text file size',\n })\n .describe('Text content to write, verbatim.'),\n});\n\nconst CreateFileResultSchema = z.strictObject({\n path: z.string().describe('Resolved absolute path of the created file'),\n size: NonNegInt.describe('File size in bytes after writing'),\n lineCount: NonNegInt.describe('Number of lines in the written file'),\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 .describe('Resource URI pointing to the created file content in the resource store'),\n created: IsoDateTime.describe('File creation timestamp (ISO 8601 UTC)'),\n modified: IsoDateTime.describe('File last-modification timestamp (ISO 8601 UTC)'),\n});\n\nconst CreateInputSchema = z.strictObject({\n files: z\n .array(CreateFileItemSchema)\n .min(1)\n .max(100)\n .describe('List of files to create (max 100); each entry requires path and content'),\n});\n\ntype CreateFailureItem = z.infer<typeof PathFailureSchema>;\n\nconst CreateOutputSchema = z.strictObject({\n files: z.array(CreateFileResultSchema).describe('Successfully created files'),\n failures: z\n .array(PathFailureSchema)\n .optional()\n .describe('Files that failed to create with per-file error details'),\n});\n\ntype CreateFileResult = z.infer<typeof CreateFileResultSchema>;\n\nexport const CREATE = defineTool({\n name: 'create',\n title: 'Create Files',\n description:\n 'Create one or more files (max 100), writing or overwriting content and creating parent directories as needed. ' +\n 'Pass files: [{ path, content }] — there is no single-path form. ' +\n 'Silently overwrites existing files — read first if you need to preserve existing content.',\n input: CreateInputSchema,\n output: CreateOutputSchema,\n annotations: {\n readOnlyHint: false,\n idempotentHint: false,\n destructiveHint: true,\n openWorldHint: false,\n },\n accessPaths: (args) => args.files.map((f) => f.path),\n run: async (args, ctx) => {\n const batch = await runOverPaths<\n { content: string },\n { file: CreateFileResult; resourceLink?: ContentBlock }\n >(\n { files: args.files },\n ctx,\n async ({ path, override }) => {\n const content = override?.content ?? '';\n\n await ctx.fs.mkdir(dirname(path), { recursive: true });\n\n const { validPath } = await ctx.fs.writeFile(path, content, {\n encoding: 'utf-8',\n signal: ctx.signal,\n });\n\n const { stats: fileStats } = await ctx.fs.stat(path, { signal: ctx.signal });\n const bytesWritten = Buffer.byteLength(content, 'utf-8');\n const lineCount = countLines(content);\n const mimeInfo = detectMimeFromContent(validPath, content);\n\n const resourceUri = buildFileResourceUri(validPath);\n const file: CreateFileResult = {\n path: validPath,\n size: bytesWritten,\n lineCount,\n mimeType: mimeInfo.mimeType,\n kind: mimeInfo.kind,\n resourceUri,\n created: fileStats.birthtime.toISOString(),\n modified: fileStats.mtime.toISOString(),\n };\n\n return ctx.resourceStore\n ? {\n file,\n resourceLink: buildFileResourceLink(validPath, mimeInfo.mimeType, bytesWritten),\n }\n : { file };\n },\n { defaultErrorCode: ErrorCode.UNKNOWN },\n );\n\n const results: CreateFileResult[] = [];\n const failures: CreateFailureItem[] = [];\n const links: ContentBlock[] = [];\n for (const r of batch.results) {\n if ('error' in r) {\n failures.push({ path: r.path, error: r.error });\n continue;\n }\n results.push(r.value.file);\n if (r.value.resourceLink) links.push(r.value.resourceLink);\n }\n\n const structured = {\n files: results,\n ...(failures.length > 0 ? { failures } : {}),\n };\n // No `text` on purpose. The one-line roster this used to build named the\n // paths and dropped every per-file size, line count and error the caller\n // asked `create` for. Supplying no text makes this a data tool, so\n // `define.ts` renders the JSON and keeps it in `structuredContent`.\n if (links.length > 0) {\n return { structured, resources: links, isError: isTotalFailure(batch.summary) };\n }\n\n return { structured, isError: isTotalFailure(batch.summary) };\n },\n progress: (args) => ({\n label: 'Create',\n subject:\n args.files.length === 1\n ? basename(args.files[0]?.path ?? '')\n : `${String(args.files.length)} files`,\n }),\n defaultErrorCode: ErrorCode.UNKNOWN,\n});\n"]}
1
+ {"version":3,"file":"create.js","sourceRoot":"","sources":["../../src/tools/create.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE9C,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAE5B,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EACL,QAAQ,EACR,WAAW,EACX,SAAS,EACT,iBAAiB,EACjB,YAAY,GACb,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,MAAM,oBAAoB,GAAG,CAAC,CAAC,YAAY,CAAC;IAC1C,IAAI,EAAE,YAAY,CAAC,QAAQ,CAAC,8CAA8C,CAAC;IAC3E,OAAO,EAAE,CAAC;SACP,MAAM,EAAE;SACR,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,IAAI,kBAAkB,E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AAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC7C,CAAC;QACF,yEAAyE;QACzE,yEAAyE;QACzE,mEAAmE;QACnE,oEAAoE;QACpE,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACrB,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,cAAc,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;QAClF,CAAC;QAED,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,cAAc,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;IAChE,CAAC;IACD,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QACnB,KAAK,EAAE,QAAQ;QACf,OAAO,EACL,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC;YACrB,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,IAAI,IAAI,EAAE,CAAC;YACrC,CAAC,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ;KAC3C,CAAC;IACF,gBAAgB,EAAE,SAAS,CAAC,OAAO;CACpC,CAAC,CAAC","sourcesContent":["import type { ContentBlock } from '@modelcontextprotocol/server';\n\nimport { basename, dirname } from 'node:path';\n\nimport * as z from 'zod/v4';\n\nimport { ErrorCode } from '../core/errors.js';\nimport { buildWrittenFileMeta } from '../core/file-uri.js';\nimport {\n FileKind,\n IsoDateTime,\n NonNegInt,\n PathFailureSchema,\n RequiredPath,\n} from '../core/schema.js';\nimport { getMaxTextFileSize } from '../core/util.js';\nimport { isTotalFailure, runOverPaths } from './batch.js';\nimport { defineTool } from './define.js';\n\nconst CreateFileItemSchema = z.strictObject({\n path: RequiredPath.describe('Absolute path where the file will be created'),\n content: z\n .string()\n .refine((val) => val.length <= getMaxTextFileSize(), {\n message: 'Content exceeds maximum allowed text file size',\n })\n .describe('Text content to write, verbatim.'),\n});\n\nconst CreateFileResultSchema = z.strictObject({\n path: z.string().describe('Resolved absolute path of the created file'),\n size: NonNegInt.describe('File size in bytes after writing'),\n lineCount: NonNegInt.describe('Number of lines in the written file'),\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 .describe('Resource URI pointing to the created file content in the resource store'),\n created: IsoDateTime.describe('File creation timestamp (ISO 8601 UTC)'),\n modified: IsoDateTime.describe('File last-modification timestamp (ISO 8601 UTC)'),\n});\n\nconst CreateInputSchema = z.strictObject({\n files: z\n .array(CreateFileItemSchema)\n .min(1)\n .max(100)\n .describe('List of files to create (max 100); each entry requires path and content'),\n});\n\ntype CreateFailureItem = z.infer<typeof PathFailureSchema>;\n\nconst CreateOutputSchema = z.strictObject({\n files: z.array(CreateFileResultSchema).describe('Successfully created files'),\n failures: z\n .array(PathFailureSchema)\n .optional()\n .describe('Files that failed to create with per-file error details'),\n});\n\ntype CreateFileResult = z.infer<typeof CreateFileResultSchema>;\n\nexport const CREATE = defineTool({\n name: 'create',\n title: 'Create Files',\n description:\n 'Create one or more files (max 100), writing or overwriting content and creating parent directories as needed. ' +\n 'Pass files: [{ path, content }] — there is no single-path form. ' +\n 'Silently overwrites existing files — read first if you need to preserve existing content.',\n input: CreateInputSchema,\n output: CreateOutputSchema,\n annotations: {\n readOnlyHint: false,\n idempotentHint: false,\n destructiveHint: true,\n openWorldHint: false,\n },\n accessPaths: (args) => args.files.map((f) => f.path),\n run: async (args, ctx) => {\n const batch = await runOverPaths<\n { content: string },\n { file: CreateFileResult; resourceLink?: ContentBlock }\n >(\n { files: args.files },\n ctx,\n async ({ path, override }) => {\n const content = override?.content ?? '';\n\n await ctx.fs.mkdir(dirname(path), { recursive: true });\n\n const { validPath } = await ctx.fs.writeFile(path, content, {\n encoding: 'utf-8',\n signal: ctx.signal,\n });\n\n const { stats: fileStats } = await ctx.fs.stat(path, { signal: ctx.signal });\n const meta = buildWrittenFileMeta(validPath, content, ctx.resourceStore);\n\n const file: CreateFileResult = {\n path: validPath,\n size: meta.size,\n lineCount: meta.lineCount,\n mimeType: meta.mimeType,\n kind: meta.kind,\n resourceUri: meta.resourceUri,\n created: fileStats.birthtime.toISOString(),\n modified: fileStats.mtime.toISOString(),\n };\n\n return meta.resourceLink ? { file, resourceLink: meta.resourceLink } : { file };\n },\n { defaultErrorCode: ErrorCode.UNKNOWN },\n );\n\n const results: CreateFileResult[] = [];\n const failures: CreateFailureItem[] = [];\n const links: ContentBlock[] = [];\n for (const r of batch.results) {\n if ('error' in r) {\n failures.push({ path: r.path, error: r.error });\n continue;\n }\n results.push(r.value.file);\n if (r.value.resourceLink) links.push(r.value.resourceLink);\n }\n\n const structured = {\n files: results,\n ...(failures.length > 0 ? { failures } : {}),\n };\n // No `text` on purpose. The one-line roster this used to build named the\n // paths and dropped every per-file size, line count and error the caller\n // asked `create` for. Supplying no text makes this a data tool, so\n // `define.ts` renders the JSON and keeps it in `structuredContent`.\n if (links.length > 0) {\n return { structured, resources: links, isError: isTotalFailure(batch.summary) };\n }\n\n return { structured, isError: isTotalFailure(batch.summary) };\n },\n progress: (args) => ({\n label: 'Create',\n subject:\n args.files.length === 1\n ? basename(args.files[0]?.path ?? '')\n : `${String(args.files.length)} files`,\n }),\n defaultErrorCode: ErrorCode.UNKNOWN,\n});\n"]}
@@ -1,4 +1,4 @@
1
- import type { AuthInfo, ClientCapabilities, ContentBlock, InputRequiredResult, McpServer, Notification, RegisteredTool, RequestMeta, RequestStateAccessor, ToolAnnotations } from '@modelcontextprotocol/server';
1
+ import type { ClientCapabilities, ContentBlock, InputRequiredResult, McpServer, Notification, RegisteredTool, RequestMeta, RequestStateAccessor, ToolAnnotations } from '@modelcontextprotocol/server';
2
2
  import * as z from 'zod/v4';
3
3
  import { ErrorCode } from '../core/errors.js';
4
4
  import type { ProgressCtx } from '../core/fmt.js';
@@ -9,8 +9,6 @@ import type { PathGuard } from '../core/path.js';
9
9
  import type { ResourceStore } from '../core/store.js';
10
10
  export interface ToolCtx {
11
11
  readonly signal: AbortSignal;
12
- readonly sessionId?: string;
13
- readonly authInfo?: AuthInfo;
14
12
  readonly _meta?: RequestMeta | undefined;
15
13
  readonly fs: GuardedFileSystem;
16
14
  readonly pageStore: PageSnapshotStore;
@@ -49,7 +47,6 @@ export interface ToolCtx {
49
47
  * all. `undefined` means "cannot tell" — never "no capabilities".
50
48
  */
51
49
  readonly clientCapabilities?: ClientCapabilities | undefined;
52
- readonly server?: McpServer;
53
50
  }
54
51
  interface ToolDeps {
55
52
  readonly server: McpServer;
@@ -1 +1 @@
1
- {"version":3,"file":"define.d.ts","sourceRoot":"","sources":["../../src/tools/define.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EAER,kBAAkB,EAClB,YAAY,EACZ,mBAAmB,EAInB,SAAS,EACT,YAAY,EACZ,cAAc,EACd,WAAW,EACX,oBAAoB,EAEpB,eAAe,EAChB,MAAM,8BAA8B,CAAC;AAOtC,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAE5B,OAAO,EAAE,SAAS,EAAsC,MAAM,mBAAmB,CAAC;AAClF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAElD,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAQlD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE/D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAGtD,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAA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CACZ,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAChB,GAAG,EAAE,OAAO,KACT,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,mBAAmB,CAAC,CAAC;CAC3D;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,EAAE,mBAAmB,CAAC;IAE1C,QAAQ,CAAC,IAAI,EAAE,QAAQ,GAAG,cAAc,CAAC;CAC1C;AAiVD,wBAAgB,UAAU,CAAC,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,CAAC,SAAS,CAAC,CAAC,OAAO,EACjE,GAAG,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,GACjB,WAAW,CA4Cb"}
@@ -8,16 +8,6 @@ import { Logger } from '../core/observability.js';
8
8
  import { isSamePath } from '../core/path-utils.js';
9
9
  import { McpProgressSink, ProgressSession } from './progress.js';
10
10
  function toToolCtx(ctx, deps) {
11
- if (!ctx) {
12
- const signal = new AbortController().signal;
13
- return {
14
- signal,
15
- fs: new GuardedFileSystem(deps.pathGuard),
16
- pageStore: deps.pageStore,
17
- resourceStore: deps.resourceStore,
18
- server: deps.server,
19
- };
20
- }
21
11
  // Envelope first, accessor second — the two eras carry this differently.
22
12
  // A modern request states the capabilities in its own `_meta` envelope; a
23
13
  // legacy connection fixed them at `initialize` and has no envelope at all.
@@ -36,8 +26,6 @@ function toToolCtx(ctx, deps) {
36
26
  deps.server.server.getClientCapabilities();
37
27
  return {
38
28
  signal: ctx.mcpReq.signal,
39
- ...(ctx.sessionId ? { sessionId: ctx.sessionId } : {}),
40
- ...(ctx.http?.authInfo ? { authInfo: ctx.http.authInfo } : {}),
41
29
  ...(ctx.mcpReq._meta ? { _meta: ctx.mcpReq._meta } : {}),
42
30
  fs: new GuardedFileSystem(deps.pathGuard),
43
31
  pageStore: deps.pageStore,
@@ -46,19 +34,10 @@ function toToolCtx(ctx, deps) {
46
34
  inputResponses: ctx.mcpReq.inputResponses,
47
35
  requestState: ctx.mcpReq.requestState,
48
36
  ...(clientCapabilities ? { clientCapabilities } : {}),
49
- server: deps.server,
50
37
  };
51
38
  }
52
39
  function resolveProgressCtx(def, args) {
53
- if (!def.progress)
54
- return { label: def.title };
55
- try {
56
- return def.progress(args);
57
- }
58
- catch (err) {
59
- Logger.warn(`resolveProgressCtx: ${def.name}.progress threw: ${String(err)}`);
60
- return { label: def.title };
61
- }
40
+ return def.progress ? def.progress(args) : { label: def.title };
62
41
  }
63
42
  function composeSignal(base, timeoutMs) {
64
43
  if (!timeoutMs)