mcp-quickbase
Version:
Work with Quickbase via Model Context Protocol
102 lines • 3.29 kB
JavaScript
;
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';
/**
* Parameter schema for create_field
*/
this.paramSchema = {
type: 'object',
properties: {
table_id: {
type: 'string',
description: 'The ID of the table'
},
field_name: {
type: 'string',
description: 'Name of the field'
},
field_type: {
type: 'string',
description: 'Type of the field (e.g., text, number, date)'
},
description: {
type: 'string',
description: 'Description of the field'
},
options: {
type: 'object',
description: 'Additional field options'
}
},
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
const body = {
label: field_name,
fieldType: field_type,
description: description || ''
};
// Add properties if provided
if (options) {
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,
description: field.description,
tableId: table_id,
...field
};
}
}
exports.CreateFieldTool = CreateFieldTool;
//# sourceMappingURL=create_field.js.map