@forestadmin/mcp-server
[!IMPORTANT]
Internal building block of the Forest Gateway. For new deployments, use
@forestadmin/gateway. The
forest-mcp-server command keeps working, deprecated.
Model Context Protocol (MCP) server for Forest Admin with OAuth authentication support.
Overview
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.
Available Tools
| 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 |
requestActionFileUpload |
Get a destination to upload a file to, for an action File field (only with fileUploads) |
listWorkflows |
List the MCP-enabled workflows in the caller's rendering, optionally filtered by collection |
triggerWorkflow |
Start a workflow run on a record, and return its runId |
getWorkflowRun |
Read a run started through MCP: its state and step-by-step history |
triggerWorkflow starts a process with side effects, so it is annotated destructiveHint: true and
MCP clients are expected to ask the user before each call. Like every other tool it is enabled by
default, but it stays inert until someone turns the MCP trigger on for a given workflow in Forest
— the server refuses a trigger on any workflow that has not opted in.
Usage
With Forest Admin Agent
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.
Standalone Server
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)
Environment Variables
| 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_SERVER_URL |
No |
http://localhost:<port> |
Public URL this server is reachable at — an http(s) origin only, no path. Required for any deployed server: without it the OAuth metadata advertise localhost, and the in-memory upload store mints localhost upload URLs no remote client can reach |
FOREST_MCP_ENABLED_TOOLS |
No |
- |
Comma-separated list of tools to enable (allowlist) |
FOREST_MCP_ALLOWED_OAUTH_CLIENTS |
No |
- |
Comma-separated domains of the OAuth client applications allowed to connect (allowedOAuthClients). Unset, any registered client is accepted |
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 |
FOREST_MCP_FILE_UPLOADS |
No |
- |
false turns action file uploads off (they are on by default, in memory). Any other value than true/false fails at startup |
FOREST_MCP_UPLOAD_STORAGE_MODULE |
No |
- |
Path to a module providing the fileUploads options, for a real storage backend. FOREST_MCP_FILE_UPLOADS=false wins over it |
Example Configuration
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
Deployed behind a public URL, add it — clients are sent wherever this says:
FOREST_MCP_SERVER_URL="https://mcp.example.com" \
FOREST_ENV_SECRET="your-env-secret" FOREST_AUTH_SECRET="your-auth-secret" npx forest-mcp-server
Restrict Tools
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.
Restrict OAuth Clients
Any OAuth client can register against the MCP server through Dynamic Client Registration and, once one of your users signs in, obtain tokens. Use allowedOAuthClients to accept only approved client applications:
// With Forest Admin Agent
agent.mountAiMcpServer({
allowedOAuthClients: ['dust.tt'],
});
# Standalone
export FOREST_MCP_ALLOWED_OAUTH_CLIENTS="dust.tt"
npx forest-mcp-server
A client is allowed only when every redirect URI it registered is an http(s) URI on a listed domain or one of its subdomains (dust.tt matches eu.dust.tt); custom schemes are rejected because they deliver the callback to whatever local application registered them, regardless of hostname. Matching uses redirect URIs because they are the one piece of registration metadata an impostor cannot benefit from — the authorization code is only ever delivered there. Self-declared fields such as the client name are ignored.
List bare domains only — unicode domains are matched through their punycode form. An entry with a scheme, port, path, or spaces fails at startup, as does a configured value containing no domains at all: the allowlist never silently falls back to accepting or rejecting everyone on a malformed configuration.
Every other client is rejected with a standard invalid_client error telling the user to contact their administrator; the response does not reveal the allowed domains. Registration itself still succeeds — it happens on the Forest Admin server — the client just cannot use it against this server. Access tokens issued before you enabled the option stay valid until they expire (1 hour at most); refreshes are blocked immediately.
Native desktop clients (Claude Desktop, MCP Inspector, ...) register loopback (localhost) redirect URIs, which a domain allowlist never matches — they are rejected unless you explicitly list localhost, which would admit every local application and defeats the restriction. Omit the option in environments that need native clients (e.g. development).
Shorten Token Lifetimes
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.
Action File Uploads
Experimental. The MCP specification is still designing its own file transfer story
(SEP-2631). The
UploadStorage contract is expected to survive, but the requestActionFileUpload tool and the handle
format may change to follow the specification once it lands.
Actions with File fields cannot normally run over MCP. The agent expects file values as data
uris, which would transit the model's context window and exceed most MCP clients' payload limits.
The fileUploads option enables them through an upload side-channel that keeps the bytes out of
the conversation:
- The client calls the
requestActionFileUpload tool with { "filename", "mimeType", "sha256"? } and receives a pre-authorized upload URL plus a signed fileHandle string.
- The client uploads the raw bytes directly to the storage backend, so they never pass through the MCP server or the model.
- The client passes the handle (
"$uploadedFile:<...>") as the field value in executeAction. The server downloads the object and hands it to the agent. The model only ever exchanges the small handle.
requestActionFileUpload follows enabledTools like every other tool, so a server that leaves it out never advertises it and never serves the upload endpoint.
The upload URL is unauthenticated — the model holds no agent credential, and must not — so the URL
itself is the authorization, as with an S3 presigned PUT. It carries a random uuid, is refused
before a byte is read unless this server issued it, expires with uploadUrlTtlSeconds, and serves
nothing but the PUT. Against the in-memory store it also accepts a single upload: once the
bytes land, a leaked URL can no longer replace them. Writing is not consuming either — redemption
needs the signed handle, which is bound to the user who requested it.
A presigned backend URL is a different animal: it is typically replayable until it expires — S3
accepts as many PUTs as fit in expiresInSeconds — so there, a URL leaked to an access log can
overwrite the bytes after the legitimate upload and before the action runs. The sha256 pin is
the defense that covers every backend at once: S3 signs it into the URL, so a different payload is
rejected at upload time, and redemption re-verifies the digest regardless of what the backend
checked. The tool instructs the model to pin by default; treat an unpinned upload as accepting that
window.
Nothing to provision, and nothing to switch on