Skip to content

Commit 55c3a31

Browse files
authored
fix(filesystem): address review feedback from #3016 (#3031)
Address two items from Camila's review: 1. Use blob type for non-image/non-audio media files, restoring the original behavior. This matches the previous implementation which used blob as the fallback for unknown binary types. Use type assertion to satisfy the SDK's type constraints. 2. Reuse ReadTextFileArgsSchema.shape in the deprecated read_file tool instead of redefining the schema inline.
1 parent b846373 commit 55c3a31

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

src/filesystem/index.ts

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
44
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
55
import {
6+
CallToolResult,
67
RootsListChangedNotificationSchema,
78
type Root,
89
} from "@modelcontextprotocol/sdk/types.js";
@@ -199,11 +200,7 @@ server.registerTool(
199200
{
200201
title: "Read File (Deprecated)",
201202
description: "Read the complete contents of a file as text. DEPRECATED: Use read_text_file instead.",
202-
inputSchema: {
203-
path: z.string(),
204-
tail: z.number().optional().describe("If provided, returns only the last N lines of the file"),
205-
head: z.number().optional().describe("If provided, returns only the first N lines of the file")
206-
},
203+
inputSchema: ReadTextFileArgsSchema.shape,
207204
outputSchema: {
208205
content: z.array(z.object({
209206
type: z.literal("text"),
@@ -253,7 +250,7 @@ server.registerTool(
253250
},
254251
outputSchema: {
255252
content: z.array(z.object({
256-
type: z.enum(["image", "audio"]),
253+
type: z.enum(["image", "audio", "blob"]),
257254
data: z.string(),
258255
mimeType: z.string()
259256
}))
@@ -278,17 +275,15 @@ server.registerTool(
278275
const mimeType = mimeTypes[extension] || "application/octet-stream";
279276
const data = await readFileAsBase64Stream(validPath);
280277

281-
if (mimeType.startsWith("audio/")) {
282-
return {
283-
content: [{ type: "audio" as const, data, mimeType }],
284-
};
285-
} else {
286-
// For all other media types including images and unknown types, return as image
287-
// (MCP ImageContent can handle any base64-encoded binary data with appropriate mimeType)
288-
return {
289-
content: [{ type: "image" as const, data, mimeType }],
290-
};
291-
}
278+
const type = mimeType.startsWith("image/")
279+
? "image"
280+
: mimeType.startsWith("audio/")
281+
? "audio"
282+
// Fallback for other binary types, not officially supported by the spec but has been used for some time
283+
: "blob";
284+
return {
285+
content: [{ type, data, mimeType }],
286+
} as unknown as CallToolResult;
292287
}
293288
);
294289

0 commit comments

Comments
 (0)