create_field
Add a new field to an Airtable table by specifying the field name, type, and optional description or options to customize your database structure.
Instructions
Create a new field in a table
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| base_id | Yes | ID of the base | |
| table_id | Yes | ID of the table | |
| field | Yes |
Implementation Reference
- src/index.ts:466-487 (handler)Handler function for the 'create_field' tool. It validates the field input and sends a POST request to the Airtable metadata API to create a new field in the specified table.case "create_field": { const { base_id, table_id, field } = request.params.arguments as { base_id: string; table_id: string; field: FieldOption; }; // Validate field before creation const validatedField = this.validateField(field); const response = await this.axiosInstance.post( `/meta/bases/${base_id}/tables/${table_id}/fields`, validatedField ); return { content: [{ type: "text", text: JSON.stringify(response.data, null, 2), }], }; }
- src/index.ts:174-213 (registration)Tool registration in the list of available tools, including name, description, and detailed input schema definition.{ name: "create_field", description: "Create a new field in a table", inputSchema: { type: "object", properties: { base_id: { type: "string", description: "ID of the base", }, table_id: { type: "string", description: "ID of the table", }, field: { type: "object", properties: { name: { type: "string", description: "Name of the field", }, type: { type: "string", description: "Type of the field", }, description: { type: "string", description: "Description of the field", }, options: { type: "object", description: "Field-specific options", }, }, required: ["name", "type"], }, }, required: ["base_id", "table_id", "field"], }, },
- src/index.ts:53-71 (helper)Helper function to validate and normalize field options before creation, removing unnecessary options or adding defaults based on field type.private validateField(field: FieldOption): FieldOption { const { type } = field; // Remove options for fields that don't need them if (!fieldRequiresOptions(type as FieldType)) { const { options, ...rest } = field; return rest; } // Add default options for fields that require them if (!field.options) { return { ...field, options: getDefaultOptions(type as FieldType), }; } return field; }
- src/types.ts:15-20 (schema)Type definition for FieldOption used in create_field input.export interface FieldOption { name: string; type: FieldType; description?: string; options?: Record<string, any>; }
- src/types.ts:22-33 (helper)Helper function determining if a field type requires options, used in validation.export const fieldRequiresOptions = (type: FieldType): boolean => { switch (type) { case 'number': case 'singleSelect': case 'multiSelect': case 'date': case 'currency': return true; default: return false; } };