search_notes
Find Apple Notes by searching titles and content snippets with keywords. Retrieve matching notes and their metadata for quick access.
Instructions
Search Apple Notes by keyword. Searches in title and snippet. Returns matching notes with metadata.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | Search keyword | |
| limit | No | Max number of results |
Implementation Reference
- src/db.ts:76-95 (handler)The core business logic that queries the SQLite database to find notes matching the query string in title or snippet.
export function searchNotes(query: string, limit?: number): NoteRow[] { const db = getDb(); const likePattern = `%${query}%`; let sql = LIST_QUERY.replace( "ORDER BY", `AND (n.ZTITLE1 LIKE ? OR n.ZSNIPPET LIKE ?) ORDER BY` ); const params: unknown[] = [likePattern, likePattern]; if (limit) { sql += ` LIMIT ?`; params.push(limit); } const rows = db.prepare(sql).all(...params) as NoteRow[]; return rows.map((r) => ({ ...r, is_pinned: Boolean(r.is_pinned), })); } - src/index.ts:42-60 (registration)The MCP tool registration and handler wrapper for 'search_notes', which calls the database function defined in db.ts.
// --- search_notes --- server.tool( "search_notes", "Search Apple Notes by keyword. Searches in title and snippet. Returns matching notes with metadata.", { query: z.string().describe("Search keyword"), limit: z.number().optional().describe("Max number of results"), }, async ({ query, limit }) => { try { const notes = searchNotes(query, limit); return { content: [{ type: "text", text: JSON.stringify(notes, null, 2) }], }; } catch (e: unknown) { return { content: [{ type: "text", text: `Error: ${(e as Error).message}` }], isError: true, };