Forest Admin - API reference
    Preparing search index...

    Allow to create a new Forest Admin agent from scratch. Builds the application by composing and configuring all the collection decorators.

    Minimal code to add a datasource

    new AgentBuilder(options)
    .addDataSource(new SomeDataSource())
    .start();

    Type Parameters

    Hierarchy

    • default
      • Agent
    Index

    Constructors

    • Create a new Agent Builder. If any options are missing, the default will be applied:

       forestServerUrl: 'https://api.forestadmin.com',
      logger: (level, data) => console.error(level, data),
      prefix: 'api/v1',
      schemaPath: '.forestadmin-schema.json',
      permissionsCacheDurationInSeconds: 15 * 60,

      Type Parameters

      Parameters

      Returns Agent<S>

      new AgentBuilder(options)
      .addDataSource(new DataSource())
      .start();

    Properties

    aiConfigurations: OpenAiConfiguration[] = []
    customizationService: CustomizationPluginService
    customizer: DataSourceCustomizer<S>
    nocodeCustomizer: DataSourceCustomizer<S>
    options: AgentOptionsWithDefaults
    prefix: string
    schemaGenerator: SchemaGenerator
    standaloneServerPort: number

    Methods

    • Enable AI features for your Forest Admin panel.

      All AI requests from Forest Admin are forwarded to your agent and processed locally. Your data and API keys never transit through Forest Admin servers, ensuring full privacy.

      Parameters

      • configuration: OpenAiConfiguration

        The AI provider configuration

        • name

          A unique name to identify this AI configuration

        • provider

          The AI provider to use ('openai')

        • apiKey

          Your API key for the chosen provider

        • model

          The model to use (e.g., 'gpt-4o')

      Returns this

      The agent instance for chaining

      Error if addAi is called more than once

      agent.addAi({
      name: 'assistant',
      provider: 'openai',
      apiKey: process.env.OPENAI_API_KEY,
      model: 'gpt-4o',
      });
    • Allow to interact with a decorated collection

      Type Parameters

      • N extends string

      Parameters

      • name: N

        the name of the collection to manipulate

      • handle: (collection: CollectionCustomizer<S, N>) => unknown

        a function that provide a collection builder on the given collection name

      Returns this

      .customizeCollection('books', books => books.renameField('xx', 'yy'))
      
    • Parameters

      • dataSource: DataSource
      • services: ForestAdminHttpDriverServices

      Returns BaseRoute[]

    • Enable MCP (Model Context Protocol) server support. This allows AI assistants to interact with your Forest Admin data.

      Returns this

      agent.mountAiMcpServer();
      
    • Mount the agent on an express app.

      Parameters

      • express: any

        instance of the express app or router.

      Returns this

    • Mount the agent on a fastify app

      Parameters

      • fastify: any

        instance of the fastify app, or of a fastify context

      Returns this

    • Mount the agent on a koa app

      Parameters

      • koa: any

        instance of a koa app or a koa Router.

      Returns this

    • Mount the agent on a NestJS app

      Parameters

      • nestJs: any

        instance of a NestJS application

      Returns this

    • Expose the agent on a given port and host

      Parameters

      • Optionalport: number

        port that should be used, defaults to 3351 or to the PORT environment variable. O will be set a random available port and the port will be available in the standaloneServerPort property.

      • Optionalhost: string

        host that should be used, default to the unspecified IPv6 address (::) when IPv6 is available, or the unspecified IPv4 address (0.0.0.0) otherwise.

      Returns this

    • Parameters

      • router: Router

      Returns Promise<void>

    • Remove collections from the exported schema (they will still be usable within the agent).

      Parameters

      • ...names: Extract<keyof S, string>[]

        the collections to remove

      Returns this

      .removeField('aCollectionToRemove', 'anotherCollectionToRemove');
      
    • Restart the agent at runtime (remount routes).

      Returns Promise<void>

    • Set the MCP HTTP callback. Call this before mount() or remount().

      Parameters

      • callback: HttpCallback

      Returns void

    • Stop the agent.

      Returns Promise<void>

    • Update the typings files generated from your datasources

      Parameters

      • typingsPath: string

        the path at which to write the new file

      • typingsMaxDepth: number

        the max depth of relation typings

      Returns Promise<void>

    • Load a plugin across all collections

      Type Parameters

      • Options

      Parameters

      • plugin: Plugin<Options>

        instance of the plugin

      • Optionaloptions: Options

        options which need to be passed to the plugin

      Returns this

      import advancedExportPlugin from '@forestadmin/plugin-advanced-export';

      agent.use(advancedExportPlugin, { format: 'xlsx' });