FindLabels
Filter and retrieve record labels from RushDB with customizable conditions, sorting, and pagination options for precise data queries.
Instructions
Find / filter record labels (supports where, limit, skip, orderBy). Superset of GetLabels.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| where | No | Filter conditions for labels (e.g., by activity flags, counts) | |
| limit | No | Maximum number of labels to return | |
| skip | No | Number of labels to skip | |
| orderBy | No | Sorting configuration: key = field, value = asc|desc |
Implementation Reference
- tools/FindLabels.ts:23-47 (handler)The core handler function that executes the tool logic: queries the labels in the database using provided where, limit, skip, orderBy filters and normalizes the response to [{name, count}] array.export async function FindLabels( params: { where?: Record<string, any> limit?: number skip?: number orderBy?: Record<string, 'asc' | 'desc'> } = {} ) { const { where, limit, skip, orderBy } = params const searchQuery: Record<string, any> = {} if (where) searchQuery.where = where if (typeof limit === 'number') searchQuery.limit = limit if (typeof skip === 'number') searchQuery.skip = skip if (orderBy && Object.keys(orderBy).length > 0) searchQuery.orderBy = orderBy const response = await db.labels.find(searchQuery) // Existing labels.find returns an object mapping label->count when empty query supplied. // When filters applied, SDK still returns .data as mapping; normalize to array. if (response?.success && response.data) { return Object.entries(response.data).map(([name, count]) => ({ name, count })) } return [] }
- tools.ts:58-74 (schema)JSON Schema definition for the input parameters of the FindLabels tool.inputSchema: { type: 'object', properties: { where: { type: 'object', description: 'Filter conditions for labels (e.g., by activity flags, counts)' }, limit: { type: 'number', description: 'Maximum number of labels to return' }, skip: { type: 'number', description: 'Number of labels to skip' }, orderBy: { type: 'object', description: 'Sorting configuration: key = field, value = asc|desc', additionalProperties: { type: 'string', enum: ['asc', 'desc'] } } }, required: [] }
- tools.ts:55-75 (registration)Registration of the FindLabels tool in the exported tools array used by MCP for listing available tools.{ name: 'FindLabels', description: 'Find / filter record labels (supports where, limit, skip, orderBy). Superset of GetLabels.', inputSchema: { type: 'object', properties: { where: { type: 'object', description: 'Filter conditions for labels (e.g., by activity flags, counts)' }, limit: { type: 'number', description: 'Maximum number of labels to return' }, skip: { type: 'number', description: 'Number of labels to skip' }, orderBy: { type: 'object', description: 'Sorting configuration: key = field, value = asc|desc', additionalProperties: { type: 'string', enum: ['asc', 'desc'] } } }, required: [] } },
- index.ts:118-135 (registration)MCP CallToolRequest handler switch case that dispatches to the FindLabels implementation and formats the textual response.case 'FindLabels': const foundLabels = await FindLabels({ 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 }) return { content: [ { type: 'text', text: foundLabels.length > 0 ? foundLabels.map((l: any) => `${l.name}: ${l.count} records`).join('\n') : 'No labels found' } ] }