Skip to main content
Glama
ispyridis

Calibre MCP Server

by ispyridis

fetch

Retrieve specific content from Calibre ebooks using epub URLs to access book sections directly from search results.

Instructions

Fetch specific content from a book using epub:// URL

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesepub:// URL from search results

Implementation Reference

  • Core handler function that implements the 'fetch' tool logic: parses epub URL, retrieves book metadata using calibredb, finds text file, extracts specified line range or default context, and returns structured content.
    async fetchByEpubUrl(url) {
        try {
            const { bookId, startLine, endLine } = this.parseEpubUrl(url);
            
            // Get book metadata
            const listResult = await this.runCalibreCommand([
                'list',
                '--fields', 'id,title,authors,formats',
                '--for-machine',
                '--search', `id:${bookId}`
            ]);
    
            const books = JSON.parse(listResult || '[]');
            
            if (books.length === 0) {
                throw new Error('Book not found');
            }
    
            const book = books[0];
            const txtPath = book.formats?.find(f => f.endsWith('.txt'));
            
            if (!txtPath || !fs.existsSync(txtPath)) {
                throw new Error('No text format available for this book');
            }
    
            // Extract content
            let content;
            if (startLine && endLine) {
                content = this.extractLineRange(txtPath, parseInt(startLine), parseInt(endLine));
            } else {
                content = this.extractParagraphContext(txtPath, 1, 5);
            }
    
            return {
                book_id: book.id,
                title: book.title,
                authors: book.authors,
                content: content,
                url: url,
                line_range: {
                    start: startLine ? parseInt(startLine) : null,
                    end: endLine ? parseInt(endLine) : null
                }
            };
            
        } catch (error) {
            throw error;
        }
    }
  • server.js:547-560 (registration)
    Registration of the 'fetch' tool in the tools/list response, including name, description, and input schema definition.
    {
        name: 'fetch',
        description: 'Fetch specific content from a book using epub:// URL',
        inputSchema: {
            type: 'object',
            properties: {
                url: {
                    type: 'string',
                    description: 'epub:// URL from search results'
                }
            },
            required: ['url']
        }
    }
  • Tool dispatch handler in tools/call method that validates input, calls fetchByEpubUrl, formats MCP-compliant response, and handles errors.
    case 'fetch':
        const url = args.url;
        
        if (!url) {
            this.sendError(id, -32602, 'Missing required parameter: url');
            return;
        }
        
        try {
            const fetchResult = await this.fetchByEpubUrl(url);
            const contentText = `Content from '${fetchResult.title}' by ${fetchResult.authors}:\n\n${fetchResult.content}`;
            
            const mcpResult = {
                content: [{
                    type: 'text',
                    text: contentText
                }],
                book_id: fetchResult.book_id,
                title: fetchResult.title,
                authors: fetchResult.authors,
                url: fetchResult.url
            };
            
            this.sendSuccess(id, mcpResult);
        } catch (error) {
            this.sendError(id, -32603, error.message);
        }
        break;
  • Helper function to parse epub:// URLs into bookId and optional line range.
    parseEpubUrl(url) {
        // Remove epub:// prefix
        url = url.replace(/^epub:\/\//, '');
        
        // Extract book ID
        const idMatch = url.match(/@(\d+)/);
        if (!idMatch) {
            throw new Error('Invalid epub URL format');
        }
        const bookId = idMatch[1];
        
        // Extract line range (optional)
        let startLine = '';
        let endLine = '';
        const rangeMatch = url.match(/#(\d+):(\d+)$/);
        if (rangeMatch) {
            startLine = rangeMatch[1];
            endLine = rangeMatch[2];
        }
        
        return { bookId, startLine, endLine };
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It states the tool fetches content but doesn't disclose behavioral traits such as whether it's read-only or mutative, what happens with invalid URLs, rate limits, or authentication needs. This is inadequate 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 that front-loads the purpose and key constraint ('epub:// URL'). There's no wasted text, making it appropriately sized and well-structured for quick understanding.

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 the tool's complexity (fetching content with a single parameter), lack of annotations, and no output schema, the description is incomplete. It doesn't explain what 'content' is returned (e.g., text, metadata), error handling, or other behavioral aspects needed for effective use.

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 'url' fully documented in the schema. The description adds minimal value by specifying 'epub:// URL from search results', which hints at the source but doesn't provide additional syntax or format details beyond the schema. 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 ('fetch') and resource ('specific content from a book'), and specifies the required input format ('using epub:// URL'). However, it doesn't explicitly differentiate from the sibling 'search' tool, which likely returns URLs rather than content. This makes it clear but not fully sibling-distinctive.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention the sibling 'search' tool, prerequisites like needing a URL from search results, or any exclusions. This leaves the agent with minimal context for tool selection.

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/ispyridis/calibre-mcp-nodejs'

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