obsidian_update_task
Modify a Markdown task's status, checked state, or text in an Obsidian note using its path and line number.
Instructions
Update one Markdown task by note path and 1-based line number.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| vault | No | Optional configured vault name. Defaults to the server default vault. | |
| path | Yes | Vault-relative path. Absolute paths and traversal are rejected. | |
| line | Yes | ||
| checked | No | ||
| status | No | ||
| text | No |
Implementation Reference
- src/tools.ts:941-959 (registration)Registration of the 'obsidian_update_task' tool. It calls the helper function 'replaceTaskLine' to update a task on a specific line of a note.
tool( "obsidian_update_task", "Update one Markdown task by note path and 1-based line number.", { vault: vaultArg, path: pathArg, line: z.number().int().min(1), checked: z.boolean().optional(), status: z.string().length(1).optional(), text: z.string().optional(), }, async (args) => { const read = await vaults.readText(args.path, args.vault); const next = replaceTaskLine(read.text, args.line, args); await vaults.writeText(read.path, next, args.vault, { overwrite: true }); return { path: read.path, line: args.line, updated: true }; }, { idempotentHint: true }, ); - src/tools.ts:945-951 (schema)Input schema for obsidian_update_task: requires vault (optional), path, line (1-based), and optional checked, status, or text fields.
vault: vaultArg, path: pathArg, line: z.number().int().min(1), checked: z.boolean().optional(), status: z.string().length(1).optional(), text: z.string().optional(), }, - src/tools.ts:952-958 (handler)Handler function for obsidian_update_task. Reads the note, calls replaceTaskLine to update the task, then writes the result back.
async (args) => { const read = await vaults.readText(args.path, args.vault); const next = replaceTaskLine(read.text, args.line, args); await vaults.writeText(read.path, next, args.vault, { overwrite: true }); return { path: read.path, line: args.line, updated: true }; }, { idempotentHint: true }, - src/markdown.ts:239-254 (helper)replaceTaskLine function: parses a task line at the given 1-based line number, updates status/checked/text, and returns the modified markdown.
export function replaceTaskLine( markdown: string, lineNumber: number, update: { checked?: boolean; status?: string; text?: string }, ): string { const lines = markdown.replace(/\r\n/g, "\n").split("\n"); const idx = lineNumber - 1; const line = lines[idx]; if (!line) throw new Error(`Line ${lineNumber} does not exist`); const match = /^(\s*[-*]\s+\[)([^\]])(\]\s+)(.*)$/.exec(line); if (!match) throw new Error(`Line ${lineNumber} is not a Markdown task`); const status = update.status ?? (update.checked === undefined ? match[2] : update.checked ? "x" : " "); const text = update.text ?? match[4]; lines[idx] = `${match[1]}${status}${match[3]}${text}`; return lines.join("\n"); }