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

    customizationService: CustomizationPluginService
    customizer: DataSourceCustomizer<S>
    nocodeCustomizer: DataSourceCustomizer<S>
    options: AgentOptionsWithDefaults
    prefix: string
    schemaGenerator: SchemaGenerator
    standaloneServerHost?: string
    standaloneServerPort: number

    Methods

    • Create a new API chart

      Parameters

      Returns this

      .addChart('numCustomers', (context, resultBuilder) => {
      return resultBuilder.distribution({
      tomatoes: 10,
      potatoes: 20,
      carrots: 30,
      });
      })
    • Run a workflow executor in-process, alongside the agent. The agent boots it on start(), stops it on stop(), and proxies /_internal/executor/* to it — no separate deployment.

      Requires the @forestadmin/workflow-executor package to be installed:

      npm install @forestadmin/workflow-executor
      

      The executor persists run state in a database: provide database, or set the DATABASE_URL environment variable. Mutually exclusive with the workflowExecutorUrl option, which targets a separately-deployed executor instead.

      Parameters

      Returns this

      the agent instance for chaining

      Error if called more than once, or if workflowExecutorUrl is also set

      createAgent(options)
      .addDataSource(...)
      .addWorkflowExecutor({ database: { uri: process.env.DATABASE_URL } })
      .start();
    • 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'))
      
    • Generate the schema (and typings, when typingsPath is set) and write them to disk without starting the agent or sending the schema to Forest Admin servers.

      Useful in a CI/CD pipeline to produce .forestadmin-schema.json at build time, so it can be shipped with the deployed code instead of committed.

      Note: when experimental no-code customizations are enabled, this still fetches their configuration from the Forest API so the generated schema includes them, which requires connectivity to Forest.

      Unlike start(), this always rebuilds the schema — even when isProduction is true — and writes the typings whenever typingsPath is set, regardless of isProduction.

      Like the rest of the agent, this does not own the data source connection lifecycle: a data source that opens a connection pool stays open after this resolves. In a one-shot script, close your data source (or call process.exit()) once it returns so the process can exit.

      Returns Promise<void>

    • Dispatcher that runs agent-client requests against the agent's own /forest stack in-memory. The handler is rebuilt on every (re)mount so a captured reference never goes stale.

      Returns InProcessDispatcher

    • Parameters

      • dataSource: DataSource
      • services: ForestAdminHttpDriverServices

      Returns BaseRoute[]

    • Parameters

      • router: Router

      Returns Promise<void>

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

      Tool calls reach your data in-process (no socket), so they skip any host-app middleware you mounted in front of the agent (rate limiting, request logging, WAF). The agent's own JWT auth and permission checks still run on them, and the inbound MCP request itself is unaffected.

      Parameters

      Returns this

      agent.mountAiMcpServer();
      // Example: read-only mode (only browse data, no create/update/delete/actions)
      agent.mountAiMcpServer({ enabledTools: ['describeCollection', 'list', 'listRelated'] });
      // Example: scope MCP routes under a prefix to avoid colliding with your app's own OAuth routes.
      // OAuth discovery metadata stays at the origin root (prefix-suffixed), so root `.well-known`
      // traffic must still reach the agent.
      agent.mountAiMcpServer({ basePath: '/ai' });
      // Example: shorten the OAuth token lifetimes. `accessTokenSeconds` cannot exceed the 1h Forest
      // grants; `refreshTokenSeconds` bounds the time between two interactive logins, which is
      // otherwise unbounded since Forest re-grants its refresh lifetime on every refresh.
      agent.mountAiMcpServer({ tokenTtl: { accessTokenSeconds: 900, refreshTokenSeconds: 86400 } });
    • 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>

    • Send the apimap to forest admin server

      Parameters

      Returns Promise<void>

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

      Parameters

      • callback: HttpCallback
      • OptionalrouteMatcher: McpRouteMatcher

      Returns void

    • Start the agent.

      Returns Promise<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' });