@j0hanz/filesystem-mcp 1.19.1 → 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 -585
  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 -473
  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
@@ -1,195 +0,0 @@
1
- import { hash, randomUUID } from 'node:crypto';
2
- import { channel } from 'node:diagnostics_channel';
3
- import { ErrorCode, McpError } from './errors.js';
4
- const DEFAULT_RESOURCE_STORE_OPTIONS = {
5
- maxEntries: 64,
6
- maxTotalBytes: 25 * 1024 * 1024,
7
- maxEntryBytes: 10 * 1024 * 1024,
8
- entryTtlMs: 30 * 60 * 1000, // 30 minutes
9
- };
10
- const RESOURCE_STORE_DIAGNOSTICS_CHANNEL = channel('filesystem-mcp:resource-store');
11
- function publishResourceStoreDiagnostics(event) {
12
- if (!RESOURCE_STORE_DIAGNOSTICS_CHANNEL.hasSubscribers)
13
- return;
14
- RESOURCE_STORE_DIAGNOSTICS_CHANNEL.publish(event);
15
- }
16
- function estimateBytes(text) {
17
- return Buffer.byteLength(text, 'utf8');
18
- }
19
- function computeSha256(text) {
20
- return hash('sha256', text, 'hex');
21
- }
22
- function buildIndexKey(mimeType, contentHash) {
23
- return `${mimeType}:${contentHash}`;
24
- }
25
- function isExpired(entry, now = Date.now()) {
26
- const expiresAt = Date.parse(entry.expiresAt);
27
- return Number.isFinite(expiresAt) && expiresAt <= now;
28
- }
29
- function createTextEntry(params) {
30
- const storedAt = new Date();
31
- return {
32
- uri: params.uri,
33
- name: params.name,
34
- mimeType: params.mimeType,
35
- text: params.text,
36
- hash: computeSha256(params.text),
37
- size: estimateBytes(params.text),
38
- storedAt: storedAt.toISOString(),
39
- expiresAt: new Date(storedAt.getTime() + params.ttlMs).toISOString(),
40
- };
41
- }
42
- export function createInMemoryResourceStore(options = {}) {
43
- const resolved = {
44
- ...DEFAULT_RESOURCE_STORE_OPTIONS,
45
- ...options,
46
- };
47
- const byUri = new Map();
48
- const byHashIndex = new Map(); // mimeType:sha256hex -> uri
49
- let totalBytes = 0;
50
- function removeEntry(uri, reason) {
51
- const existing = byUri.get(uri);
52
- if (!existing)
53
- return;
54
- totalBytes -= existing.size;
55
- byUri.delete(uri);
56
- byHashIndex.delete(buildIndexKey(existing.mimeType, existing.hash));
57
- publishResourceStoreDiagnostics({
58
- phase: 'cache_evict',
59
- uri,
60
- name: existing.name,
61
- bytes: existing.size,
62
- ...(reason !== undefined ? { reason } : {}),
63
- });
64
- }
65
- function evictOldest() {
66
- const first = byUri.keys().next();
67
- if (first.done)
68
- return;
69
- removeEntry(first.value);
70
- }
71
- function pruneExpiredEntries(now = Date.now()) {
72
- for (const [uri, entry] of byUri) {
73
- if (isExpired(entry, now)) {
74
- removeEntry(uri, 'expired');
75
- }
76
- }
77
- }
78
- function enforceLimits() {
79
- while (byUri.size > resolved.maxEntries)
80
- evictOldest();
81
- while (totalBytes > resolved.maxTotalBytes) {
82
- if (byUri.size === 0)
83
- break;
84
- evictOldest();
85
- }
86
- }
87
- function putText(params) {
88
- pruneExpiredEntries();
89
- const mimeType = params.mimeType ?? 'text/plain';
90
- const entryBytes = estimateBytes(params.text);
91
- if (entryBytes > resolved.maxEntryBytes) {
92
- publishResourceStoreDiagnostics({
93
- phase: 'cache_reject',
94
- bytes: entryBytes,
95
- reason: 'entry_too_large',
96
- });
97
- throw new McpError(ErrorCode.TOO_LARGE, `Resource too large to cache (${entryBytes} bytes).`);
98
- }
99
- const contentHash = computeSha256(params.text);
100
- const indexKey = buildIndexKey(mimeType, contentHash);
101
- const existingUri = byHashIndex.get(indexKey);
102
- if (existingUri !== undefined) {
103
- const cached = byUri.get(existingUri);
104
- if (cached !== undefined) {
105
- if (isExpired(cached)) {
106
- removeEntry(existingUri, 'expired');
107
- }
108
- else {
109
- publishResourceStoreDiagnostics({
110
- phase: 'cache_hit',
111
- uri: cached.uri,
112
- name: cached.name,
113
- bytes: cached.size,
114
- });
115
- return cached;
116
- }
117
- }
118
- else {
119
- byHashIndex.delete(indexKey);
120
- }
121
- }
122
- const id = randomUUID();
123
- const uri = `filesystem-mcp://result/${id}`;
124
- const entry = createTextEntry({
125
- uri,
126
- name: params.name,
127
- mimeType,
128
- text: params.text,
129
- ttlMs: resolved.entryTtlMs,
130
- });
131
- byUri.set(uri, entry);
132
- byHashIndex.set(indexKey, uri);
133
- totalBytes += entryBytes;
134
- publishResourceStoreDiagnostics({
135
- phase: 'cache_store',
136
- uri: entry.uri,
137
- name: entry.name,
138
- bytes: entry.size,
139
- });
140
- enforceLimits();
141
- if (!byUri.has(uri)) {
142
- publishResourceStoreDiagnostics({
143
- phase: 'cache_reject',
144
- uri,
145
- name: entry.name,
146
- bytes: entry.size,
147
- reason: 'evicted_immediately',
148
- });
149
- throw new McpError(ErrorCode.TOO_LARGE, 'Cache full: entry evicted.');
150
- }
151
- return entry;
152
- }
153
- function getText(uri) {
154
- const existing = byUri.get(uri);
155
- if (!existing) {
156
- publishResourceStoreDiagnostics({
157
- phase: 'cache_miss',
158
- uri,
159
- reason: 'not_found',
160
- });
161
- throw new McpError(ErrorCode.NOT_FOUND, `Resource not found: ${uri}. Re-run the tool to regenerate.`);
162
- }
163
- if (isExpired(existing)) {
164
- removeEntry(uri, 'expired');
165
- publishResourceStoreDiagnostics({
166
- phase: 'cache_miss',
167
- uri,
168
- reason: 'expired',
169
- });
170
- throw new McpError(ErrorCode.NOT_FOUND, `Resource expired: ${uri}. Re-run the tool to regenerate.`);
171
- }
172
- publishResourceStoreDiagnostics({
173
- phase: 'cache_hit',
174
- uri: existing.uri,
175
- name: existing.name,
176
- bytes: existing.size,
177
- });
178
- return existing;
179
- }
180
- function clear() {
181
- const bytesBeforeClear = totalBytes;
182
- byUri.clear();
183
- byHashIndex.clear();
184
- totalBytes = 0;
185
- publishResourceStoreDiagnostics({
186
- phase: 'cache_clear',
187
- bytes: bytesBeforeClear,
188
- });
189
- }
190
- function keys() {
191
- pruneExpiredEntries();
192
- return Array.from(byUri.keys());
193
- }
194
- return { putText, getText, clear, keys };
195
- }
@@ -1,7 +0,0 @@
1
- export declare function isRecord(value: unknown): value is Record<string, unknown>;
2
- export declare function debounce<Args extends unknown[]>(func: (...args: Args) => void, waitMs: number): {
3
- (...args: Args): void;
4
- cancel: () => void;
5
- };
6
- export declare function mergeOptions<T extends object>(defaults: T, overrides: Partial<T>): T;
7
- export declare function omitOptionKeys<T extends object, K extends keyof T>(input: T, keys: readonly K[]): Omit<T, K>;
package/dist/lib/utils.js DELETED
@@ -1,37 +0,0 @@
1
- // type-guards.ts
2
- export function isRecord(value) {
3
- return value !== null && typeof value === 'object';
4
- }
5
- // debounce
6
- export function debounce(func, waitMs) {
7
- let timeoutId;
8
- const debounced = (...args) => {
9
- if (timeoutId !== undefined) {
10
- clearTimeout(timeoutId);
11
- }
12
- timeoutId = setTimeout(() => {
13
- timeoutId = undefined;
14
- func(...args);
15
- }, waitMs);
16
- // Unref if in Node environment to not block process exit
17
- timeoutId.unref();
18
- };
19
- debounced.cancel = () => {
20
- if (timeoutId !== undefined) {
21
- clearTimeout(timeoutId);
22
- timeoutId = undefined;
23
- }
24
- };
25
- return debounced;
26
- }
27
- // option-utils.ts
28
- export function mergeOptions(defaults, overrides) {
29
- return { ...defaults, ...overrides };
30
- }
31
- export function omitOptionKeys(input, keys) {
32
- const output = { ...input };
33
- for (const key of keys) {
34
- Reflect.deleteProperty(output, key);
35
- }
36
- return output;
37
- }
@@ -1,2 +0,0 @@
1
- import { z } from 'zod';
2
- export declare function createBase64JsonCodec<Schema extends z.ZodType>(schema: Schema): z.ZodCodec<z.ZodString, Schema>;
@@ -1,18 +0,0 @@
1
- import { z } from 'zod';
2
- export function createBase64JsonCodec(schema) {
3
- return z.codec(z.string(), schema, {
4
- decode: (value) => {
5
- let parsed;
6
- try {
7
- parsed = JSON.parse(Buffer.from(value, 'base64url').toString('utf-8'));
8
- }
9
- catch (error) {
10
- throw new Error('Invalid base64url-encoded JSON payload.', {
11
- cause: error,
12
- });
13
- }
14
- return parsed;
15
- },
16
- encode: (value) => Buffer.from(JSON.stringify(value)).toString('base64url'),
17
- });
18
- }
@@ -1,7 +0,0 @@
1
- export declare const pkgInfo: {
2
- [x: string]: unknown;
3
- name: string;
4
- version: string;
5
- description?: string | undefined;
6
- homepage?: string | undefined;
7
- };
package/dist/pkg-info.js DELETED
@@ -1,9 +0,0 @@
1
- import { z } from 'zod';
2
- import packageJsonRaw from '../package.json' with { type: 'json' };
3
- const PkgInfoSchema = z.looseObject({
4
- name: z.string(),
5
- version: z.string(),
6
- description: z.string().optional(),
7
- homepage: z.url().optional(),
8
- });
9
- export const pkgInfo = PkgInfoSchema.parse(packageJsonRaw);
@@ -1 +0,0 @@
1
- export declare function buildServerInstructions(): string;
@@ -1,105 +0,0 @@
1
- import { buildToolCatalogDetailsOnly } from './tool-catalog.js';
2
- import { buildCoreContextPack, formatToolNameList, getSharedConstraints, getToolContracts, pickAvailableToolNames, } from './tool-info.js';
3
- import { buildWorkflowGuide } from './workflows.js';
4
- function buildToolsOverview() {
5
- const rows = [
6
- ['Navigate', pickAvailableToolNames(['roots', 'ls', 'tree', 'find'])],
7
- [
8
- 'Inspect',
9
- pickAvailableToolNames(['stat', 'stat_many', 'grep', 'calculate_hash']),
10
- ],
11
- ['Read', pickAvailableToolNames(['read', 'read_many', 'diff_files'])],
12
- [
13
- 'Write',
14
- pickAvailableToolNames([
15
- 'mkdir',
16
- 'write',
17
- 'edit',
18
- 'mv',
19
- 'rm',
20
- 'apply_patch',
21
- 'search_and_replace',
22
- ]),
23
- ],
24
- ];
25
- return rows
26
- .filter(([, names]) => names.length > 0)
27
- .map(([category, names]) => `| ${category} | ${formatToolNameList(names)} |`)
28
- .join('\n');
29
- }
30
- function buildInstructionsHeader() {
31
- return `## Role
32
-
33
- Secure filesystem agent. Operate strictly within allowed roots. Resolve paths before acting — never assume.
34
-
35
- ## Tools Overview
36
-
37
- | Category | Tools |
38
- | -------- | ----- |
39
-
40
- ${buildToolsOverview()}
41
-
42
- ## Resources
43
-
44
- | URI | Purpose |
45
- | -------------------------------- | -------------------------------------------------------------- |
46
- | \`internal://instructions\` | Full usage reference (this document) |
47
- | \`internal://tool-catalog\` | Tool routing, data flow, and selection guide |
48
- | \`internal://workflows\` | Step-by-step execution sequences |
49
- | \`internal://tool-info/{name}\` | Per-tool contract (e.g. \`internal://tool-info/read\`) |
50
- | \`filesystem-mcp://result/{id}\` | Cached large output — fetch via \`resources/read\` immediately |
51
- | \`filesystem-mcp://metrics\` | Per-tool call count, error rate, and avg duration |
52
-
53
- ## Task Protocol
54
-
55
- - Check \`execution.taskSupport\` before sending task metadata.
56
- - \`forbidden\` (default): Do not send \`task\`.
57
- - \`optional\`: Send \`task\` only when durable polling or deferred retrieval is needed.
58
- - \`required\`: Always send \`task\`.
59
- - Poll status via \`tasks/get\`, retrieve final payload via \`tasks/result\`.
60
- - Pass \`_meta.progressToken\` in \`tools/call\` to receive \`notifications/progress\`.
61
- `;
62
- }
63
- const INSTRUCTIONS_FOOTER = `## Constraints
64
-
65
- ${getSharedConstraints()
66
- .map((c) => `- ${c}`)
67
- .join('\n')}
68
-
69
- ## Error Recovery
70
-
71
- | Error Code | Action |
72
- | ------------------- | ------------------------------------------------------------------------- |
73
- | \`ACCESS_DENIED\` | Run \`roots\` to list allowed directories, retry with a valid path. |
74
- | \`NOT_FOUND\` | Run \`ls\` or \`find\` to verify the path. |
75
- | \`TOO_LARGE\` | Use \`head\`/\`tail\`, line ranges, or split across \`read_many\`. |
76
- | \`TIMEOUT\` | Reduce scope, depth, or maxResults. |
77
- | \`INVALID_INPUT\` | Re-read tool contract via \`internal://tool-info/{name}\`. |
78
- `;
79
- function formatToolSection(tool) {
80
- const parts = [`### ${tool.name}\n${tool.description}`];
81
- if (tool.nuances && tool.nuances.length > 0) {
82
- parts.push(...tool.nuances.map((n) => `- ${n}`));
83
- }
84
- if (tool.gotchas && tool.gotchas.length > 0) {
85
- parts.push(...tool.gotchas.map((g) => `- ⚠ ${g}`));
86
- }
87
- return parts.join('\n');
88
- }
89
- export function buildServerInstructions() {
90
- const toolSections = getToolContracts().map(formatToolSection).join('\n\n');
91
- return [
92
- buildInstructionsHeader(),
93
- buildCoreContextPack(),
94
- '',
95
- buildToolCatalogDetailsOnly(),
96
- '',
97
- '## Tool Reference',
98
- '',
99
- toolSections,
100
- '',
101
- buildWorkflowGuide(),
102
- '',
103
- INSTRUCTIONS_FOOTER,
104
- ].join('\n');
105
- }
@@ -1,2 +0,0 @@
1
- export declare function buildToolCatalog(): string;
2
- export declare function buildToolCatalogDetailsOnly(): string;
@@ -1,78 +0,0 @@
1
- import { buildCoreContextPack, getTaskCapableToolNames, pickAvailableToolNames, } from './tool-info.js';
2
- function buildCrossToolDataFlow() {
3
- const flows = [];
4
- if (pickAvailableToolNames(['find', 'read']).length === 2) {
5
- flows.push('find.results[].path -> read.path');
6
- }
7
- if (pickAvailableToolNames(['grep', 'read']).length === 2) {
8
- flows.push('grep.matches[].file -> read.path');
9
- }
10
- if (pickAvailableToolNames(['diff_files', 'apply_patch']).length === 2) {
11
- flows.push('diff_files.diff -> apply_patch.patch');
12
- }
13
- flows.push('toolResult.resourceUri -> resources/read.uri');
14
- return flows.join('\n');
15
- }
16
- function buildCatalogGuide() {
17
- const taskCapable = getTaskCapableToolNames();
18
- return `# Tool Selection Guide
19
-
20
- ## Primitive Routing
21
-
22
- | Primitive | Purpose |
23
- | -------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
24
- | \`tools\` | Model-controlled operations that inspect or mutate the filesystem within allowed roots. |
25
- | \`resources\` | Application-driven context: \`internal://instructions\`, \`internal://tool-info/{name}\`, cached \`filesystem-mcp://result/{id}\`. |
26
- | \`prompts\` | User-controlled workflow templates for help, comparison, and guided inspection. |
27
- | \`completion\` | Argument suggestions for prompts and resource templates (not a discovery mechanism). |
28
-
29
- ## Cross-Tool Data Flow
30
-
31
- \`\`\`
32
- ${buildCrossToolDataFlow()}
33
- \`\`\`
34
-
35
- ## Result Contract
36
-
37
- - Success: returns both \`content\` (JSON text) and \`structuredContent\` (when \`outputSchema\` is declared).
38
- - Error: \`isError: true\` in tool result, \`structuredContent\` omitted. Parse \`content\` text for error details.
39
- - Tool/business failures use \`isError: true\` inside the tool result, not JSON-RPC protocol errors.
40
- - When a response includes \`resourceUri\` or \`resource_link\`, follow up with \`resources/read\` immediately.
41
-
42
- ## Task Mode
43
-
44
- Use inline execution by default. Add task mode only when the caller needs durable polling, deferred retrieval, or cancellation.
45
-
46
- Task-capable tools: ${taskCapable.length > 0 ? taskCapable.map((name) => `\`${name}\``).join(', ') : 'none'}.
47
-
48
- ## Search Strategy
49
-
50
- | Goal | Tool |
51
- | ----------------------- | ------------------------------------------ |
52
- | Find files by name/glob | \`find\` |
53
- | Search file contents | \`grep\` |
54
- | Replace across files | \`search_and_replace\` (not for discovery) |
55
-
56
- ## Write Strategy
57
-
58
- | Scenario | Tool |
59
- | --------------------------- | ----------------------------------------------------- |
60
- | Single file, targeted edit | \`edit\` — match exact text, replace first occurrence |
61
- | Single file, full rewrite | \`write\` — overwrite entire content |
62
- | Multiple files, same change | \`search_and_replace\` — glob + pattern across files |
63
- | Unsure what to change | \`grep\` first, then decide |
64
-
65
- ## Patch Strategy
66
-
67
- 1. Generate with \`diff_files\`.
68
- 2. Validate with \`apply_patch(dryRun: true)\` before writing.
69
- 3. Apply with \`apply_patch\`.
70
- 4. Multi-file patches: set \`path\` to the base directory; results are per-file.
71
- `;
72
- }
73
- export function buildToolCatalog() {
74
- return `${buildCoreContextPack()}\n\n${buildCatalogGuide()}`;
75
- }
76
- export function buildToolCatalogDetailsOnly() {
77
- return buildCatalogGuide();
78
- }
@@ -1,9 +0,0 @@
1
- import type { ToolContract } from '../tools/contract.js';
2
- export declare function getToolContracts(): ToolContract[];
3
- export declare function getSortedToolContracts(): ToolContract[];
4
- export declare function pickAvailableToolNames(names: readonly string[]): string[];
5
- export declare function formatToolNameList(names: readonly string[]): string;
6
- export declare function getTaskCapableToolNames(): string[];
7
- export declare function buildCoreContextPack(): string;
8
- export declare function getSharedConstraints(): string[];
9
- export declare function buildToolInfo(name: string): string | undefined;