mcp-quickbase
Version:
Work with Quickbase via Model Context Protocol
101 lines • 3.35 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.UpdateRecordTool = void 0;
const base_1 = require("../base");
const logger_1 = require("../../utils/logger");
const logger = (0, logger_1.createLogger)("UpdateRecordTool");
/**
* Tool for updating an existing record in a Quickbase table
*/
class UpdateRecordTool extends base_1.BaseTool {
/**
* Constructor
* @param client Quickbase client
*/
constructor(client) {
super(client);
this.name = "update_record";
this.description = "Updates an existing record in a Quickbase table";
/**
* Parameter schema for update_record
*/
this.paramSchema = {
type: "object",
properties: {
table_id: {
type: "string",
description: "The ID of the Quickbase table",
},
record_id: {
type: "string",
description: "The ID of the record to update",
},
data: {
type: "object",
description: "The updated data for the record",
additionalProperties: true,
},
},
required: ["table_id", "record_id", "data"],
};
}
/**
* Run the update_record tool
* @param params Tool parameters
* @returns Updated record information
*/
async run(params) {
const { table_id, record_id, data } = params;
logger.info("Updating record in Quickbase table", {
tableId: table_id,
recordId: record_id,
});
// Validate data
if (!data || typeof data !== "object" || Object.keys(data).length === 0) {
throw new Error("Update data is required and must be a non-empty object");
}
// Prepare record data
// Convert data to { [fieldId]: { value: fieldValue } } format expected by the API
const recordData = {};
for (const [field, value] of Object.entries(data)) {
recordData[field] = { value };
}
// Prepare request body
const body = {
to: table_id,
data: [
{
id: record_id,
...recordData,
},
],
};
// Update the record
const response = await this.client.request({
method: "POST",
path: "/records",
body,
});
if (!response.success || !response.data) {
logger.error("Failed to update record", {
error: response.error,
tableId: table_id,
recordId: record_id,
});
throw new Error(response.error?.message || "Failed to update record");
}
logger.info("Successfully updated record", {
recordId: record_id,
tableId: table_id,
updatedFields: Object.keys(data),
});
return {
recordId: record_id,
tableId: table_id,
updatedTime: new Date().toISOString(),
updatedFields: Object.keys(data),
};
}
}
exports.UpdateRecordTool = UpdateRecordTool;
//# sourceMappingURL=update_record.js.map