UNPKG

mcp-quickbase

Version:

Work with Quickbase via Model Context Protocol

114 lines 3.89 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'; /** * Parameter schema for update_field */ this.paramSchema = { type: 'object', properties: { table_id: { type: 'string', description: 'The ID of the table' }, field_id: { type: 'string', description: 'The ID of the field' }, name: { type: 'string', description: 'New name for the field' }, field_type: { type: 'string', description: 'New type for the field' }, description: { type: 'string', description: 'New description for the field' }, options: { type: 'object', description: 'Additional field options' } }, 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, field_type, 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 && !field_type && (!options || Object.keys(options).length === 0)) { throw new Error('At least one update field (name, description, field_type, or options) is required'); } // Prepare request body with only the fields that are provided const body = {}; if (name !== undefined) { body.label = name; } if (field_type !== undefined) { body.fieldType = field_type; } if (description !== undefined) { body.description = 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, description: field.description, tableId: table_id, ...field }; } } exports.UpdateFieldTool = UpdateFieldTool; //# sourceMappingURL=update_field.js.map