Skip to main content
Glama

mcp-open-library

get_authors_by_name

Retrieve detailed author information from Open Library by entering the author's name to facilitate efficient book-related searches and research.

Instructions

Search for author information on Open Library.

Input Schema

NameRequiredDescriptionDefault
nameYesThe name of the author to search for.

Input Schema (JSON Schema)

{ "properties": { "name": { "description": "The name of the author to search for.", "type": "string" } }, "required": [ "name" ], "type": "object" }

Implementation Reference

  • The handler function that executes the tool: validates input with Zod, queries Open Library /search/authors.json API with author name, processes docs into AuthorInfo array, returns JSON string or error.
    const handleGetAuthorsByName = async ( args: unknown, axiosInstance: AxiosInstance, ): Promise<CallToolResult> => { const parseResult = GetAuthorsByNameArgsSchema.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_authors_by_name: ${errorMessages}`, ); } const authorName = parseResult.data.name; try { const response = await axiosInstance.get<OpenLibraryAuthorSearchResponse>( "/search/authors.json", // Use the author search endpoint { params: { q: authorName }, // Use 'q' parameter for author search }, ); if ( !response.data || !response.data.docs || response.data.docs.length === 0 ) { return { content: [ { type: "text", text: `No authors found matching name: "${authorName}"`, }, ], }; } const authorResults: AuthorInfo[] = response.data.docs.map((doc) => ({ key: doc.key, name: doc.name, alternate_names: doc.alternate_names, birth_date: doc.birth_date, top_work: doc.top_work, work_count: doc.work_count, })); return { content: [ { type: "text", text: JSON.stringify(authorResults, null, 2), }, ], }; } catch (error) { let errorMessage = "Failed to fetch author data from Open Library."; if (axios.isAxiosError(error)) { errorMessage = `Open Library API error: ${ error.response?.statusText ?? error.message }`; } else if (error instanceof Error) { errorMessage = `Error processing request: ${error.message}`; } console.error("Error in get_authors_by_name:", error); return { content: [ { type: "text", text: errorMessage, }, ], isError: true, }; } };
  • Zod schema for input validation: requires a non-empty 'name' string.
    // Schema for the get_authors_by_name tool arguments export const GetAuthorsByNameArgsSchema = z.object({ name: z.string().min(1, { message: "Author name cannot be empty" }), });
  • src/index.ts:70-82 (registration)
    Tool registration in MCP ListTools handler: defines name, description, and JSON schema matching the Zod schema.
    name: "get_authors_by_name", description: "Search for author information on Open Library.", inputSchema: { type: "object", properties: { name: { type: "string", description: "The name of the author to search for.", }, }, required: ["name"], }, },
  • src/index.ts:172-173 (registration)
    Dispatches tool calls to the handler in MCP CallToolRequestHandler switch statement.
    case "get_authors_by_name": return handleGetAuthorsByName(args, this.axiosInstance);
  • Type definitions for API response structures and processed author information used by the handler.
    export interface OpenLibraryAuthorDoc { key: string; type: string; name: string; alternate_names?: string[]; birth_date?: string; top_work?: string; work_count: number; top_subjects?: string[]; _version_?: number; } export interface OpenLibraryAuthorSearchResponse { numFound: number; start: number; numFoundExact: boolean; docs: OpenLibraryAuthorDoc[]; } export interface AuthorInfo { key: string; name: string; alternate_names?: string[]; birth_date?: string; top_work?: string; work_count: number; }

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/8enSmith/mcp-open-library'

If you have feedback or need assistance with the MCP directory API, please join our Discord server