ExportRecords
Export database records to CSV format with filtering, sorting, and limit options for data analysis and reporting.
Instructions
Export records to CSV format
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| labels | No | Filter by record labels | |
| limit | No | Maximum number of records to export | |
| orderBy | No | Sorting configuration for export | |
| where | No | Search conditions for records to export |
Implementation Reference
- tools/ExportRecords.ts:17-50 (handler)The core handler function for the ExportRecords tool. It constructs a search query from parameters and calls db.records.export to generate CSV output.export async function ExportRecords(params: { labels?: string[] where?: Record<string, any> limit?: number }) { const { labels, where, limit } = params const searchQuery: any = {} if (labels && labels.length > 0) { searchQuery.labels = labels } if (where) { searchQuery.where = where } if (limit) { searchQuery.limit = limit } const result = await db.records.export(searchQuery) if (result.success && result.data) { return { csv: result.data.fileContent, dateTime: result.data.dateTime, message: 'Records exported successfully' } } return { csv: '', dateTime: new Date().toISOString(), message: 'No records found to export' } }
- tools.ts:286-299 (schema)JSON Schema definition for the ExportRecords tool input parameters, defining labels, where, limit, and orderBy.inputSchema: { type: 'object', properties: { labels: { type: 'array', items: { type: 'string' }, description: 'Filter by record labels' }, where: { type: 'object', description: 'Search conditions for records to export' }, limit: { type: 'number', description: 'Maximum number of records to export' }, orderBy: { type: 'object', description: 'Sorting configuration for export', additionalProperties: { type: 'string', enum: ['asc', 'desc'] } } }, required: [] }
- tools.ts:283-300 (registration)Registration of the ExportRecords tool in the tools array, including name, description, and schema for MCP ListTools.{ name: 'ExportRecords', description: 'Export records to CSV format', inputSchema: { type: 'object', properties: { labels: { type: 'array', items: { type: 'string' }, description: 'Filter by record labels' }, where: { type: 'object', description: 'Search conditions for records to export' }, limit: { type: 'number', description: 'Maximum number of records to export' }, orderBy: { type: 'object', description: 'Sorting configuration for export', additionalProperties: { type: 'string', enum: ['asc', 'desc'] } } }, required: [] } },
- index.ts:303-316 (registration)Dispatcher/registration in the MCP CallToolRequest switch statement, invoking the handler with arguments and formatting response.case 'ExportRecords': const exportResult = await ExportRecords({ labels: args.labels as string[] | undefined, where: args.where as Record<string, any> | undefined, limit: args.limit as number | undefined }) return { content: [ { type: 'text', text: `Export completed at ${exportResult.dateTime}\n\n${exportResult.csv}` } ] }
- index.ts:37-37 (registration)Import statement bringing the ExportRecords handler into the main index.ts for use in tool dispatching.import { ExportRecords } from './tools/ExportRecords.js'