Skip to content

Commit dd69258

Browse files
committed
feat(filesystem): add idempotentHint and openWorldHint annotations
Add idempotentHint: true to all 10 read-only tools (reads are inherently safe to retry) and openWorldHint: false to all 14 tools (all operations are scoped to allowed directories with no external side effects). Closes modelcontextprotocol#3402
1 parent f424458 commit dd69258

1 file changed

Lines changed: 14 additions & 14 deletions

File tree

‎src/filesystem/index.ts‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ server.registerTool(
217217
description: "Read the complete contents of a file as text. DEPRECATED: Use read_text_file instead.",
218218
inputSchema: ReadTextFileArgsSchema.shape,
219219
outputSchema: { content: z.string() },
220-
annotations: { readOnlyHint: true }
220+
annotations: { readOnlyHint: true, idempotentHint: true, openWorldHint: false }
221221
},
222222
readTextFileHandler
223223
);
@@ -240,7 +240,7 @@ server.registerTool(
240240
head: z.number().optional().describe("If provided, returns only the first N lines of the file")
241241
},
242242
outputSchema: { content: z.string() },
243-
annotations: { readOnlyHint: true }
243+
annotations: { readOnlyHint: true, idempotentHint: true, openWorldHint: false }
244244
},
245245
readTextFileHandler
246246
);
@@ -262,7 +262,7 @@ server.registerTool(
262262
mimeType: z.string()
263263
}))
264264
},
265-
annotations: { readOnlyHint: true }
265+
annotations: { readOnlyHint: true, idempotentHint: true, openWorldHint: false }
266266
},
267267
async (args: z.infer<typeof ReadMediaFileArgsSchema>) => {
268268
const validPath = await validatePath(args.path);
@@ -313,7 +313,7 @@ server.registerTool(
313313
.describe("Array of file paths to read. Each path must be a string pointing to a valid file within allowed directories.")
314314
},
315315
outputSchema: { content: z.string() },
316-
annotations: { readOnlyHint: true }
316+
annotations: { readOnlyHint: true, idempotentHint: true, openWorldHint: false }
317317
},
318318
async (args: z.infer<typeof ReadMultipleFilesArgsSchema>) => {
319319
const results = await Promise.all(
@@ -349,7 +349,7 @@ server.registerTool(
349349
content: z.string()
350350
},
351351
outputSchema: { content: z.string() },
352-
annotations: { readOnlyHint: false, idempotentHint: true, destructiveHint: true }
352+
annotations: { readOnlyHint: false, idempotentHint: true, destructiveHint: true, openWorldHint: false }
353353
},
354354
async (args: z.infer<typeof WriteFileArgsSchema>) => {
355355
const validPath = await validatePath(args.path);
@@ -379,7 +379,7 @@ server.registerTool(
379379
dryRun: z.boolean().default(false).describe("Preview changes using git-style diff format")
380380
},
381381
outputSchema: { content: z.string() },
382-
annotations: { readOnlyHint: false, idempotentHint: false, destructiveHint: true }
382+
annotations: { readOnlyHint: false, idempotentHint: false, destructiveHint: true, openWorldHint: false }
383383
},
384384
async (args: z.infer<typeof EditFileArgsSchema>) => {
385385
const validPath = await validatePath(args.path);
@@ -404,7 +404,7 @@ server.registerTool(
404404
path: z.string()
405405
},
406406
outputSchema: { content: z.string() },
407-
annotations: { readOnlyHint: false, idempotentHint: true, destructiveHint: false }
407+
annotations: { readOnlyHint: false, idempotentHint: true, destructiveHint: false, openWorldHint: false }
408408
},
409409
async (args: z.infer<typeof CreateDirectoryArgsSchema>) => {
410410
const validPath = await validatePath(args.path);
@@ -430,7 +430,7 @@ server.registerTool(
430430
path: z.string()
431431
},
432432
outputSchema: { content: z.string() },
433-
annotations: { readOnlyHint: true }
433+
annotations: { readOnlyHint: true, idempotentHint: true, openWorldHint: false }
434434
},
435435
async (args: z.infer<typeof ListDirectoryArgsSchema>) => {
436436
const validPath = await validatePath(args.path);
@@ -459,7 +459,7 @@ server.registerTool(
459459
sortBy: z.enum(["name", "size"]).optional().default("name").describe("Sort entries by name or size")
460460
},
461461
outputSchema: { content: z.string() },
462-
annotations: { readOnlyHint: true }
462+
annotations: { readOnlyHint: true, idempotentHint: true, openWorldHint: false }
463463
},
464464
async (args: z.infer<typeof ListDirectoryWithSizesArgsSchema>) => {
465465
const validPath = await validatePath(args.path);
@@ -538,7 +538,7 @@ server.registerTool(
538538
excludePatterns: z.array(z.string()).optional().default([])
539539
},
540540
outputSchema: { content: z.string() },
541-
annotations: { readOnlyHint: true }
541+
annotations: { readOnlyHint: true, idempotentHint: true, openWorldHint: false }
542542
},
543543
async (args: z.infer<typeof DirectoryTreeArgsSchema>) => {
544544
interface TreeEntry {
@@ -608,7 +608,7 @@ server.registerTool(
608608
destination: z.string()
609609
},
610610
outputSchema: { content: z.string() },
611-
annotations: { readOnlyHint: false, idempotentHint: false, destructiveHint: true }
611+
annotations: { readOnlyHint: false, idempotentHint: false, destructiveHint: true, openWorldHint: false }
612612
},
613613
async (args: z.infer<typeof MoveFileArgsSchema>) => {
614614
const validSourcePath = await validatePath(args.source);
@@ -639,7 +639,7 @@ server.registerTool(
639639
excludePatterns: z.array(z.string()).optional().default([])
640640
},
641641
outputSchema: { content: z.string() },
642-
annotations: { readOnlyHint: true }
642+
annotations: { readOnlyHint: true, idempotentHint: true, openWorldHint: false }
643643
},
644644
async (args: z.infer<typeof SearchFilesArgsSchema>) => {
645645
const validPath = await validatePath(args.path);
@@ -665,7 +665,7 @@ server.registerTool(
665665
path: z.string()
666666
},
667667
outputSchema: { content: z.string() },
668-
annotations: { readOnlyHint: true }
668+
annotations: { readOnlyHint: true, idempotentHint: true, openWorldHint: false }
669669
},
670670
async (args: z.infer<typeof GetFileInfoArgsSchema>) => {
671671
const validPath = await validatePath(args.path);
@@ -691,7 +691,7 @@ server.registerTool(
691691
"before trying to access files.",
692692
inputSchema: {},
693693
outputSchema: { content: z.string() },
694-
annotations: { readOnlyHint: true }
694+
annotations: { readOnlyHint: true, idempotentHint: true, openWorldHint: false }
695695
},
696696
async () => {
697697
const text = `Allowed directories:\n${allowedDirectories.join('\n')}`;

0 commit comments

Comments
 (0)