FindRecords
Search and filter database records using queries, labels, sorting, and aggregation to retrieve specific data from RushDB.
Instructions
Find records in the database using a search query
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| aggregate | No | Aggregation definitions (records only) | |
| groupBy | No | Fields to group by (records only) | |
| labels | No | Filter by record labels | |
| limit | No | Maximum number of records to return | |
| orderBy | No | Sorting configuration: key = field, value = asc|desc | |
| skip | No | Number of records to skip | |
| where | No | Search conditions for finding records |
Implementation Reference
- tools/FindRecords.ts:17-45 (handler)The core handler function implementing the FindRecords tool logic. Constructs a searchQuery from params and executes db.records.find().export async function FindRecords(params: { labels?: string[] where?: Record<string, any> limit?: number skip?: number orderBy?: Record<string, 'asc' | 'desc'> aggregate?: Record<string, { fn: string; field?: string; alias?: string; where?: any }> groupBy?: string[] }) { const { labels, where, limit = 10, skip = 0, orderBy, aggregate, groupBy } = params const searchQuery: any = {} if (labels && labels.length > 0) searchQuery.labels = labels if (where) searchQuery.where = where if (limit) searchQuery.limit = limit if (skip) searchQuery.skip = skip if (orderBy && Object.keys(orderBy).length > 0) searchQuery.orderBy = orderBy if (aggregate && Object.keys(aggregate).length > 0) searchQuery.aggregate = aggregate if (groupBy && groupBy.length > 0) searchQuery.groupBy = groupBy const result = await db.records.find(searchQuery) // If aggregation present, return raw response so caller gets aggregates. if (searchQuery.aggregate || searchQuery.groupBy) { return result } return result.data.map((record: any) => record.data) }
- tools.ts:115-158 (schema)The JSON schema definition for the FindRecords tool input, defining parameters like labels, where, aggregate, groupBy, etc.{ name: 'FindRecords', description: 'Find records in the database using a search query', inputSchema: { type: 'object', properties: { labels: { type: 'array', items: { type: 'string' }, description: 'Filter by record labels' }, where: { type: 'object', description: 'Search conditions for finding records' }, limit: { type: 'number', description: 'Maximum number of records to return', default: 10 }, skip: { type: 'number', description: 'Number of records to skip', default: 0 }, orderBy: { type: 'object', description: 'Sorting configuration: key = field, value = asc|desc', additionalProperties: { type: 'string', enum: ['asc', 'desc'] } }, aggregate: { type: 'object', description: 'Aggregation definitions (records only)', additionalProperties: { type: 'object', properties: { fn: { type: 'string', description: 'Aggregation function (count,sum,avg,min,max,timeBucket)' }, field: { type: 'string', description: 'Field to aggregate' }, alias: { type: 'string', description: 'Optional alias override' }, granularity: { type: 'string', description: 'For timeBucket, the time granularity (e.g., day, week, month, quarter, year)' } }, required: ['fn'] } }, groupBy: { type: 'array', items: { type: 'string' }, description: 'Fields to group by (records only)' } }, required: [] } },
- index.ts:182-206 (registration)Registration and dispatch in the MCP server handler: switch case that calls the FindRecords function with validated args and formats response.case 'FindRecords': const foundRecords = await FindRecords({ labels: args.labels as string[] | undefined, where: args.where as Record<string, any> | undefined, limit: args.limit as number | undefined, skip: args.skip as number | undefined, orderBy: args.orderBy as Record<string, 'asc' | 'desc'> | undefined, aggregate: args.aggregate as | Record<string, { fn: string; field?: string; alias?: string; where?: any }> | undefined, groupBy: args.groupBy as string[] | undefined }) const isAggregate = Boolean(args.aggregate) || Boolean(args.groupBy) return { content: [ { type: 'text', text: Array.isArray(foundRecords) && foundRecords.length === 0 ? 'No matching records found.' : JSON.stringify(foundRecords, null, 2) } ] }
- index.ts:30-30 (registration)Import statement registering the FindRecords handler for use in the MCP tool dispatch.import { FindRecords } from './tools/FindRecords.js'