readwise_topic_search
Search documents in Readwise Reader by matching topics against titles, summaries, notes, and tags using case-insensitive regex patterns.
Instructions
Search documents in Readwise Reader by topic using regex matching on title, summary, notes, and tags
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| searchTerms | Yes | List of search terms to match against document content (case-insensitive regex matching) |
Implementation Reference
- The handler function that implements the core logic of the 'readwise_topic_search' tool. It extracts searchTerms from args, calls client.searchDocumentsByTopic, maps the response data to a structured searchResults object, stringifies it to JSON, appends any messages, and returns it as a 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, }, ], }; }
- The tool definition including name, description, and inputSchema for validating arguments to 'readwise_topic_search', requiring an array of searchTerms.{ 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, }, },
- src/handlers/index.ts:26-27 (registration)The switch case in the main handleToolCall dispatcher that registers and routes calls to the 'readwise_topic_search' handler function.case 'readwise_topic_search': return handleTopicSearch(args);
- src/handlers/index.ts:7-26 (registration)Import statement that brings the handleTopicSearch handler into the main dispatcher module.import { handleListTags, handleTopicSearch } from './tag-search-handlers.js'; 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':