get_author_photo
Retrieve the URL for an author's photo by providing their Open Library Author ID (OLID). Use this tool to access visual profiles of authors for enhanced book-related searches.
Instructions
Get the URL for an author's photo using their Open Library Author ID (OLID e.g. OL23919A).
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| olid | Yes | The Open Library Author ID (OLID) for the author (e.g. OL23919A). |
Implementation Reference
- The main handler function that parses arguments using the schema, validates the OLID, constructs the photo URL from Open Library API, and returns it as text content.const handleGetAuthorPhoto = async (args: unknown): Promise<CallToolResult> => { const parseResult = GetAuthorPhotoArgsSchema.safeParse(args); if (!parseResult.success) { const errorMessages = parseResult.error.errors .map((e) => `${e.path.join(".")}: ${e.message}`) .join(", "); throw new McpError( ErrorCode.InvalidParams, `Invalid arguments for get_author_photo: ${errorMessages}`, ); } const olid = parseResult.data.olid; const photoUrl = `https://covers.openlibrary.org/a/olid/${olid}-L.jpg`; // Use -L for large size // Note: We don't actually fetch the image here, just return the URL. // The Open Library Covers API doesn't provide a way to check if an image exists // other than trying to fetch it. We assume the URL is correct if the OLID format is valid. return { content: [ { type: "text", text: photoUrl, }, ], }; // No try/catch needed here as we are just constructing a URL string based on validated input. };
- Zod schema defining and validating the 'olid' input parameter for the get_author_photo tool.export const GetAuthorPhotoArgsSchema = z.object({ olid: z .string() .min(1, { message: "OLID cannot be empty" }) .regex(/^OL\d+A$/, { // Escaped backslash for regex in string message: "OLID must be in the format OL<number>A", }), });
- src/index.ts:99-113 (registration)Tool registration in the listTools handler, providing name, description, and input schema for MCP discovery.{ name: "get_author_photo", description: "Get the URL for an author's photo using their Open Library Author ID (OLID e.g. OL23919A).", inputSchema: { type: "object", properties: { olid: { type: "string", description: "The Open Library Author ID (OLID) for the author (e.g. OL23919A).", }, }, required: ["olid"], },
- src/index.ts:176-177 (registration)Dispatcher in callTool handler that routes requests for 'get_author_photo' to the handler function.case "get_author_photo": return handleGetAuthorPhoto(args);
- src/index.ts:12-19 (registration)Import of the get_author_photo handler from the tools module.import { handleGetAuthorPhoto, handleGetBookByTitle, handleGetBookCover, handleGetAuthorsByName, handleGetAuthorInfo, handleGetBookById, } from "./tools/index.js";