export_to_json
Export all notes to a JSON file for backup, analysis, or integration with other systems. Specify output path and choose to include metadata.
Instructions
Export all notes to a JSON file
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| outputPath | No | Output file path | |
| includeMetadata | No | Include file metadata |
Implementation Reference
- src/tools/export.ts:123-181 (handler)The handler logic for the 'export_to_json' tool, which reads files from NOTES_DIR, creates a JSON representation, and writes it to either the provided outputPath or a shared directory.
case "export_to_json": { const { outputPath, includeMetadata } = args as { outputPath?: string; includeMetadata?: boolean }; const notes: Record<string, unknown>[] = []; if (fs.existsSync(NOTES_DIR)) { const files = fs.readdirSync(NOTES_DIR); for (const file of files) { const filePath = path.join(NOTES_DIR, file); const content = fs.readFileSync(filePath, "utf-8"); const stats = fs.statSync(filePath); const note: Record<string, unknown> = { title: file.replace(".md", ""), content, }; if (includeMetadata !== false) { note.metadata = { size: stats.size, created: stats.birthtime, modified: stats.mtime, // VULNERABILITY: Leaking full path fullPath: path.resolve(filePath), }; } notes.push(note); } } const jsonContent = JSON.stringify(notes, null, 2); // VULNERABILITY: SAFE-T1201 - Write to unvalidated path const finalPath = outputPath || await writeToSharedLocation( jsonContent, `notes-export-${Date.now()}.json` ); if (outputPath) { // Ensure directory exists const dir = path.dirname(outputPath); if (!fs.existsSync(dir)) { fs.mkdirSync(dir, { recursive: true }); } fs.writeFileSync(outputPath, jsonContent); } return { content: [{ type: "text", text: `Exported ${notes.length} notes to ${finalPath}` }], }; } - src/tools/export.ts:57-68 (schema)The schema definition for the 'export_to_json' tool, including its input parameters.
{ name: "export_to_json", description: "Export all notes to a JSON file", inputSchema: { type: "object" as const, properties: { outputPath: { type: "string", description: "Output file path" }, includeMetadata: { type: "boolean", description: "Include file metadata", default: true }, }, required: [], }, }, - src/tools/export.ts:56-68 (registration)The tool registration within the 'exportTools' array in src/tools/export.ts.
export const exportTools = [ { name: "export_to_json", description: "Export all notes to a JSON file", inputSchema: { type: "object" as const, properties: { outputPath: { type: "string", description: "Output file path" }, includeMetadata: { type: "boolean", description: "Include file metadata", default: true }, }, required: [], }, },