search_entries
Search and filter journal entries by date, tags, keywords, or starred status using specific parameters to retrieve relevant results efficiently.
Instructions
Search and filter journal entries
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| contains | No | Text to search for | |
| from | No | Start date (e.g., "yesterday", "2024-01-01") | |
| journal | No | Journal name (uses current/default if not specified) | |
| limit | No | Maximum number of entries | |
| starred | No | Only show starred entries | |
| tags | No | Tags to filter by | |
| to | No | End date |
Implementation Reference
- src/handlers/entryHandlers.ts:23-59 (handler)The main handler function implementing the search_entries tool logic. It builds a search command using provided filters, executes it via JrnlExecutor, parses the JSON output, transforms entries, and returns entries and tags.export async function searchEntries( params: SearchEntriesParams, executor: JrnlExecutor, ): Promise<{ entries: JournalEntry[]; tags: Record<string, number> }> { const filters: SearchFilters = { from: params.from, to: params.to, tags: params.tags, contains: params.contains, limit: params.limit, starred: params.starred, }; const command = buildSearchCommand(filters, params.journal); const result = await executor.execute(command); try { const data = JSON.parse(result); // jrnl exports in a specific format, need to transform it const entries: JournalEntry[] = data.entries.map((entry: any) => ({ date: entry.date, time: entry.time || "", title: entry.title || "", body: entry.body || "", tags: entry.tags || [], starred: entry.starred || false, })); return { entries, tags: data.tags || {}, }; } catch (error) { throw new Error(`Failed to parse jrnl output: ${error}`); } }
- src/handlers/entryHandlers.ts:13-21 (schema)TypeScript interface defining the input parameters for the searchEntries handler.export interface SearchEntriesParams { from?: string; to?: string; tags?: string[]; contains?: string; limit?: number; starred?: boolean; journal?: string; }
- src/handlers/entryHandlers.ts:4-11 (schema)TypeScript interface defining the structure of a journal entry returned by the handler.export interface JournalEntry { date: string; time: string; title: string; body: string; tags: string[]; starred: boolean; }
- src/index.ts:36-64 (registration)MCP tool registration defining the 'search_entries' tool's metadata and input schema in the ListTools response.{ name: "search_entries", description: "Search and filter journal entries", inputSchema: { type: "object", properties: { from: { type: "string", description: 'Start date (e.g., "yesterday", "2024-01-01")', }, to: { type: "string", description: "End date" }, tags: { type: "array", items: { type: "string" }, description: "Tags to filter by", }, contains: { type: "string", description: "Text to search for" }, limit: { type: "number", description: "Maximum number of entries" }, starred: { type: "boolean", description: "Only show starred entries", }, journal: { type: "string", description: "Journal name (uses current/default if not specified)", }, }, }, },
- src/index.ts:154-166 (registration)Dispatch handler in the CallToolRequestHandler switch statement that invokes the searchEntries function.case "search_entries": return { content: [ { type: "text", text: JSON.stringify( await searchEntries({ ...args, journal } as any, executor), null, 2, ), }, ], };