Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 12 additions & 17 deletions src/filesystem/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import {
CallToolResult,
RootsListChangedNotificationSchema,
type Root,
} from "@modelcontextprotocol/sdk/types.js";
Expand Down Expand Up @@ -199,11 +200,7 @@ server.registerTool(
{
title: "Read File (Deprecated)",
description: "Read the complete contents of a file as text. DEPRECATED: Use read_text_file instead.",
inputSchema: {
path: z.string(),
tail: z.number().optional().describe("If provided, returns only the last N lines of the file"),
head: z.number().optional().describe("If provided, returns only the first N lines of the file")
},
inputSchema: ReadTextFileArgsSchema.shape,
outputSchema: {
content: z.array(z.object({
type: z.literal("text"),
Expand Down Expand Up @@ -253,7 +250,7 @@ server.registerTool(
},
outputSchema: {
content: z.array(z.object({
type: z.enum(["image", "audio"]),
type: z.enum(["image", "audio", "blob"]),
data: z.string(),
mimeType: z.string()
}))
Expand All @@ -278,17 +275,15 @@ server.registerTool(
const mimeType = mimeTypes[extension] || "application/octet-stream";
const data = await readFileAsBase64Stream(validPath);

if (mimeType.startsWith("audio/")) {
return {
content: [{ type: "audio" as const, data, mimeType }],
};
} else {
// For all other media types including images and unknown types, return as image
// (MCP ImageContent can handle any base64-encoded binary data with appropriate mimeType)
return {
content: [{ type: "image" as const, data, mimeType }],
};
}
const type = mimeType.startsWith("image/")
? "image"
: mimeType.startsWith("audio/")
? "audio"
// Fallback for other binary types, not officially supported by the spec but has been used for some time
: "blob";
return {
content: [{ type, data, mimeType }],
} as unknown as CallToolResult;
}
);

Expand Down