get_note
Retrieve the content of a specific note from Bear Note Taking App by providing its unique identifier or title, enabling easy access to stored information via the Bear MCP Server.
Instructions
Get the content of a specific note
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | No | Note unique identifier | |
| title | No | Note title (used if id is not provided) |
Implementation Reference
- src/index.ts:434-451 (registration)Registration of the 'get_note' tool in the ListToolsRequestSchema handler, including its name, description, and input schema definition.{ name: "get_note", description: "Get the content of a specific note", inputSchema: { type: "object", properties: { id: { type: "string", description: "Note unique identifier", }, title: { type: "string", description: "Note title (used if id is not provided)", }, }, required: [], }, },
- src/index.ts:627-653 (handler)The main handler logic for the 'get_note' tool. It builds Bear URL parameters from the input arguments (id or title), calls executeBearURL to interact with Bear app via x-callback-url, and formats the retrieved note content (title, text, metadata) as a markdown response.case "get_note": { const params: BearParams = {}; if (args.id) params.id = String(args.id); if (args.title) params.title = String(args.title); const response = await executeBearURL("open-note", params, true); if (response && response.note) { return { content: [ { type: "text", text: `# ${response.title || "Note"}\n\n${response.note}\n\n---\nID: ${response.identifier || "N/A"}\nTags: ${response.tags || "none"}\nModified: ${response.modificationDate || "N/A"}`, }, ], }; } else { return { content: [ { type: "text", text: "Unable to retrieve note content. Make sure Bear's x-callback-url is enabled in preferences.", }, ], }; } }
- src/index.ts:303-372 (helper)Shared helper function executeBearURL that constructs and executes Bear x-callback-url schemes using AppleScript and handles callbacks via a local HTTP server. Called by get_note handler with 'open-note' action to retrieve note content.async function executeBearURL(action: string, params: BearParams, expectResponse: boolean = false, requiresToken: boolean = false): Promise<BearResponse | null> { const callbackHandler = new BearCallbackHandler(); try { // Add token if required and available if (requiresToken) { const token = getCurrentToken(); if (token) { params.token = token; } else { throw new Error("Token required but not available. Use set_bear_token to configure."); } } // Always use show_window=no to prevent Bear from opening if (!params.hasOwnProperty('show_window')) { params.show_window = "no"; } // Start callback server if we expect a response if (expectResponse) { await callbackHandler.startServer(); params["x-success"] = `http://127.0.0.1:${CALLBACK_PORT}/bear-callback`; params["x-error"] = `http://127.0.0.1:${CALLBACK_PORT}/bear-callback`; } // Build the URL const url = new URL(`${BEAR_URL_SCHEME}/${action}`); Object.entries(params).forEach(([key, value]) => { if (value !== undefined) { url.searchParams.append(key, value); } }); console.error(`[DEBUG] Opening Bear URL: ${url.toString()}`); // Use AppleScript to open the URL (more reliable than 'open' command) const script = `open location "${url.toString()}"`; try { execSync(`osascript -e '${script}'`, { stdio: 'pipe' }); } catch (execError) { console.error(`[DEBUG] Error executing AppleScript:`, execError); throw new Error(`Failed to open Bear URL: ${execError}`); } // Wait for callback if expected if (expectResponse) { try { const response = await callbackHandler.waitForCallback(); // Check for errors in response if (response.errorCode || response['error-Code'] || response.errorMessage) { const errorCode = response.errorCode || response['error-Code'] || 'unknown'; const errorMessage = response.errorMessage || response.errorMessage || 'Unknown error'; throw new Error(`Bear API Error ${errorCode}: ${errorMessage}`); } return response; } catch (error) { console.error(`[DEBUG] Callback error:`, error); throw error; } } return null; } finally { // Always stop the server callbackHandler.stopServer(); } }