Skip to main content
Glama
8enSmith

mcp-open-library

get_book_by_title

Search for books by title using the Open Library API. Retrieve detailed book information by providing the exact or partial title as input with this MCP server tool.

Instructions

Search for a book by its title on Open Library.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
titleYesThe title of the book to search for.

Implementation Reference

  • The core handler function `handleGetBookByTitle` that implements the tool logic: validates input with Zod schema, queries Open Library search API, maps results to BookInfo, handles errors, and returns MCP CallToolResult.
    const handleGetBookByTitle = async (
      args: unknown,
      axiosInstance: AxiosInstance,
    ): Promise<CallToolResult> => {
      const parseResult = GetBookByTitleArgsSchema.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_by_title: ${errorMessages}`,
        );
      }
    
      const bookTitle = parseResult.data.title;
    
      try {
        const response = await axiosInstance.get<OpenLibrarySearchResponse>(
          "/search.json",
          {
            params: { title: bookTitle },
          },
        );
    
        if (
          !response.data ||
          !response.data.docs ||
          response.data.docs.length === 0
        ) {
          return {
            content: [
              {
                type: "text",
                text: `No books found matching title: "${bookTitle}"`,
              },
            ],
          };
        }
    
        const bookResults = Array.isArray(response.data.docs)
          ? response.data.docs.map((doc) => {
              const bookInfo: BookInfo = {
                title: doc.title,
                authors: doc.author_name || [],
                first_publish_year: doc.first_publish_year || null,
                open_library_work_key: doc.key,
                edition_count: doc.edition_count || 0,
              };
    
              if (doc.cover_i) {
                bookInfo.cover_url = `https://covers.openlibrary.org/b/id/${doc.cover_i}-M.jpg`;
              }
    
              return bookInfo;
            })
          : [];
    
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify(bookResults, null, 2),
            },
          ],
        };
      } catch (error) {
        let errorMessage = "Failed to fetch book data from Open Library.";
        if (axios.isAxiosError(error)) {
          errorMessage = `Error processing request: ${
            error.response?.statusText ?? error.message
          }`;
        } else if (error instanceof Error) {
          errorMessage = `Error processing request: ${error.message}`;
        }
        console.error("Error in get_book_by_title:", error);
    
        return {
          content: [
            {
              type: "text",
              text: errorMessage,
            },
          ],
          isError: true,
        };
      }
    };
  • Zod schema `GetBookByTitleArgsSchema` used for input validation in the handler.
    // Schema for the get_book_by_title tool arguments
    export const GetBookByTitleArgsSchema = z.object({
      title: z.string().min(1, { message: "Title cannot be empty" }),
    });
  • src/index.ts:55-68 (registration)
    Tool registration in ListTools handler: defines name, description, and JSON inputSchema for MCP protocol.
    {
      name: "get_book_by_title",
      description: "Search for a book by its title on Open Library.",
      inputSchema: {
        type: "object",
        properties: {
          title: {
            type: "string",
            description: "The title of the book to search for.",
          },
        },
        required: ["title"],
      },
    },
  • src/index.ts:170-171 (registration)
    Dispatch case in CallToolRequest handler that routes to the `handleGetBookByTitle` function.
    case "get_book_by_title":
      return handleGetBookByTitle(args, this.axiosInstance);
  • TypeScript interfaces defining OpenLibrary API response shapes and output BookInfo used in the handler.
    export interface OpenLibraryDoc {
      title: string;
      author_name?: string[];
      first_publish_year?: number;
      key: string; // Work key, e.g., "/works/OL45883W"
      edition_count: number;
      cover_i?: number; // Add optional cover ID
    }
    
    export interface OpenLibrarySearchResponse {
      docs: OpenLibraryDoc[];
    }
    
    export interface BookInfo {
      title: string;
      authors: string[];
      first_publish_year: number | null;
      open_library_work_key: string;
      edition_count: number;
      cover_url?: string;
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden but only states it's a search operation. It doesn't disclose behavioral traits like whether it returns multiple matches, handles partial titles, requires authentication, has rate limits, or what happens on no results. This leaves significant gaps for a tool with zero annotation coverage.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with zero waste—it directly states the tool's purpose without redundancy. It's appropriately sized and front-loaded, making it easy to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations, no output schema, and a search tool that likely returns complex data, the description is incomplete. It doesn't explain return values, error handling, or behavioral nuances, leaving the agent with insufficient context to use the tool effectively beyond basic invocation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 100%, with the parameter 'title' fully documented in the schema. The description adds no additional parameter semantics beyond what's in the schema, such as format examples or search behavior details. Baseline 3 is appropriate when the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Search for a book') and resource ('on Open Library'), with the specific criterion 'by its title' distinguishing it from sibling tools like get_book_by_id. However, it doesn't explicitly differentiate from get_authors_by_name or other search tools, keeping it from a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage when searching by title rather than ID or author name, but doesn't explicitly state when to use this tool versus alternatives like get_book_by_id or get_authors_by_name. No guidance on prerequisites, error conditions, or exclusions is provided.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

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