Model Context Protocol (MCP) server for Forest Admin with OAuth authentication support.
This MCP server provides HTTP REST API access to Forest Admin operations, enabling AI assistants and other MCP clients to interact with your Forest Admin data through a standardized protocol.
| Tool | Description |
|---|---|
describeCollection |
Get the schema of a collection (fields, types, relations) |
list |
Retrieve records from a collection |
listRelated |
Retrieve related records |
create |
Create a new record |
update |
Update an existing record |
delete |
Delete records |
associate |
Associate records in a relation |
dissociate |
Dissociate records from a relation |
getActionForm |
Get the form fields for a custom action |
executeAction |
Execute a custom action |
The MCP server is included with the Forest Admin agent. Simply call mountAiMcpServer():
import { createAgent } from '@forestadmin/agent';
const agent = createAgent(options)
.addDataSource(myDataSource)
.mountAiMcpServer();
agent.mountOnExpress(app);
agent.start();
The MCP server will be automatically initialized and mounted on your application.
You can run the MCP server standalone using the CLI:
npx forest-mcp-server
Or from the package directory:
yarn start # Production
yarn start:dev # Development (loads .env file automatically)
| Variable | Required | Default | Description |
|---|---|---|---|
FOREST_ENV_SECRET |
Yes | - | Your Forest Admin environment secret |
FOREST_AUTH_SECRET |
Yes | - | Your Forest Admin authentication secret (must match your agent) |
MCP_SERVER_PORT |
No | 3931 |
Port for the HTTP server |
FOREST_MCP_ENABLED_TOOLS |
No | - | Comma-separated list of tools to enable (allowlist) |
FOREST_AGENT_URL |
No | your environment's back-end URL | URL the MCP server uses to reach the back-end's data layer. Set it when the server runs next to a self-hosted back-end at an internal address (e.g. http://localhost:3310), instead of the public URL registered in Forest |
FOREST_MCP_ACCESS_TOKEN_TTL_SECONDS |
No | 3600 (1 hour) |
Maximum lifetime of the OAuth access tokens the server issues (tokenTtl.accessTokenSeconds). Minimum 60 |
FOREST_MCP_REFRESH_TOKEN_TTL_SECONDS |
No | unbounded | Maximum time between two interactive logins (tokenTtl.refreshTokenSeconds). Unset, a client that keeps refreshing never signs in again. Minimum 60 |
Create a .env file in the package directory:
FOREST_ENV_SECRET="your-env-secret"
FOREST_AUTH_SECRET="your-auth-secret"
Then run:
yarn start:dev
Or set the variables inline:
FOREST_ENV_SECRET="your-env-secret" FOREST_AUTH_SECRET="your-auth-secret" npx forest-mcp-server
You can restrict which tools the MCP server exposes using enabledTools. Only the listed tools will be available. New tools added in future releases will NOT be automatically enabled — you must explicitly add them.
For example, to set up a read-only mode where the AI assistant can only browse data (no create, update, delete or action execution):
// With Forest Admin Agent — read-only example
agent.mountAiMcpServer({
enabledTools: ['describeCollection', 'list', 'listRelated'],
});
# Standalone
export FOREST_MCP_ENABLED_TOOLS="describeCollection,list,listRelated"
npx forest-mcp-server
When enabledTools is not set, all tools are enabled by default.
See Available Tools for the full list. describeCollection is always enabled as it is required for the MCP server to function properly.
Forest grants 1 hour (3600s) for an access token and 8 days (691200s) for a refresh token — but it re-grants those 8 days on every refresh, so without refreshTokenSeconds a client that keeps working is never asked to sign in again.
Both values are upper bounds: they can only shorten that, never extend it. For accessTokenSeconds a value above 3600 therefore has no effect. refreshTokenSeconds bounds the whole session, which Forest otherwise re-extends on every refresh, so any value shortens it however large it is.
// With Forest Agent
agent.mountAiMcpServer({
tokenTtl: { accessTokenSeconds: 900, refreshTokenSeconds: 86400 },
});
# Standalone
export FOREST_MCP_ACCESS_TOKEN_TTL_SECONDS=900
export FOREST_MCP_REFRESH_TOKEN_TTL_SECONDS=86400
npx forest-mcp-server
The two settings differ in what the user notices:
accessTokenSeconds shortens how long a leaked access token can drive this server: the MCP path closes, its scopes stop applying and its calls stop being audited. It does not shorten the Forest token carried inside that JWT — the JWT is signed, not encrypted, so treat a leak as a Forest token leak and revoke at the source. It is transparent to users — the assistant silently obtains a new one.refreshTokenSeconds bounds the time between two interactive logins: once it elapses, the assistant can no longer refresh and the user signs in through the browser again. It is measured from the login itself, so an active assistant cannot keep extending its session. Refresh tokens issued before you enabled the option carry no login timestamp, so their window is measured from their last refresh instead — one longer session each, then bounded.The minimum for either value is 60 seconds; anything lower is raised to it. An invalid value (zero, negative, fractional) fails at startup rather than silently leaving the tokens uncapped.
Once running, the MCP server exposes the following endpoints:
| Method | Path | Description |
|---|---|---|
| POST | /mcp |
Main MCP protocol endpoint (requires Bearer token) |
| POST | /oauth/authorize |
OAuth 2.0 authorization |
| POST | /oauth/token |
OAuth 2.0 token exchange |
| GET | /.well-known/oauth-protected-resource/mcp |
OAuth metadata discovery |
The /mcp endpoint expects MCP protocol messages (JSON-RPC 2.0) and requires a valid OAuth Bearer token with at least the mcp:read scope.
mcp:read, mcp:write, mcp:action, mcp:admin)yarn build
yarn build:watch
yarn lint
yarn test
yarn clean
These are only needed by Forest Admin developers (e.g. to point to a local or staging server):
| Variable | Default | Description |
|---|---|---|
FOREST_SERVER_URL |
https://api.forestadmin.com |
Forest Admin API URL |
FOREST_APP_URL |
https://app.forestadmin.com |
Forest Admin application URL |
The server consists of:
GPL-3.0
https://github.com/ForestAdmin/agent-nodejs
For issues and feature requests, please visit the GitHub repository.