mcp-quickbase
Version:
Work with Quickbase via Model Context Protocol
100 lines • 3.55 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ListTablesTool = void 0;
const base_1 = require("../base");
const logger_1 = require("../../utils/logger");
const logger = (0, logger_1.createLogger)('ListTablesTool');
/**
* Tool for listing tables in a Quickbase application
*/
class ListTablesTool extends base_1.BaseTool {
/**
* Constructor
* @param client Quickbase client
*/
constructor(client) {
super(client);
this.name = 'list_tables';
this.description = 'Lists all tables in the Quickbase application';
/**
* Parameter schema for list_tables
*/
this.paramSchema = {
type: 'object',
properties: {
app_id: {
type: 'string',
description: 'The ID of the application'
},
include_hidden: {
type: 'boolean',
description: 'Whether to include hidden tables'
},
filter: {
type: 'string',
description: 'Filter tables by name (case-insensitive substring match)'
}
},
required: []
};
}
/**
* Run the list_tables tool
* @param params Tool parameters
* @returns List of tables in the application
*/
async run(params) {
const { app_id, include_hidden, filter } = params;
// Use provided app_id or fall back to the one from config
const appId = app_id || this.client.getConfig().appId;
if (!appId) {
throw new Error('Application ID is required but not provided in parameters or configuration');
}
logger.info('Listing tables in Quickbase application', {
appId,
includeHidden: include_hidden
});
// Prepare query parameters
const queryParams = {};
if (include_hidden !== undefined) {
queryParams.includeHidden = include_hidden.toString();
}
// List tables in the application
const response = await this.client.request({
method: 'GET',
path: `/tables?appId=${appId}`,
params: queryParams
});
if (!response.success || !response.data) {
logger.error('Failed to list tables', {
error: response.error,
appId
});
throw new Error(response.error?.message || 'Failed to list tables');
}
// Cast data to array of tables
let tables = response.data.map(table => ({
id: table.id,
name: table.name,
description: table.description,
singleRecordName: table.singleRecordName,
pluralRecordName: table.pluralRecordName,
created: table.created,
updated: table.updated,
...table
}));
// Filter tables if requested
if (filter && filter.trim() !== '') {
const filterLower = filter.toLowerCase();
tables = tables.filter(table => table.name.toLowerCase().includes(filterLower) ||
(table.description && table.description.toLowerCase().includes(filterLower)));
}
logger.info(`Found ${tables.length} tables in application`, { appId });
return {
tables,
appId
};
}
}
exports.ListTablesTool = ListTablesTool;
//# sourceMappingURL=list_tables.js.map