Skip to main content
Glama
cipher416

Airtable MCP Server

by cipher416
createTableRecord.ts1.48 kB
import { InferSchema, type ToolMetadata } from "xmcp"; import { z } from "zod"; export const schema = { baseId: z.string(), tableId: z.string(), // Arbitrary field map for the Airtable record fields: z.record(z.string(), z.any()), // When true, Airtable will attempt to coerce values to the right type typecast: z.boolean().optional(), }; export const metadata: ToolMetadata = { name: "createTableRecord", description: "Create a record in a specified table within a base", annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, }, }; export default async function createTableRecord( args: InferSchema<typeof schema>, ) { const url = `${process.env.AIRTABLE_API_URL}/v0/${args.baseId}/${args.tableId}`; const payload = { records: [ { fields: args.fields, }, ], typecast: args.typecast ?? false, }; const result = await fetch(url, { method: "POST", headers: { Authorization: `Bearer ${process.env.AIRTABLE_API_KEY}`, "Content-Type": "application/json", }, body: JSON.stringify(payload), }); if (!result.ok) { let detail = ""; try { const err = await result.json(); detail = ` - ${JSON.stringify(err)}`; } catch { // ignore JSON parse errors } throw new Error( `Failed to create record: ${result.status}${detail}`, ); } const created = await result.json(); return JSON.stringify(created); }

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/cipher416/airtable-mcp'

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