UNPKG

mcp-quickbase

Version:

Work with Quickbase via Model Context Protocol

115 lines 4.28 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.UpdateFieldTool = void 0; const base_1 = require("../base"); const logger_1 = require("../../utils/logger"); const logger = (0, logger_1.createLogger)("UpdateFieldTool"); /** * Tool for updating an existing field in a Quickbase table */ class UpdateFieldTool extends base_1.BaseTool { /** * Constructor * @param client Quickbase client */ constructor(client) { super(client); this.name = "update_field"; this.description = "Updates an existing field in a Quickbase table. " + "Can modify the field label, help text, and properties. " + "Note: Field type cannot be changed - delete and recreate the field instead."; /** * Parameter schema for update_field */ this.paramSchema = { type: "object", properties: { table_id: { type: "string", description: "The ID of the table (e.g., 'bqx7xkw3r')", }, field_id: { type: "string", description: "The ID of the field to update (e.g., '6')", }, name: { type: "string", description: "New display label for the field", }, description: { type: "string", description: "Help text shown to users when editing the field (stored as fieldHelp)", }, options: { type: "object", description: "Field properties to update: required, unique, appearsByDefault, " + "findEnabled, maxLength, numLines, defaultValue, etc.", }, }, required: ["table_id", "field_id"], }; } /** * Run the update_field tool * @param params Tool parameters * @returns Updated field details */ async run(params) { const { table_id, field_id, name, description, options } = params; logger.info("Updating field in Quickbase table", { tableId: table_id, fieldId: field_id, }); // At least one update field is required if (!name && !description && (!options || Object.keys(options).length === 0)) { throw new Error("At least one update field (name, description, or options) is required"); } // Prepare request body with only the fields that are provided // Note: Quickbase API uses 'fieldHelp' at root level for help text (not 'description') // Note: Field type cannot be changed via API - must delete and recreate const body = {}; if (name !== undefined) { body.label = name; } // Add fieldHelp if description provided (maps to root-level fieldHelp) if (description !== undefined) { body.fieldHelp = description; } // Add properties if provided if (options && Object.keys(options).length > 0) { body.properties = { ...options }; } // Update the field const response = await this.client.request({ method: "POST", path: `/fields/${field_id}?tableId=${table_id}`, body, }); if (!response.success || !response.data) { logger.error("Failed to update field", { error: response.error, tableId: table_id, fieldId: field_id, }); throw new Error(response.error?.message || "Failed to update field"); } const field = response.data; logger.info("Successfully updated field", { fieldId: field.id, tableId: table_id, updates: Object.keys(body).join(", "), }); return { fieldId: field.id, label: field.label, fieldType: field.fieldType, fieldHelp: field.fieldHelp, tableId: table_id, ...field, }; } } exports.UpdateFieldTool = UpdateFieldTool; //# sourceMappingURL=update_field.js.map