check_bear_setup
Verify Bear Note Taking App configuration and test connectivity to ensure proper integration with Claude Desktop via Bear MCP Server.
Instructions
Check if Bear is properly configured and test the connection
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:533-596 (handler)Main handler logic for the 'check_bear_setup' tool. Checks Bear app availability using AppleScript, verifies token presence, tests token validity by fetching tags via executeBearURL, and returns a formatted status message.case "check_bear_setup": { let statusMessage = "Bear Setup Status:\n\n"; // Check if Bear app is available try { // Check if Bear is installed without activating it const checkScript = `tell application "System Events" to return exists application process "Bear"`; execSync(`osascript -e '${checkScript}'`, { stdio: 'pipe' }); statusMessage += "✅ Bear app is installed and accessible\n"; } catch { statusMessage += "❌ Bear app not found or not accessible\n"; return { content: [{ type: "text", text: statusMessage }], }; } // Check token const token = getCurrentToken(); if (token) { statusMessage += "✅ Token is configured\n"; // Test token by trying to get tags try { const response = await executeBearURL("tags", {}, true, true); console.error("[DEBUG] Tags response:", response); if (response && response.tags) { let tagNames: string[] = []; if (Array.isArray(response.tags)) { tagNames = response.tags.map((tag: any) => { if (typeof tag === 'string') { return tag; } else if (tag && tag.name) { return tag.name; } else { return String(tag); } }); } statusMessage += `✅ Token is valid - found ${tagNames.length} tags\n`; if (tagNames.length > 0) { statusMessage += `📋 Sample tags: ${tagNames.slice(0, 5).join(", ")}${tagNames.length > 5 ? "..." : ""}`; } } else { statusMessage += "⚠️ Token test returned no data (you might have no tags)"; } } catch (error) { statusMessage += `❌ Token test failed: ${error instanceof Error ? error.message : String(error)}`; } } else { statusMessage += "❌ No token configured\n"; statusMessage += "\nTo fix: Get token from Bear → Help → Advanced → API Token → Copy Token\nThen use set_bear_token tool"; } return { content: [ { type: "text", text: statusMessage, }, ], }; }
- src/index.ts:403-411 (registration)Registration of the 'check_bear_setup' tool in the ListToolsRequestSchema handler, including its description and empty input schema.{ name: "check_bear_setup", description: "Check if Bear is properly configured and test the connection", inputSchema: { type: "object", properties: {}, required: [], }, },
- src/index.ts:303-372 (helper)Core helper function executeBearURL used by check_bear_setup to perform the token test by calling Bear's 'tags' action via x-callback-url with HTTP callback handling.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(); } }
- src/index.ts:57-59 (helper)Helper function getCurrentToken used in check_bear_setup to retrieve the current Bear token from file or env.function getCurrentToken(): string | null { return loadToken() || process.env.BEAR_TOKEN || null; }