get_local_image_size
Retrieve the dimensions of a local image by providing its absolute file path, enabling quick access to width and height details.
Instructions
Get the size of a local image
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| options | Yes | Options for retrieving local image size |
Implementation Reference
- src/tools/imageSize.ts:17-38 (handler)The core handler function that implements the logic for getting the size of a local image file using probe-image-size library. It checks file existence, reads the file into buffer, probes synchronously, and returns width, height, type, mime, and path.export async function getLocalImageSize(imagePath: string) { // 检查文件是否存在 if (!fs.existsSync(imagePath)) { throw new Error(`文件不存在: ${imagePath}`); } // 使用Buffer(同步方法) const imageBuffer = fs.readFileSync(imagePath); const result = probe.sync(imageBuffer); if (!result) { throw new Error(`无法识别图片格式: ${imagePath}`); } return { width: result.width, height: result.height, type: result.type, mime: result.mime, path: imagePath, }; }
- src/server.ts:201-230 (registration)The MCP server.tool registration block for the 'get_local_image_size' tool, including schema, description, and the wrapper async function that calls the core handler `getLocalImageSize`.server.tool( "get_local_image_size", "Get the size of a local image", { options: z .object({ imagePath: z.string().describe("Absolute path to the local image"), }) .describe("Options for retrieving local image size"), }, async ({ options = {} }) => { try { const { imagePath } = options as { imagePath: string }; // Call tool function implementation const result = await getLocalImageSize(imagePath); return { content: [ { type: "text" as const, text: JSON.stringify(result, null, 2), }, ], }; } catch (error) { throw new Error( `Failed to get local image size: ${(error as Error).message}`, ); } }, );
- src/server.ts:57-63 (schema)The input schema (Zod) definition for 'get_local_image_size' in the server's capabilities declaration.get_local_image_size: { options: z .object({ imagePath: z.string().describe("Absolute path to the local image"), }) .describe("Options for retrieving local image size"), },
- src/server.ts:21-21 (registration)Initial inclusion of 'get_local_image_size' in the set of available tools.const availableTools = new Set(["get_image_size", "get_local_image_size"]);
- src/server.ts:6-12 (helper)Import of the getLocalImageSize handler from tools/index.js.import { getImageSizeFromUrl, getLocalImageSize, compressImageFromUrl, compressLocalImage, getFigmaImages, } from "./tools/index.js";