Skip to main content
Glama
felores

Airtable MCP Server

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
NameRequiredDescriptionDefault
base_idYesID of the base
table_nameYesName of the new table
descriptionNoDescription of the table
fieldsNoInitial fields for the table

Implementation Reference

  • 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),
        }],
      };
    }
  • 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"],
      },
    },
  • 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;
    }
  • 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>;
    }
  • 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;
      }
    };

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/felores/airtable-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server