UNPKG

mcp-quickbase

Version:

Work with Quickbase via Model Context Protocol

112 lines 4.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CreateFieldTool = void 0; const base_1 = require("../base"); const logger_1 = require("../../utils/logger"); const logger = (0, logger_1.createLogger)("CreateFieldTool"); /** * Tool for creating a new field in a Quickbase table */ class CreateFieldTool extends base_1.BaseTool { /** * Constructor * @param client Quickbase client */ constructor(client) { super(client); this.name = "create_field"; this.description = "Creates a new field in a Quickbase table. " + "Valid field_type values: text, text-multi-line, text-multiple-choice, rich-text, " + "numeric, currency, percent, rating, date, datetime, timestamp, timeofday, duration, " + "checkbox, user, multiuser, email, url, phone, address, file. " + "Use options to set field properties like maxLength, defaultValue, numLines, etc."; /** * Parameter schema for create_field */ this.paramSchema = { type: "object", properties: { table_id: { type: "string", description: "The ID of the table (e.g., 'bqx7xkw3r')", }, field_name: { type: "string", description: "Display label for the field", }, field_type: { type: "string", description: "Field type: text, text-multi-line, rich-text, numeric, currency, " + "percent, rating, date, datetime, checkbox, user, email, url, phone, address, file", }, description: { type: "string", description: "Help text shown to users when editing the field (stored as fieldHelp)", }, options: { type: "object", description: "Field properties: appearsByDefault, findEnabled, required, unique, " + "maxLength (text), numLines (multi-line), defaultValue, etc.", }, }, required: ["table_id", "field_name", "field_type"], }; } /** * Run the create_field tool * @param params Tool parameters * @returns Created field details */ async run(params) { const { table_id, field_name, field_type, description, options } = params; logger.info("Creating new field in Quickbase table", { tableId: table_id, fieldName: field_name, fieldType: field_type, }); // Prepare request body // Note: Quickbase API uses 'fieldHelp' at root level for help text (not 'description') const body = { label: field_name, fieldType: field_type, }; // Add fieldHelp if description provided (maps to root-level fieldHelp) if (description) { body.fieldHelp = description; } // Add properties if provided if (options && Object.keys(options).length > 0) { body.properties = { ...options }; } // Create the field const response = await this.client.request({ method: "POST", path: `/fields?tableId=${table_id}`, body, }); if (!response.success || !response.data) { logger.error("Failed to create field", { error: response.error, tableId: table_id, fieldName: field_name, }); throw new Error(response.error?.message || "Failed to create field"); } const field = response.data; logger.info("Successfully created field", { fieldId: field.id, tableId: table_id, fieldName: field.label, }); return { fieldId: field.id, label: field.label, fieldType: field.fieldType, fieldHelp: field.fieldHelp, tableId: table_id, ...field, }; } } exports.CreateFieldTool = CreateFieldTool; //# sourceMappingURL=create_field.js.map