ExportRecords
Export database records to CSV format with filtering, sorting, and limit options for data analysis and sharing.
Instructions
Export records to CSV format
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "ExportRecords"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| labels | No | Filter by record labels | |
| where | No | Search conditions for records to export | |
| limit | No | Maximum number of records to export | |
| orderBy | No | Sorting configuration for export |
Implementation Reference
- tools/ExportRecords.ts:17-50 (handler)The core handler function that performs the record export to CSV using the database export method based on provided labels, where clause, and limit.
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:283-300 (schema)JSON schema definition for the ExportRecords tool input, including parameters for labels, where, limit, and orderBy.
{ 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)Registration and dispatching logic in the main MCP server handler's switch case for calling the ExportRecords tool and formatting the 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 that brings the ExportRecords handler into the main index file for use in the tool dispatcher.
import { ExportRecords } from './tools/ExportRecords.js' - tools.ts:30-30 (registration)Tool name included in the ToolName type union for type-safe tool handling.
| 'ExportRecords'