Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions deco-admin-airtable-sync/app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"scopeName": "deco",
"name": "deco-admin-airtable-sync",
"friendlyName": "Deco Admin — Airtable Sync",
"connection": {
"type": "HTTP",
"url": "https://sites-deco-admin-airtable-sync.decocache.com/mcp"
},
"description": "Triggers the deco.cx admin Airtable sync action for a given table.",
"icon": "https://decoims.com/admin/81eca612-7d01-4a91-80f9-5081e277ba61/invoice.png",
"unlisted": true,
"auth": {
"type": "token",
"header": "Authorization",
"prefix": "Bearer"
},
"metadata": {
"categories": ["Developer Tools"],
"official": false,
"tags": ["airtable", "deco", "sync", "admin"],
"short_description": "Triggers the deco.cx admin Airtable sync action.",
"mesh_description": "This MCP provides a single tool to trigger the deco.cx admin Airtable sync action for a specific table. It allows AI agents to kick off data synchronization jobs between Airtable and the deco.cx platform, with support for dry-run mode and workflow orchestration."
}
}
23 changes: 23 additions & 0 deletions deco-admin-airtable-sync/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "@decocms/deco-admin-airtable-sync",
"version": "1.0.0",
"description": "MCP to trigger deco.cx admin Airtable sync actions",
"private": true,
"type": "module",
"scripts": {
"dev": "bun run --hot server/main.ts",
"build:server": "NODE_ENV=production bun build server/main.ts --target=bun --outfile=dist/server/main.js",
"build": "bun run build:server",
"publish": "cat app.json | deco registry publish -w /shared/deco -y",
"check": "tsc --noEmit"
},
"dependencies": {
"@decocms/runtime": "1.2.8",
"zod": "^4.0.0"
},
"devDependencies": {
"@decocms/mcps-shared": "1.0.0",
"deco-cli": "^0.28.0",
"typescript": "^5.7.2"
}
}
6 changes: 6 additions & 0 deletions deco-admin-airtable-sync/server/lib/env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { Env } from "../../shared/deco.gen.ts";

export function getApiKey(env: Env): string {
const auth = env.MESH_REQUEST_CONTEXT?.authorization ?? "";
return auth.startsWith("Bearer ") ? auth.slice(7) : auth;
}
14 changes: 14 additions & 0 deletions deco-admin-airtable-sync/server/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { withRuntime } from "@decocms/runtime";
import { serve } from "@decocms/mcps-shared/serve";
import { tools } from "./tools/index.ts";
import type { Env } from "../shared/deco.gen.ts";

export type { Env };

const runtime = withRuntime<Env>({
tools: (env: Env) => tools.map((createTool) => createTool(env)),
});

if (runtime.fetch) {
serve(runtime.fetch);
}
3 changes: 3 additions & 0 deletions deco-admin-airtable-sync/server/tools/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { createSyncAirtableTable } from "./sync-airtable-table.ts";

export const tools = [createSyncAirtableTable];
62 changes: 62 additions & 0 deletions deco-admin-airtable-sync/server/tools/sync-airtable-table.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { createPrivateTool } from "@decocms/runtime/tools";
import { z } from "zod";
import type { Env } from "../../shared/deco.gen.ts";
import { getApiKey } from "../lib/env.ts";

const SYNC_URL =
"https://admin.deco.cx/live/invoke/deco-sites/admin/actions/airtable/sync.ts";

export const createSyncAirtableTable = (env: Env) =>
createPrivateTool({
id: "syncAirtableTable",
description:
"Triggers the deco.cx admin Airtable sync action for a given table. " +
"Use mode 'dry-run' to preview changes without applying them.",
inputSchema: z.object({
table: z
.string()
.describe('Name of the Airtable table to sync, e.g. "invoices"'),
shouldStartWorkflow: z
.boolean()
.default(false)
.describe("Whether to start a workflow after the sync completes"),
mode: z
.enum(["apply", "dry-run"])
.default("apply")
.describe(
'"apply" executes the sync for real; "dry-run" simulates without making changes',
),
}),
outputSchema: z.object({
ok: z.boolean(),
status: z.number(),
body: z.unknown(),
}),
execute: async ({ context }) => {
const apiKey = getApiKey(env);
const { table, shouldStartWorkflow, mode } = context;

const res = await fetch(SYNC_URL, {
method: "POST",
headers: {
"Content-Type": "application/json",
"x-api-key": apiKey,
},
body: JSON.stringify({ table, shouldStartWorkflow, mode }),
});

const text = await res.text();
let body: unknown = text;
try {
body = JSON.parse(text);
} catch {
// keep as plain text
}

if (!res.ok) {
throw new Error(`Sync failed (${res.status}): ${text}`);
}

return { ok: true, status: res.status, body };
},
});
7 changes: 7 additions & 0 deletions deco-admin-airtable-sync/shared/deco.gen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export interface MeshRequestContext {
authorization?: string;
}

export interface Env {
MESH_REQUEST_CONTEXT: MeshRequestContext;
}
34 changes: 34 additions & 0 deletions deco-admin-airtable-sync/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"compilerOptions": {
"target": "ES2022",
"useDefineForClassFields": true,
"lib": ["ES2023", "ES2024", "DOM", "DOM.Iterable"],
"module": "ESNext",
"skipLibCheck": true,

/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"isolatedModules": true,
"verbatimModuleSyntax": false,
"moduleDetection": "force",
"noEmit": true,
"allowJs": true,

/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedSideEffectImports": true,

/* Path Aliases */
"baseUrl": ".",
"paths": {
"server/*": ["./server/*"]
}
},
"include": [
"server"
]
}
9 changes: 9 additions & 0 deletions deploy.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
{
"deco-admin-airtable-sync": {
"site": "deco-admin-airtable-sync",
"entrypoint": "./dist/server/main.js",
"platformName": "kubernetes-bun",
"watch": [
"deco-admin-airtable-sync/**",
"shared/**"
]
},
"airtable": {
"site": "airtable",
"entrypoint": "./dist/server/main.js",
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"crazy-egg",
"data-for-seo",
"datajud",
"deco-admin-airtable-sync",
"deco-llm",
"deco-news-weekly-digest",
"discord",
Expand Down
Loading