bear_edit_note
Edit a Bear note by appending text, replacing its body, or updating its YAML front matter fields.
Instructions
Edit an existing Bear note. Provide 'append_text' to add text, 'body' to replace content, or 'set_frontmatter'/'remove_frontmatter' to edit YAML front matter fields. Front matter edits can be combined with each other but not with body/append.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | Note ID (uniqueIdentifier) | |
| append_text | No | Text to append to the end of the note | |
| body | No | New content to replace the entire note body | |
| after | No | Insert appended text after the line containing this text (use with append_text) | |
| replace_section | No | Replace content under this heading (replaces until next heading of same or higher level) | |
| section_content | No | New content for the section (use with replace_section) | |
| set_frontmatter | No | Front matter fields to set or update (key-value pairs) | |
| remove_frontmatter | No | Front matter field keys to remove |
Implementation Reference
- mcp-server/src/tools.ts:256-308 (handler)The buildArgs function for bear_edit_note: translates tool input parameters into bcli command-line arguments. Supports four editing modes: front matter edits (--set-fm/--remove-fm), section replacement (--replace-section), text appending (--append), and body replacement (--stdin).
buildArgs: (input) => { // Front matter editing mode const hasFm = (input.set_frontmatter && Object.keys(input.set_frontmatter as object).length > 0) || (Array.isArray(input.remove_frontmatter) && input.remove_frontmatter.length > 0); if (hasFm && !input.append_text && !input.body) { const args = ["edit", String(input.id), "--json"]; if (input.set_frontmatter && typeof input.set_frontmatter === "object") { const fm = input.set_frontmatter as Record<string, string>; args.push( "--set-fm", ...Object.entries(fm).map(([k, v]) => `${k}=${v}`), ); } if (Array.isArray(input.remove_frontmatter)) { args.push( "--remove-fm", ...input.remove_frontmatter.map(String), ); } return args; } // Section replacement mode if (input.replace_section) { const args = ["edit", String(input.id), "--replace-section", String(input.replace_section), "--json"]; if (input.section_content) args.push("--section-content", String(input.section_content)); return args; } if (input.append_text) { const args = [ "edit", String(input.id), "--append", String(input.append_text), "--json", ]; if (input.after) args.push("--after", String(input.after)); return args; } // --stdin case handled separately via usesStdin return ["edit", String(input.id), "--stdin", "--json"]; }, usesStdin: (input) => { if (input.body && !input.append_text) { return String(input.body); } return null; }, - mcp-server/src/tools.ts:303-308 (handler)The usesStdin function for bear_edit_note: when 'body' is provided (not append_text), it returns the body content to be piped via stdin to the bcli process for a full body replacement. Otherwise returns null (no stdin needed).
usesStdin: (input) => { if (input.body && !input.append_text) { return String(input.body); } return null; }, - mcp-server/src/tools.ts:205-249 (schema)The inputSchema for bear_edit_note: defines the JSON schema with required 'id' (string) and optional parameters including append_text, body, after, replace_section, section_content, set_frontmatter (object), and remove_frontmatter (array of strings).
inputSchema: { type: "object" as const, properties: { id: { type: "string", description: "Note ID (uniqueIdentifier)", }, append_text: { type: "string", description: "Text to append to the end of the note", }, body: { type: "string", description: "New content to replace the entire note body", }, after: { type: "string", description: "Insert appended text after the line containing this text (use with append_text)", }, replace_section: { type: "string", description: "Replace content under this heading (replaces until next heading of same or higher level)", }, section_content: { type: "string", description: "New content for the section (use with replace_section)", }, set_frontmatter: { type: "object", description: "Front matter fields to set or update (key-value pairs)", additionalProperties: { type: "string" }, }, remove_frontmatter: { type: "array", items: { type: "string" }, description: "Front matter field keys to remove", }, }, required: ["id"], }, - mcp-server/src/tools.ts:200-309 (registration)The full tool definition and registration for bear_edit_note in the tools registry. It is a key in the exported 'tools' Record with the name 'bear_edit_note' and its tool metadata includes name, description, inputSchema, and annotations.
bear_edit_note: { tool: { name: "bear_edit_note", description: "Edit an existing Bear note. Provide 'append_text' to add text, 'body' to replace content, or 'set_frontmatter'/'remove_frontmatter' to edit YAML front matter fields. Front matter edits can be combined with each other but not with body/append.", inputSchema: { type: "object" as const, properties: { id: { type: "string", description: "Note ID (uniqueIdentifier)", }, append_text: { type: "string", description: "Text to append to the end of the note", }, body: { type: "string", description: "New content to replace the entire note body", }, after: { type: "string", description: "Insert appended text after the line containing this text (use with append_text)", }, replace_section: { type: "string", description: "Replace content under this heading (replaces until next heading of same or higher level)", }, section_content: { type: "string", description: "New content for the section (use with replace_section)", }, set_frontmatter: { type: "object", description: "Front matter fields to set or update (key-value pairs)", additionalProperties: { type: "string" }, }, remove_frontmatter: { type: "array", items: { type: "string" }, description: "Front matter field keys to remove", }, }, required: ["id"], }, annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, }, }, buildArgs: (input) => { // Front matter editing mode const hasFm = (input.set_frontmatter && Object.keys(input.set_frontmatter as object).length > 0) || (Array.isArray(input.remove_frontmatter) && input.remove_frontmatter.length > 0); if (hasFm && !input.append_text && !input.body) { const args = ["edit", String(input.id), "--json"]; if (input.set_frontmatter && typeof input.set_frontmatter === "object") { const fm = input.set_frontmatter as Record<string, string>; args.push( "--set-fm", ...Object.entries(fm).map(([k, v]) => `${k}=${v}`), ); } if (Array.isArray(input.remove_frontmatter)) { args.push( "--remove-fm", ...input.remove_frontmatter.map(String), ); } return args; } // Section replacement mode if (input.replace_section) { const args = ["edit", String(input.id), "--replace-section", String(input.replace_section), "--json"]; if (input.section_content) args.push("--section-content", String(input.section_content)); return args; } if (input.append_text) { const args = [ "edit", String(input.id), "--append", String(input.append_text), "--json", ]; if (input.after) args.push("--after", String(input.after)); return args; } // --stdin case handled separately via usesStdin return ["edit", String(input.id), "--stdin", "--json"]; }, usesStdin: (input) => { if (input.body && !input.append_text) { return String(input.body); } return null; }, }, - mcp-server/src/index.ts:46-78 (registration)Direct validation logic for bear_edit_note in the MCP server request handler: ensures at least one edit operation is provided (append_text, body, set_frontmatter, or remove_frontmatter) and that append_text and body are not both specified. Returns error messages for invalid combinations.
// Validate bear_edit_note: need at least one edit operation if (name === "bear_edit_note") { const hasAppend = params.append_text !== undefined; const hasBody = params.body !== undefined; const hasSetFm = params.set_frontmatter !== undefined && Object.keys(params.set_frontmatter as object).length > 0; const hasRemoveFm = Array.isArray(params.remove_frontmatter) && (params.remove_frontmatter as unknown[]).length > 0; const hasFm = hasSetFm || hasRemoveFm; if (!hasAppend && !hasBody && !hasFm) { return { content: [ { type: "text", text: "Provide 'append_text', 'body', 'set_frontmatter', or 'remove_frontmatter'.", }, ], isError: true, }; } if (hasAppend && hasBody) { return { content: [ { type: "text", text: "Provide either 'append_text' or 'body', not both.", }, ], isError: true, }; } }