create_table
Add a new table to an Airtable base with custom fields and structure for organizing data.
Instructions
Create a new table in a base
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| base_id | Yes | ID of the base | |
| table_name | Yes | Name of the new table | |
| description | No | Description of the table | |
| fields | No | Initial fields for the table |
Implementation Reference
- src/index.ts:420-443 (handler)The main handler for the 'create_table' tool. It extracts arguments, validates fields using validateField, makes a POST request to Airtable's metadata API to create the table, and returns the response as text.case "create_table": { const { base_id, table_name, description, fields } = request.params.arguments as { base_id: string; table_name: string; description?: string; fields?: FieldOption[]; }; // Validate and prepare fields const validatedFields = fields?.map(field => this.validateField(field)); const response = await this.axiosInstance.post(`/meta/bases/${base_id}/tables`, { name: table_name, description, fields: validatedFields, }); return { content: [{ type: "text", text: JSON.stringify(response.data, null, 2), }], }; }
- src/index.ts:100-147 (schema)Input schema definition for the 'create_table' tool, including parameters for base_id, table_name, description, and fields array with their types.{ name: "create_table", description: "Create a new table in a base", inputSchema: { type: "object", properties: { base_id: { type: "string", description: "ID of the base", }, table_name: { type: "string", description: "Name of the new table", }, description: { type: "string", description: "Description of the table", }, fields: { type: "array", description: "Initial fields for the table", items: { type: "object", properties: { name: { type: "string", description: "Name of the field", }, type: { type: "string", description: "Type of the field (e.g., singleLineText, multilineText, number, etc.)", }, description: { type: "string", description: "Description of the field", }, options: { type: "object", description: "Field-specific options", }, }, required: ["name", "type"], }, }, }, required: ["base_id", "table_name"], }, },
- src/index.ts:53-71 (helper)Helper function used by the create_table handler to validate and normalize field definitions by removing unnecessary options or adding defaults.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)TypeScript interface defining the structure of a FieldOption, used in the input schema for fields in create_table.export interface FieldOption { name: string; type: FieldType; description?: string; options?: Record<string, any>; }
- src/types.ts:22-46 (helper)Helper functions to determine if a field type requires options and to provide default options, used by validateField in the create_table handler.export const fieldRequiresOptions = (type: FieldType): boolean => { switch (type) { case 'number': case 'singleSelect': case 'multiSelect': case 'date': case 'currency': return true; default: return false; } }; export const getDefaultOptions = (type: FieldType): Record<string, any> | undefined => { switch (type) { case 'number': return { precision: 0 }; case 'date': return { dateFormat: { name: 'local' } }; case 'currency': return { precision: 2, symbol: '$' }; default: return undefined; } };