get-table-data
Retrieve data from Firebird database tables with filtering, pagination, and sorting options to extract specific information efficiently.
Instructions
Retrieves data from a specific table with optional filtering, pagination, and ordering.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| tableName | Yes | Name of the table to retrieve data from | |
| first | No | Number of rows to retrieve (FIRST clause in Firebird) | |
| skip | No | Number of rows to skip (SKIP clause in Firebird) | |
| where | No | Optional WHERE clause (without the WHERE keyword) | |
| orderBy | No | Optional ORDER BY clause (without the ORDER BY keyword) |
Implementation Reference
- src/tools/database.ts:552-595 (handler)The handler function constructs a dynamic SQL SELECT query based on input parameters (tableName, first, skip, where, orderBy) and executes it using executeQuery to retrieve table data.handler: async (args: z.infer<typeof GetTableDataArgsSchema>) => { const { tableName, first, skip, where, orderBy } = args; logger.info(`Getting data from table: ${tableName}`); try { let sql = `SELECT * FROM "${tableName}"`; if (where) { sql += ` WHERE ${where}`; } if (orderBy) { sql += ` ORDER BY ${orderBy}`; } if (first !== undefined) { sql = `SELECT FIRST ${first} ${skip ? `SKIP ${skip}` : ''} * FROM "${tableName}"${where ? ` WHERE ${where}` : ''}${orderBy ? ` ORDER BY ${orderBy}` : ''}`; } const result = await executeQuery(sql); logger.info(`Retrieved ${result.length} rows from ${tableName}`); return { content: [{ type: "text", text: formatForClaude({ tableName, rowCount: result.length, data: result }) }] }; } catch (error) { const errorResponse = wrapError(error); logger.error(`Error getting data from ${tableName}: ${errorResponse.error}`); return { content: [{ type: "text", text: formatForClaude(errorResponse) }] }; } }
- src/tools/database.ts:105-111 (schema)Zod input schema validating the arguments: tableName (required), first/skip (optional pagination), where/orderBy (optional filtering/sorting).export const GetTableDataArgsSchema = z.object({ tableName: z.string().min(1).describe("Name of the table to retrieve data from"), first: z.number().int().positive().optional().describe("Number of rows to retrieve (FIRST clause in Firebird)"), skip: z.number().int().min(0).optional().describe("Number of rows to skip (SKIP clause in Firebird)"), where: z.string().optional().describe("Optional WHERE clause (without the WHERE keyword)"), orderBy: z.string().optional().describe("Optional ORDER BY clause (without the ORDER BY keyword)") });
- src/tools/database.ts:547-596 (registration)Tool registration in the setupDatabaseTools() function, adding 'get-table-data' to the tools Map with name, description, schema, and inline handler.tools.set("get-table-data", { name: "get-table-data", title: "Get Table Data", description: "Retrieves data from a specific table with optional filtering, pagination, and ordering.", inputSchema: GetTableDataArgsSchema, handler: async (args: z.infer<typeof GetTableDataArgsSchema>) => { const { tableName, first, skip, where, orderBy } = args; logger.info(`Getting data from table: ${tableName}`); try { let sql = `SELECT * FROM "${tableName}"`; if (where) { sql += ` WHERE ${where}`; } if (orderBy) { sql += ` ORDER BY ${orderBy}`; } if (first !== undefined) { sql = `SELECT FIRST ${first} ${skip ? `SKIP ${skip}` : ''} * FROM "${tableName}"${where ? ` WHERE ${where}` : ''}${orderBy ? ` ORDER BY ${orderBy}` : ''}`; } const result = await executeQuery(sql); logger.info(`Retrieved ${result.length} rows from ${tableName}`); return { content: [{ type: "text", text: formatForClaude({ tableName, rowCount: result.length, data: result }) }] }; } catch (error) { const errorResponse = wrapError(error); logger.error(`Error getting data from ${tableName}: ${errorResponse.error}`); return { content: [{ type: "text", text: formatForClaude(errorResponse) }] }; } } });