Skip to main content
Glama
edricgsh

Readwise Reader MCP Server

by edricgsh

readwise_topic_search

Search documents in Readwise Reader by topic using regex matching on titles, summaries, notes, and tags to find relevant content.

Instructions

Search documents in Readwise Reader by topic using regex matching on title, summary, notes, and tags

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
searchTermsYesList of search terms to match against document content (case-insensitive regex matching)

Implementation Reference

  • MCP tool handler that extracts search terms from args, calls client.searchDocumentsByTopic, formats results as JSON, appends messages if any, and returns text content response.
    export async function handleTopicSearch(args: any) {
      const client = initializeClient();
      const { searchTerms } = args as { searchTerms: string[] };
      
      const response = await client.searchDocumentsByTopic(searchTerms);
      
      const searchResults = {
        searchTerms,
        totalMatches: response.data.length,
        documents: response.data.map((doc: any) => ({
          id: doc.id,
          url: doc.url,
          title: doc.title,
          author: doc.author,
          source: doc.source,
          category: doc.category,
          location: doc.location,
          tags: doc.tags,
          site_name: doc.site_name,
          word_count: doc.word_count,
          created_at: doc.created_at,
          updated_at: doc.updated_at,
          published_date: doc.published_date,
          summary: doc.summary,
          image_url: doc.image_url,
          source_url: doc.source_url,
          notes: doc.notes,
          reading_progress: doc.reading_progress,
          first_opened_at: doc.first_opened_at,
          last_opened_at: doc.last_opened_at,
          saved_at: doc.saved_at,
          last_moved_at: doc.last_moved_at,
        }))
      };
    
      let responseText = JSON.stringify(searchResults, null, 2);
      
      if (response.messages && response.messages.length > 0) {
        responseText += '\n\nMessages:\n' + response.messages.map(msg => `${msg.type.toUpperCase()}: ${msg.content}`).join('\n');
      }
    
      return {
        content: [
          {
            type: 'text',
            text: responseText,
          },
        ],
      };
    } 
  • Tool schema definition with name, description, and inputSchema specifying searchTerms array.
    {
      name: 'readwise_topic_search',
      description: 'Search documents in Readwise Reader by topic using regex matching on title, summary, notes, and tags',
      inputSchema: {
        type: 'object',
        properties: {
          searchTerms: {
            type: 'array',
            items: { type: 'string' },
            description: 'List of search terms to match against document content (case-insensitive regex matching)',
            minItems: 1,
          },
        },
        required: ['searchTerms'],
        additionalProperties: false,
      },
    },
  • Core search logic in ReadwiseClient: paginates all documents, filters client-side using case-insensitive regex on title/summary/notes/tags for any matching search term.
    async searchDocumentsByTopic(searchTerms: string[]): Promise<APIResponse<ReadwiseDocument[]>> {
      try {
        // Fetch all documents without full content for performance
        const allDocuments: ReadwiseDocument[] = [];
        let nextPageCursor: string | undefined;
        
        do {
          const params: ListDocumentsParams = {
            withFullContent: false,
            withHtmlContent: false,
          };
          
          if (nextPageCursor) {
            params.pageCursor = nextPageCursor;
          }
          
          const response = await this.listDocuments(params);
          allDocuments.push(...response.data.results);
          nextPageCursor = response.data.nextPageCursor;
        } while (nextPageCursor);
    
        // Create regex patterns from search terms (case-insensitive)
        const regexPatterns = searchTerms.map(term => 
          new RegExp(term.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'i')
        );
    
        // Filter documents that match any of the search terms
        const matchingDocuments = allDocuments.filter(doc => {
          // Extract searchable text fields
          const searchableFields = [
            doc.title || '',
            doc.summary || '',
            doc.notes || '',
            // Handle tags - they can be string array or object
            Array.isArray(doc.tags) ? doc.tags.join(' ') : '',
          ];
    
          const searchableText = searchableFields.join(' ').toLowerCase();
    
          // Check if any regex pattern matches
          return regexPatterns.some(pattern => pattern.test(searchableText));
        });
    
        return this.createResponse(matchingDocuments);
      } catch (error) {
        if (error instanceof Error && error.message.startsWith('RATE_LIMIT:')) {
          const seconds = parseInt(error.message.split(':')[1], 10);
          throw new Error(`Rate limit exceeded. Too many requests. Please retry after ${seconds} seconds.`);
        }
        throw error;
      }
    }
  • Tool dispatcher function with switch case registering/routing readwise_topic_search to its handler.
    export async function handleToolCall(name: string, args: any) {
      switch (name) {
        case 'readwise_save_document':
          return handleSaveDocument(args);
          
        case 'readwise_list_documents':
          return handleListDocuments(args);
          
        case 'readwise_update_document':
          return handleUpdateDocument(args);
          
        case 'readwise_delete_document':
          return handleDeleteDocument(args);
          
        case 'readwise_list_tags':
          return handleListTags(args);
          
        case 'readwise_topic_search':
          return handleTopicSearch(args);
          
        default:
          throw new Error(`Unknown tool: ${name}`);
      }
    } 
  • src/index.ts:24-26 (registration)
    MCP server registration of the tools list (including readwise_topic_search schema) for listTools requests.
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      return { tools };
    });
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It mentions regex matching across multiple fields and case-insensitivity, which is useful. However, it doesn't describe important behavioral aspects like pagination, rate limits, authentication requirements, error handling, or what happens when no matches are found. For a search tool with zero annotation coverage, this leaves significant gaps.

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 and front-loaded with all necessary information in a single sentence. Every word earns its place by specifying the action, target, method, and search fields without any redundancy or unnecessary elaboration.

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 (search functionality with regex matching), lack of annotations, and no output schema, the description is incomplete. It doesn't explain what the search returns, how results are structured, whether there are limitations on search scope or result size, or how the regex matching actually works across the different fields. The description should provide more context for effective tool 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?

Schema description coverage is 100%, so the schema already fully documents the 'searchTerms' parameter with its type, constraints, and description. The description adds minimal value beyond the schema by mentioning the fields being searched (title, summary, notes, tags), but doesn't provide additional syntax, format, or usage details for the parameters.

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 tool's purpose: searching documents in Readwise Reader by topic using regex matching across multiple fields (title, summary, notes, tags). It specifies the verb 'search' and resource 'documents' with scope 'by topic', but doesn't explicitly differentiate from sibling tools like 'readwise_list_documents' or 'readwise_save_document' beyond the search functionality.

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 when to choose this search tool over 'readwise_list_documents' for listing all documents, or when to use it in conjunction with other tools. There's no context about prerequisites, limitations, or typical use cases.

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/edricgsh/Readwise-Reader-MCP'

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