export_local_documents
Export matching offline Salesforce documentation pages as a single Markdown file by specifying output path, URL prefix, or category.
Instructions
Export all matching offline documentation pages concatenated into a single Markdown file on your local machine.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| outputPath | Yes | Absolute file path to save the .md file. | |
| urlPrefix | No | Filter to URLs starting with this. | |
| category | No | Filter by category. |
Implementation Reference
- src/db.ts:266-334 (handler)Core handler function that queries the SQLite database for documents matching optional urlPrefix/category filters, concatenates their markdown chunks, and writes the result to a local .md file via writeFileSync.
export async function exportLocalDocuments(outputPath: string, urlPrefix?: string, category?: string) { const database = await getDatabase(); let query = 'SELECT d.id, d.title, d.url FROM documents d'; const conditions = []; const params = []; if (urlPrefix) { conditions.push('d.url LIKE ?'); params.push(`${urlPrefix}%`); } if (category) { conditions.push('d.category = ?'); params.push(category); } if (conditions.length > 0) { query += ' WHERE ' + conditions.join(' AND '); } query += ' ORDER BY d.url ASC'; const docStmt = database.prepare(query); docStmt.bind(params); const documents = []; while (docStmt.step()) { const row = docStmt.get(); documents.push({ id: row[0], title: row[1], url: row[2] }); } docStmt.free(); if (documents.length === 0) { return { success: false, count: 0, message: "No documents matched the provided filters." }; } let combinedMarkdown = `# Filtered Export (${documents.length} pages)\n\n`; if (urlPrefix) combinedMarkdown += `**URL Prefix:** \`${urlPrefix}\`\n`; if (category) combinedMarkdown += `**Category:** \`${category}\`\n`; combinedMarkdown += `---\n\n`; // Extract chunks for each matched document for (const doc of documents) { const chunkStmt = database.prepare('SELECT content FROM chunks WHERE document_id = ? ORDER BY chunk_index ASC'); chunkStmt.bind([doc.id]); let markdown = ''; while (chunkStmt.step()) { const row = chunkStmt.get(); markdown += row[0] + '\n\n'; } chunkStmt.free(); // Append to the giant file combinedMarkdown += `# ${doc.title}\n`; combinedMarkdown += `**Source:** [${doc.url}](${doc.url})\n\n`; combinedMarkdown += `${markdown.trim()}\n\n---\n\n`; } // Write directly to user's disk writeFileSync(outputPath, combinedMarkdown, { encoding: 'utf-8' }); return { success: true, count: documents.length, message: `Successfully exported ${documents.length} documents to ${outputPath}` }; } - src/index.ts:39-43 (schema)Zod schema (ExportDocsSchema) defining the input parameters: outputPath (required), urlPrefix (optional), category (optional).
const ExportDocsSchema = z.object({ outputPath: z.string().describe("The absolute path on your local machine to save the compiled Markdown file (e.g. /Users/name/Desktop/guide.md)"), urlPrefix: z.string().optional().describe("Optional. Only export documents whose URL starts with this string. Useful for clustering sections of a guide."), category: z.string().optional().describe("Optional. Only export documents tagged with this category.") }); - src/index.ts:97-109 (registration)Tool registration in the ListToolsRequestSchema handler, declaring the tool name 'export_local_documents', description, and input JSON schema.
{ name: "export_local_documents", description: "Export all matching offline documentation pages concatenated into a single Markdown file on your local machine.", inputSchema: { type: "object", properties: { outputPath: { type: "string", description: "Absolute file path to save the .md file." }, urlPrefix: { type: "string", description: "Filter to URLs starting with this." }, category: { type: "string", description: "Filter by category." } }, required: ["outputPath"] } } - src/index.ts:248-260 (handler)CallToolRequestSchema handler that parses args with ExportDocsSchema, calls exportLocalDocuments(), and returns success/error response.
if (name === "export_local_documents") { const { outputPath, urlPrefix, category } = ExportDocsSchema.parse(args); console.error(`Exporting documents to ${outputPath}...`); const exportResult = await exportLocalDocuments(outputPath, urlPrefix, category); if (!exportResult.success) { return { content: [{ type: "text", text: `Export Failed: ${exportResult.message}` }], isError: true }; } return { content: [{ type: "text", text: exportResult.message }] }; }