get_canvas
Retrieve canvas file contents from Obsidian vaults to access and work with visual knowledge maps and structured content.
Instructions
Get canvas file contents
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"vault": "<vault>",
"path": "<path>"
},
"name": "get_canvas"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Path to canvas file | |
| vault | Yes | Vault name |
Implementation Reference
- src/index.ts:216-225 (registration)Registration of the 'get_canvas' tool including name, description, and input schema.
name: 'get_canvas', description: 'Get canvas file contents', inputSchema: { type: 'object', properties: { vault: { type: 'string', description: 'Vault name' }, path: { type: 'string', description: 'Path to canvas file' }, }, required: ['vault', 'path'], }, - src/index.ts:641-650 (handler)Handler case for 'get_canvas' tool that retrieves the connector and calls CanvasService.readCanvas.
case 'get_canvas': { const connector = this.connectors.get(args?.vault as string); if (!connector || !connector.vaultPath) { throw new Error(`Vault "${args?.vault}" not found or not a local vault`); } const result = await this.canvasService.readCanvas(connector.vaultPath, args?.path as string); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }], }; } - src/services/CanvasService.ts:64-77 (handler)Core implementation of get_canvas: reads the canvas file from the vault path and parses its JSON content.
async readCanvas(vaultPath: string, canvasPath: string): Promise<VaultOperationResult<CanvasData>> { try { const fullPath = path.join(vaultPath, canvasPath); const content = await fs.readFile(fullPath, 'utf-8'); const data: CanvasData = JSON.parse(content); return { success: true, data }; } catch (error) { return { success: false, error: `Failed to read canvas: ${error instanceof Error ? error.message : String(error)}` }; } }