orientation
Extract image orientation values (1-8) from EXIF metadata to determine correct display rotation for images from files, URLs, or encoded data.
Instructions
Get image orientation value (1-8)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| image | Yes |
Implementation Reference
- src/tools/index.ts:181-195 (handler)The handler function that executes the 'orientation' tool logic: loads the image into a buffer, extracts the orientation value (1-8) using exifr.orientation, and returns a success response with the value or an appropriate error.async (args, extra) => { try { const { image } = args; const buf = await loadImage(image); const orientation = await exifr.orientation(buf); if (orientation === undefined) { return createErrorResponse('No orientation metadata found in image'); } return createSuccessResponse({ orientation }); } catch (error) { return createErrorResponse(`Error reading orientation: ${error instanceof Error ? error.message : String(error)}`); } }
- src/tools/index.ts:54-60 (schema)Zod input schema for the 'image' parameter, defining supported source kinds (path, url, base64, buffer) used by the 'orientation' tool.const ImageSourceSchema = z.object({ kind: z.enum(['path', 'url', 'base64', 'buffer']), path: z.string().optional(), url: z.string().optional(), data: z.string().optional(), buffer: z.string().optional() });
- src/tools/index.ts:176-197 (registration)Registers the 'orientation' tool with the MCP server via server.tool(), providing name, description, input schema, and handler function. Also stores reference for testing.const orientationTool = server.tool('orientation', "Get image orientation value (1-8)", { image: ImageSourceSchema }, async (args, extra) => { try { const { image } = args; const buf = await loadImage(image); const orientation = await exifr.orientation(buf); if (orientation === undefined) { return createErrorResponse('No orientation metadata found in image'); } return createSuccessResponse({ orientation }); } catch (error) { return createErrorResponse(`Error reading orientation: ${error instanceof Error ? error.message : String(error)}`); } } ); tools['orientation'] = orientationTool;