mcp-quickbase
Version:
Work with Quickbase via Model Context Protocol
96 lines • 3.35 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.GetTableFieldsTool = void 0;
const base_1 = require("../base");
const logger_1 = require("../../utils/logger");
const logger = (0, logger_1.createLogger)("GetTableFieldsTool");
/**
* Tool for retrieving field information for a specific Quickbase table
*/
class GetTableFieldsTool extends base_1.BaseTool {
/**
* Constructor
* @param client Quickbase client
*/
constructor(client) {
super(client);
this.name = "get_table_fields";
this.description = "Retrieves field information for a specific Quickbase table";
/**
* Parameter schema for get_table_fields
*/
this.paramSchema = {
type: "object",
properties: {
table_id: {
type: "string",
description: "The ID of the Quickbase table",
},
include_system: {
type: "boolean",
description: "Whether to include system fields",
},
field_type: {
type: "string",
description: "Filter fields by type",
},
},
required: ["table_id"],
};
}
/**
* Run the get_table_fields tool
* @param params Tool parameters
* @returns Table field information
*/
async run(params) {
const { table_id, include_system, field_type } = params;
logger.info("Getting fields for Quickbase table", {
tableId: table_id,
includeSystem: include_system,
});
// Prepare query parameters
const queryParams = {};
if (include_system !== undefined) {
queryParams.includeSystem = include_system.toString();
}
// Get fields in the table
const response = await this.client.request({
method: "GET",
path: `/fields?tableId=${table_id}`,
params: queryParams,
});
if (!response.success || !response.data) {
logger.error("Failed to get table fields", {
error: response.error,
tableId: table_id,
});
throw new Error(response.error?.message || "Failed to get table fields");
}
// Cast data to array of fields
let fields = response.data.map((field) => ({
id: field.id,
label: field.label,
fieldType: field.fieldType,
description: field.description,
required: field.required,
unique: field.unique,
properties: field.properties,
...field,
}));
// Filter fields by type if requested
if (field_type && field_type.trim() !== "") {
fields = fields.filter((field) => field.fieldType.toLowerCase() === field_type.toLowerCase());
}
logger.info(`Found ${fields.length} fields in table`, {
tableId: table_id,
fieldTypes: [...new Set(fields.map((f) => f.fieldType))].join(", "),
});
return {
fields,
tableId: table_id,
};
}
}
exports.GetTableFieldsTool = GetTableFieldsTool;
//# sourceMappingURL=get_table_fields.js.map