get_book_cover
Retrieve a book’s cover image URL by providing an identifier (ISBN, OCLC, LCCN, OLID, ID) and selecting the desired size (S, M, L).
Instructions
Get the URL for a book's cover image using a key (ISBN, OCLC, LCCN, OLID, ID) and value.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| key | Yes | The type of identifier used (ISBN, OCLC, LCCN, OLID, ID). | |
| size | No | The desired size of the cover (S, M, or L). | |
| value | Yes | The value of the identifier. |
Input Schema (JSON Schema)
{
"properties": {
"key": {
"description": "The type of identifier used (ISBN, OCLC, LCCN, OLID, ID).",
"enum": [
"ISBN",
"OCLC",
"LCCN",
"OLID",
"ID"
],
"type": "string"
},
"size": {
"description": "The desired size of the cover (S, M, or L).",
"enum": [
"S",
"M",
"L"
],
"type": "string"
},
"value": {
"description": "The value of the identifier.",
"type": "string"
}
},
"required": [
"key",
"value"
],
"type": "object"
}
Implementation Reference
- src/tools/get-book-cover/index.ts:18-45 (handler)Implements the core logic for the get_book_cover tool: validates input using Zod schema, constructs the Open Library cover image URL based on key (ISBN, OCLC, etc.), value, and size, and returns it as MCP content.const handleGetBookCover = async (args: unknown) => { const parseResult = GetBookCoverArgsSchema.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_book_cover: ${errorMessages}`, ); } const { key, value, size } = parseResult.data; // Construct the URL according to the Open Library Covers API format const coverUrl = `https://covers.openlibrary.org/b/${key.toLowerCase()}/${value}-${size}.jpg`; return { content: [ { type: "text", text: coverUrl, }, ], }; // No try/catch needed here as we are just constructing a URL string based on validated input. };
- Zod schema for input validation of get_book_cover tool arguments: key (ISBN/OCLC/etc.), value, optional size (defaults to L).// Schema for the get_book_cover tool arguments export const GetBookCoverArgsSchema = z.object({ key: z.enum(["ISBN", "OCLC", "LCCN", "OLID", "ID"], { errorMap: () => ({ message: "Key must be one of ISBN, OCLC, LCCN, OLID, ID", }), }), value: z.string().min(1, { message: "Value cannot be empty" }), size: z .nullable(z.enum(["S", "M", "L"])) .optional() .transform((val) => val || "L"), });
- src/index.ts:115-141 (registration)MCP tool registration: defines name, description, and JSON inputSchema for get_book_cover in the server's tool list.{ name: "get_book_cover", description: "Get the URL for a book's cover image using a key (ISBN, OCLC, LCCN, OLID, ID) and value.", inputSchema: { type: "object", properties: { key: { type: "string", // ID is internal cover ID enum: ["ISBN", "OCLC", "LCCN", "OLID", "ID"], description: "The type of identifier used (ISBN, OCLC, LCCN, OLID, ID).", }, value: { type: "string", description: "The value of the identifier.", }, size: { type: "string", enum: ["S", "M", "L"], description: "The desired size of the cover (S, M, or L).", }, }, required: ["key", "value"], }, },
- src/index.ts:178-179 (registration)Switch case in CallToolRequestHandler that routes get_book_cover calls to the handler function.case "get_book_cover": return handleGetBookCover(args);