Skip to main content
Glama
hongfanmeng

Bookstore MCP Server

by hongfanmeng

buy_book

Purchase books from the Bookstore MCP Server by specifying book ID and quantity. Complete transactions to acquire desired titles directly through the system.

Instructions

Buy a book.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
book_idYes
quantityNo

Implementation Reference

  • The buy_book tool handler function, decorated with @mcp.tool() for registration. It handles purchasing books by checking stock, updating count, and saving to JSON.
    @mcp.tool()
    def buy_book(book_id: int, quantity: int = 1):
        """Buy a book."""
        if quantity <= 0:
            return {"success": False, "error": "Quantity must be > 0"}
    
        books = load_books()
        book = next((b for b in books if b["id"] == book_id), None)
    
        if not book:
            return {"success": False, "error": f"Book {book_id} not found"}
    
        if book["count"] < quantity:
            return {"success": False, "error": f"Only {book['count']} available"}
    
        book["count"] -= quantity
    
        if save_books(books):
            return {
                "success": True,
                "message": f"Purchased {quantity} of '{book['title']}'",
            }
        else:
            return {"success": False, "error": "Save failed"}
Behavior1/5

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

With no annotations provided, the description carries full burden but offers no behavioral details. It doesn't disclose that this is a transactional/mutative operation, potential side effects (e.g., inventory reduction, payment processing), authentication needs, error conditions, or what happens upon success/failure.

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 extremely concise with just three words. While under-specified, it's front-loaded and wastes no words—every word directly states the tool's action, though it lacks necessary detail.

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

Completeness1/5

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

For a transactional tool with 2 parameters, 0% schema coverage, no annotations, and no output schema, the description is completely inadequate. It doesn't explain what the tool does beyond the obvious name, provide usage context, parameter meanings, or expected outcomes.

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

Parameters1/5

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

Schema description coverage is 0%, so parameters are undocumented in the schema. The description adds no information about what 'book_id' represents (e.g., ISBN, database ID) or 'quantity' constraints (e.g., must be positive, stock limits). It fails to compensate for the complete lack of schema documentation.

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

Purpose2/5

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

The description 'Buy a book' restates the tool name 'buy_book' almost verbatim, making it tautological. It doesn't specify what buying entails (e.g., purchase transaction, inventory reduction, order placement) or distinguish it from siblings like 'check_availability' or 'restock_book'.

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

Usage Guidelines1/5

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

No guidance is provided on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., checking availability first), exclusions, or relationships to sibling tools like 'check_availability' or 'get_books_in_stock'.

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

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/hongfanmeng/bookstore-mcp'

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