mcp-quickbase
Version:
Work with Quickbase via Model Context Protocol
102 lines • 3.58 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.BulkUpdateRecordsTool = void 0;
const base_1 = require("../base");
const logger_1 = require("../../utils/logger");
const logger = (0, logger_1.createLogger)("BulkUpdateRecordsTool");
/**
* Tool for updating multiple records in a Quickbase table
*/
class BulkUpdateRecordsTool extends base_1.BaseTool {
/**
* Constructor
* @param client Quickbase client
*/
constructor(client) {
super(client);
this.name = "bulk_update_records";
this.description = "Updates multiple records in a Quickbase table";
/**
* Parameter schema for bulk_update_records
*/
this.paramSchema = {
type: "object",
properties: {
table_id: {
type: "string",
description: "The ID of the Quickbase table",
},
records: {
type: "array",
description: "Array of record data to update (must include record IDs)",
items: {
type: "object",
additionalProperties: true,
},
},
},
required: ["table_id", "records"],
};
}
/**
* Run the bulk_update_records tool
* @param params Tool parameters
* @returns Bulk update result
*/
async run(params) {
const { table_id, records } = params;
logger.info(`Bulk updating ${records.length} records in Quickbase table`, {
tableId: table_id,
recordCount: records.length,
});
// Validate records
if (!records || !Array.isArray(records) || records.length === 0) {
throw new Error("Records array is required and must not be empty");
}
// Check if all records have IDs
const missingIds = records.some((record) => !record.id);
if (missingIds) {
throw new Error('All records must include an "id" field for bulk updates');
}
// Prepare record data
const formattedRecords = records.map((record) => {
const { id, ...fields } = record;
const recordData = { id };
for (const [field, value] of Object.entries(fields)) {
recordData[field] = { value };
}
return recordData;
});
// Prepare request body
const body = {
to: table_id,
data: formattedRecords,
};
// Update the records
const response = await this.client.request({
method: "POST",
path: "/records",
body,
});
if (!response.success || !response.data) {
logger.error("Failed to bulk update records", {
error: response.error,
tableId: table_id,
});
throw new Error(response.error?.message || "Failed to bulk update records");
}
const recordIds = records.map((record) => record.id);
logger.info(`Successfully updated ${recordIds.length} records`, {
recordCount: recordIds.length,
tableId: table_id,
});
return {
recordIds,
tableId: table_id,
updatedCount: recordIds.length,
updatedTime: new Date().toISOString(),
};
}
}
exports.BulkUpdateRecordsTool = BulkUpdateRecordsTool;
//# sourceMappingURL=bulk_update_records.js.map