Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

1.5 KB
Raw Blame
import { createAction, Property } from '@activepieces/pieces-framework';
import { airtableAuth } from '../auth';
import { airtableCommon } from '../common';
import { AirtableBase } from '../common/models';
import { findBaseActionOutputSchema } from '../output-schemas';

export const airtableFindBaseAction = createAction({
  auth: airtableAuth,
  name: 'airtable_find_base',
  classification: 'SEARCH',
  displayName: 'Find Base',
  description: 'Find a base by its name or a keyword.',
  audience: 'human',
  outputSchema: findBaseActionOutputSchema,
  aiMetadata: {
    description:
      'Lists all accessible bases and returns those whose name contains the given keyword (case-insensitive substring match). Use to resolve a base ID from a name before other operations. Read-only and idempotent.',
    idempotent: true,
  },
  props: {
    baseName: Property.ShortText({
      displayName: 'Base Name',
      description: 'Bases whose name contains this text are returned.',
      placeholder: 'e.g. CRM',
      required: true,
    }),
  },
  async run(context) {
    const { auth: personalToken, propsValue } = context;
    const { baseName } = propsValue;

    const allBases: AirtableBase[] = await airtableCommon.fetchAllBases({
      token: personalToken.secret_text,
    });

    const searchTerm = (baseName as string).toLowerCase();


    const foundBases = allBases.filter((base) =>
      base.name.toLowerCase().includes(searchTerm)
    );

    return foundBases;
  },
});