Airtable MCP Server (Engineer Track)
Goal
Build an MCP server that connects to Airtable, understanding each component as you go.
Step 1: Project setup
Copy the starter template and install dependencies:
1cp -r starter-template airtable-mcp
2cd airtable-mcp
3npm install
Open airtable-mcp/src/index.ts. You'll see the MCP SDK boilerplate:
1import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
3import { z } from 'zod';
4
5const server = new McpServer({
6 name: 'my-mcp-server',
7 version: '1.0.0'
8});
9
10const transport = new StdioServerTransport();
11await server.connect(transport);
This is the shell. You'll add tools between the server creation and transport connection.
Step 2: Understand the Airtable API
Before writing code, understand what you're calling.
Base URL pattern:
https://api.airtable.com/v0/{baseId}/{tableIdOrName}
Authentication: Bearer token in the Authorization header.
Example request:
1curl "https://api.airtable.com/v0/appXXX/Tasks" \
2 -H "Authorization: Bearer pat_xxx"
Response shape:
1{
2 "records": [
3 {
4 "id": "recABC123",
5 "createdTime": "2024-01-15T10:00:00.000Z",
6 "fields": {
7 "Name": "My Task",
8 "Status": "In Progress"
9 }
10 }
11 ]
12}
Key points:
id is always rec + 14 characters
fields is dynamic, it contains whatever columns your table has
- The API uses query params for filtering/pagination
Step 3: Add environment config
Add this at the top of your file, after the imports:
1const AIRTABLE_PAT = process.env.AIRTABLE_PAT;
2const AIRTABLE_BASE_ID = process.env.AIRTABLE_BASE_ID;
3const AIRTABLE_TABLE_NAME = process.env.AIRTABLE_TABLE_NAME || 'Tasks';
4
5if (!AIRTABLE_PAT || !AIRTABLE_BASE_ID) {
6 console.error('Missing required environment variables: AIRTABLE_PAT and AIRTABLE_BASE_ID');
7 process.exit(1);
8}
This pattern is called "fail fast". If credentials are missing, the server exits immediately with a clear error instead of failing later with a cryptic message.
Now add the base URL and headers you'll reuse across all tools:
1const baseUrl = `https://api.airtable.com/v0/${AIRTABLE_BASE_ID}/${encodeURIComponent(
2 AIRTABLE_TABLE_NAME,
3)}`;
4
5const headers = {
6 Authorization: `Bearer ${AIRTABLE_PAT}`,
7 'Content-Type': 'application/json',
8};
Note: encodeURIComponent handles table names with spaces or special characters.
Step 4: Build the list-records tool
API docs: https://airtable.com/developers/web/api/list-records
This tool lists all records from your table. Add it after your headers config:
1server.registerTool(
2 'list-records',
3 {
4 title: 'List Records',
5 description: 'List all records from the Airtable table',
6 inputSchema: {
7 maxRecords: z.number().optional().describe('Maximum records to return'),
8 },
9 outputSchema: {
10 records: z.array(z.object({ id: z.string(), fields: z.record(z.any()) })),
11 count: z.number(),
12 },
13 },
14 async ({ maxRecords = 100 }) => {
15 const response = await fetch(`${baseUrl}?maxRecords=${maxRecords}`, { headers });
16 if (!response.ok) {
17 return {
18 content: [{ type: 'text', text: `Error: ${await response.text()}` }],
19 isError: true,
20 };
21 }
22 const data = await response.json();
23 const output = {
24 records: data.records.map((r: any) => ({ id: r.id, fields: r.fields })),
25 count: data.records.length,
26 };
27 return {
28 content: [{ type: 'text', text: JSON.stringify(output, null, 2) }],
29 structuredContent: output,
30 };
31 },
32);
Schema notes:
z.record(z.any()) handles dynamic fields since every Airtable table has different columns
outputSchema defines what structured data the tool returns
- Both
content (text for display) and structuredContent (typed data) are returned
Step 5: Build the get-record tool
API docs: https://airtable.com/developers/web/api/get-record
Fetches a single record by ID:
1server.registerTool(
2 'get-record',
3 {
4 title: 'Get Record',
5 description: 'Get a single record by ID',
6 inputSchema: { recordId: z.string().describe('The record ID (starts with "rec")') },
7 outputSchema: { id: z.string(), fields: z.record(z.any()) },
8 },
9 async ({ recordId }) => {
10 const response = await fetch(`${baseUrl}/${recordId}`, { headers });
11 if (!response.ok) {
12 return {
13 content: [{ type: 'text', text: `Error: ${await response.text()}` }],
14 isError: true,
15 };
16 }
17 const data = await response.json();
18 const output = { id: data.id, fields: data.fields };
19 return {
20 content: [{ type: 'text', text: JSON.stringify(output, null, 2) }],
21 structuredContent: output,
22 };
23 },
24);
The pattern is similar: fetch, check response, transform, return both content types.
Step 6: Build the create-record tool
API docs: https://airtable.com/developers/web/api/create-records
This is a write operation using POST:
1server.registerTool(
2 'create-record',
3 {
4 title: 'Create Record',
5 description: 'Create a new record',
6 inputSchema: { fields: z.record(z.any()).describe('Object with field names and values') },
7 outputSchema: { id: z.string(), fields: z.record(z.any()) },
8 },
9 async ({ fields }) => {
10 const response = await fetch(baseUrl, {
11 method: 'POST',
12 headers,
13 body: JSON.stringify({ fields }),
14 });
15 if (!response.ok) {
16 return {
17 content: [{ type: 'text', text: `Error: ${await response.text()}` }],
18 isError: true,
19 };
20 }
21 const data = await response.json();
22 const output = { id: data.id, fields: data.fields };
23 return {
24 content: [{ type: 'text', text: `Created: ${JSON.stringify(output, null, 2)}` }],
25 structuredContent: output,
26 };
27 },
28);
The input is z.record(z.any()) because field names depend on your table structure.
Step 7: Configure Cursor
Update your MCP config. Find the absolute path to your project:
Add to ~/.cursor/mcp.json:
1{
2 "mcpServers": {
3 "airtable": {
4 "command": "npx",
5 "args": [
6 "-y", "ts-node", "--esm", "/absolute/path/to/airtable-mcp/src/index.ts"
7 ],
8 "env": {
9 "AIRTABLE_PAT": "pat_your_token_here",
10 "AIRTABLE_BASE_ID": "appYourBaseId",
11 "AIRTABLE_TABLE_NAME": "tblYourTableId"
12 }
13 }
14 }
15}
Reload Cursor (Cmd+Shift+P, type "Reload Window").
Step 8: Test your tools
Try these in Cursor chat:
- "List all records from my Airtable"
- "Get the record with ID recXXXXXX" (use a real ID from the list)
- "Create a new record with Name set to 'Test from MCP'"
Extension challenges
Try adding these tools yourself:
Hints:
- Update uses PATCH method
- Delete uses DELETE method
- Both need a record ID in the URL path
Reference
Complete implementation: examples/airtable/src/index.ts