Get note metadata
obsidian_get_metadataRetrieve metadata for an Obsidian note, including frontmatter, tags, links, and file stats, returned as JSON.
Instructions
Returns metadata for a note (frontmatter, tags, links, file stats) as JSON.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| vault | No | Vault name to target. Optional — defaults to the most recently focused vault. | |
| file | No | Note name resolved as a wikilink (e.g. 'My Note'). Provide either `file` or `path`. | |
| path | No | Vault-root-relative path to the note (e.g. 'Folder/My Note.md'). Provide either `file` or `path`. |
Implementation Reference
- src/tools.ts:322-332 (schema)Input schema for obsidian_get_metadata – accepts optional vault, and either file (wikilink) or path (vault-relative path).
name: "obsidian_get_metadata", title: "Get note metadata", description: "Returns metadata for a note (frontmatter, tags, links, file stats) as JSON.", inputSchema: { ...VaultArg, ...FileTargetArg }, annotations: { readOnlyHint: true, openWorldHint: false }, handler: async ({ vault, file, path }) => { requireFileTarget({ file, path }); return runJson("file", { vault, params: { file, path } }); }, }, - src/tools.ts:328-331 (handler)Handler function for obsidian_get_metadata – validates that file or path is provided, then delegates to runJson which invokes the Obsidian CLI's 'file' command to fetch metadata (frontmatter, tags, links, file stats) as JSON.
handler: async ({ vault, file, path }) => { requireFileTarget({ file, path }); return runJson("file", { vault, params: { file, path } }); }, - src/tools.ts:7-14 (helper)Shared schema fragment VaultArg – optional vault name parameter reused across tools.
const VaultArg = { vault: z .string() .optional() .describe( "Vault name to target. Optional — defaults to the most recently focused vault.", ), }; - src/tools.ts:16-29 (helper)Shared schema fragment FileTargetArg – reusable file or path parameter for targeting notes.
const FileTargetArg = { file: z .string() .optional() .describe( "Note name resolved as a wikilink (e.g. 'My Note'). Provide either `file` or `path`.", ), path: z .string() .optional() .describe( "Vault-root-relative path to the note (e.g. 'Folder/My Note.md'). Provide either `file` or `path`.", ), }; - src/tools.ts:31-37 (helper)requireFileTarget validation helper – throws if neither file nor path is provided.
function requireFileTarget(input: { file?: string; path?: string }) { if (!input.file && !input.path) { throw new Error( "Either `file` (wikilink name) or `path` (vault-relative path) must be provided.", ); } } - src/tools.ts:82-97 (helper)runJson helper – executes an Obsidian CLI command with JSON output and parses the result.
async function runJson( command: string, opts: Parameters<typeof runObsidian>[1] = {}, ): Promise<McpToolResult> { try { const result = await runObsidian(command, { ...opts, format: opts.format ?? "json" }); const parsed = parseJsonOrText(result.stdout); const text = typeof parsed === "string" ? parsed : JSON.stringify(parsed, null, 2); return textResult(text || "(no output)", parsed); } catch (err) { return errorResult(err); } } - src/index.ts:40-51 (registration)Tool registration in index.ts – each tool in the tools array is registered with the MCP server via server.registerTool.
for (const tool of tools) { server.registerTool( tool.name, { title: tool.title, description: tool.description, inputSchema: tool.inputSchema, annotations: tool.annotations, }, buildHandler(server, tool), ); }