Skip to main content
Glama
apitable

AITable MCP Server

Official

create_record

Generate a new record in a datasheet by extracting key information from user input. Convert provided text into a JSON object based on a predefined schema for structured data storage.

Instructions

Create a new record in the datasheet. Extract key information from user-provided text based on a predefined Fields JSON Schema and create a new record in the datasheet as a JSON object.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
attachments_fieldsNoA JSON object containing Attachment type field data. Keys represent field names and values are arrays of attachment objects. The structure of attachment objects must conform to the Fields JSON Schema provided by the "get_fields_schema" tool. You need to use the "upload_file_via_url" tool to obtain the attachment objects.
fieldsYesA JSON object containing non-Attachment type field data. Keys represent field names and values represent field values. Omit unspecified fields in the API request. The structure of field values must conform to the Fields JSON Schema provided by the "get_fields_schema" tool.
node_idYesThe ID of the datasheet where the new record will be created.

Implementation Reference

  • MCP tool handler for 'create_record': validates inputs, fetches datasheet fields schema, converts fields to cell format, handles attachments, creates record via service, returns formatted response or error.
    async ({ node_id, fields, attachments_fields }) => {
      try {
        if (!node_id) {
          throw new Error("The datasheet ID (node_id) is required.");
        }
    
        if (!fields && !attachments_fields) {
          throw new Error("At least one of 'fields' or 'attachments_fields' must be provided.");
        }
    
    
        const getFieldsResult = await aitableService.getDatasheetFieldsSchema(node_id);
    
        if (!getFieldsResult.success) {
          throw new Error(getFieldsResult.message || "Failed to fetch datasheet fields schema");
        }
    
        const fieldsSchema = getFieldsResult.data.fields;
        let cells: Record<string, any> = {};
        if (fields !== undefined) {
          cells = aitableService.convertFieldValuesToCellFormat(fieldsSchema, fields);
        }
    
        if (attachments_fields) {
          console.error("attachments_fields", attachments_fields);
          console.error("fieldsSchema", fieldsSchema);
          fieldsSchema.forEach((fieldschema) => {
            const fieldValue = attachments_fields[fieldschema.name];
            if (fieldValue !== undefined) {
              cells[fieldschema.name] = fieldValue;
            }
          });
        }
    
        const createRecordResult = await aitableService.createDatasheetRecord(node_id, cells);
    
        if (!createRecordResult.success) {
          throw new Error(createRecordResult.message || "Failed to create record");
        }
    
        return formatToolResponse({
          success: true,
          data: {
            records: createRecordResult.data.records,
          },
        });
      }
      catch (error) {
        console.error("Error in create_record:", error);
        return formatToolResponse({
          success: false,
          message: error instanceof Error ? error.message : "Unknown error occurred"
        }, true);
      }
    }
  • Zod input schema for create_record tool parameters: node_id (string), fields (record of any), attachments_fields (optional record of attachment arrays).
    {
      node_id: z.string().describe('The ID of the datasheet where the new record will be created.'),
      fields: z.record(z.any()).describe('A JSON object containing non-Attachment type field data. Keys represent field names and values represent field values. Omit unspecified fields in the API request. The structure of field values must conform to the Fields JSON Schema provided by the "get_fields_schema" tool.'),
      attachments_fields: z.record(z.array(z.object({
        token: z.string(),
        name: z.string(),
        size: z.number(),
        mimeType: z.string(),
        height: z.number().optional(),
        width: z.number().optional(),
        url: z.string(),
      }))).optional().describe('A JSON object containing Attachment type field data. Keys represent field names and values are arrays of attachment objects. The structure of attachment objects must conform to the Fields JSON Schema provided by the "get_fields_schema" tool. You need to use the "upload_file_via_url" tool to obtain the attachment objects.'),
    },
  • src/index.ts:215-285 (registration)
    Registration of the create_record tool on the MCP server, specifying name, description, input schema, and handler function.
    server.tool("create_record",
      "Create a new record in the datasheet. Extract key information from user-provided text based on a predefined Fields JSON Schema and create a new record in the datasheet as a JSON object.",
      {
        node_id: z.string().describe('The ID of the datasheet where the new record will be created.'),
        fields: z.record(z.any()).describe('A JSON object containing non-Attachment type field data. Keys represent field names and values represent field values. Omit unspecified fields in the API request. The structure of field values must conform to the Fields JSON Schema provided by the "get_fields_schema" tool.'),
        attachments_fields: z.record(z.array(z.object({
          token: z.string(),
          name: z.string(),
          size: z.number(),
          mimeType: z.string(),
          height: z.number().optional(),
          width: z.number().optional(),
          url: z.string(),
        }))).optional().describe('A JSON object containing Attachment type field data. Keys represent field names and values are arrays of attachment objects. The structure of attachment objects must conform to the Fields JSON Schema provided by the "get_fields_schema" tool. You need to use the "upload_file_via_url" tool to obtain the attachment objects.'),
      },
      async ({ node_id, fields, attachments_fields }) => {
        try {
          if (!node_id) {
            throw new Error("The datasheet ID (node_id) is required.");
          }
    
          if (!fields && !attachments_fields) {
            throw new Error("At least one of 'fields' or 'attachments_fields' must be provided.");
          }
    
    
          const getFieldsResult = await aitableService.getDatasheetFieldsSchema(node_id);
    
          if (!getFieldsResult.success) {
            throw new Error(getFieldsResult.message || "Failed to fetch datasheet fields schema");
          }
    
          const fieldsSchema = getFieldsResult.data.fields;
          let cells: Record<string, any> = {};
          if (fields !== undefined) {
            cells = aitableService.convertFieldValuesToCellFormat(fieldsSchema, fields);
          }
    
          if (attachments_fields) {
            console.error("attachments_fields", attachments_fields);
            console.error("fieldsSchema", fieldsSchema);
            fieldsSchema.forEach((fieldschema) => {
              const fieldValue = attachments_fields[fieldschema.name];
              if (fieldValue !== undefined) {
                cells[fieldschema.name] = fieldValue;
              }
            });
          }
    
          const createRecordResult = await aitableService.createDatasheetRecord(node_id, cells);
    
          if (!createRecordResult.success) {
            throw new Error(createRecordResult.message || "Failed to create record");
          }
    
          return formatToolResponse({
            success: true,
            data: {
              records: createRecordResult.data.records,
            },
          });
        }
        catch (error) {
          console.error("Error in create_record:", error);
          return formatToolResponse({
            success: false,
            message: error instanceof Error ? error.message : "Unknown error occurred"
          }, true);
        }
      }
    );
  • AitableService helper method that sends POST request to AITable API to create a datasheet record using provided cells.
    public async createDatasheetRecord(
      node_id: string,
      cells: Record<string, unknown>
    ): Promise<ResponseVO<{records: RecordVO[]}>> {
    
      const endpoint = `/v1/datasheets/${node_id}/records`;
    
      console.error('Creating record with cells:', cells);
    
      return this.fetchFromAPI(endpoint, {
        method: "POST",
        body: JSON.stringify({
          records:[
            {
              fields: cells,
            }
          ]
        }),
      });
    }
  • Helper method to convert user field values to API-compatible cell format, applying type-specific conversions using field schema.
    public convertFieldValuesToCellFormat(
      fieldsSchema: FieldSchemaVO[],
      fieldValues: Record<string, unknown>
    ): Record<string, unknown> {
      const cells: Record<string, unknown> = {};
    
      fieldsSchema.forEach((fieldschema) => {
        const fieldValue = fieldValues[fieldschema.name];
        if (fieldValue !== undefined) {
          const cellValue = this._getCellValueByFieldType(
            fieldschema,
            fieldValue
          );
    
          // Only add the cell if the value is not null
          if (cellValue !== null) {
            cells[fieldschema.name] = cellValue;
          }
        }
      });
    
      return cells;
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden. It states this is a creation operation (implying mutation) but doesn't disclose behavioral traits like required permissions, whether the operation is idempotent, error conditions, rate limits, or what happens on success/failure. The mention of 'Extract key information from user-provided text' adds some context about input processing, but overall behavioral disclosure is minimal for a mutation tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately concise (two sentences) and front-loaded with the core purpose. Both sentences add value: the first states the action and resource, the second provides implementation context. No redundant information or unnecessary elaboration is present.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a mutation tool with 3 parameters (including complex nested objects), no annotations, and no output schema, the description is insufficient. It doesn't explain what happens after creation (e.g., returns record ID, success status), error handling, or important behavioral constraints. The schema handles parameter documentation well, but the description fails to compensate for the lack of annotations and output information.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so parameters are well-documented in the schema. The description adds minimal value beyond the schema: it mentions 'Extract key information from user-provided text' which loosely relates to the 'fields' parameter, and references 'get_fields_schema' for structure. However, it doesn't explain parameter interactions or provide additional semantic context beyond what's already in the schema descriptions.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Create a new record') and resource ('in the datasheet'), with additional context about extracting information from user text. It distinguishes from siblings like 'list_records' by specifying creation rather than retrieval. However, it doesn't explicitly differentiate from potential similar creation tools (though none are listed).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description mentions using 'get_fields_schema' for structure and 'upload_file_via_url' for attachments, providing some implementation guidance. However, it lacks explicit when-to-use criteria, prerequisites, or comparisons to alternatives like 'upload_attachment_via_url' for attachment handling. No guidance on when NOT to use this tool is provided.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

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/apitable/aitable-mcp-server'

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