MCP Server installation & setup
Overview
Model Context Protocol (MCP) is an open protocol that standardizes how AI agents connect to services that expose tools, resources, and prompts — a universal interface that lets you plug any agent into any integration without bespoke code.
The Beefree SDK MCP Server exposes the editor, and Check API as callable tools. When the agent makes a change, it is pushed to the editor in real time — the user sees the template update live as the agent works, if the builder is open.
Choose your integration path
Beefree SDK's MCP Server support both headless and in-editor use-cases.
Headless
To integrate the MCP Server in a headless setup, you can follow the API-managed session path below skipping the third step to "Connect the editor".
In-Editor
There are two ways to connect your agent to the editor. The right choice depends on whether co-editing is available and enabled on your account:
Co-editing not enabled → Editor-managed session: the editor creates a lightweight temporary session on demand via
bee.startMcpSession(). No backend session management required.Co-editing enabled → API-managed session: your host application creates and manages the session lifecycle via the Headless API. Supports multiple concurrent users, presence indicators, per-change history, and persistent sessions.
Both paths use the same MCP endpoint and authentication. They differ only in how the session and templateId are created.
Core architecture
AI Agent → MCP Client → CSAPI → MCP Server → Beefree SDK Ecosystem (optional)
↓ ↓ ↓ ↓ ↓
Natural JSON-RPC Auth & Tool Calls Editor /
Language Protocol Routing Processing Check API
CSAPI — public API entry point for your agent. Authenticates requests and routes them to the MCP server.
MCP Server — implements the MCP protocol and exposes tools that operate on Beefree SDK resources.
Beefree SDK Ecosystem — the Editor, and Check API.
At a protocol level:
Base protocol & lifecycle. Clients and servers speak JSON-RPC 2.0, negotiate capabilities, and then exchange requests until shutdown. Initialization (initialize → initialized) must happen first.
Tools. Servers list tools via tools/list and invoke them via tools/call. Each tool has a name and JSON Schema for inputs (and optionally outputs).
Metadata (_meta). A reserved envelope for passing extra routing/context (not tool args), namespaced as the spec requires. We'll use it to pass Beefree session routing when not using HTTP headers.
Prerequisites
Get an MCP-compatible CSAPI key
All requests to the MCP endpoint require a valid CSAPI key. You can enable your CSAPI Key from your SDK Console.
Once you have a key, include it in every request:
MCP endpoint
All agent connections use the v2 endpoint:
Your agent must complete the MCP initialize/initialized handshake before calling any tools. MCP clients (SDKs, runtimes) typically handle this automatically.
Rate Limits
MCP template operations (/v2/sdk/mcp/template*, used to create and retrieve templates) have their own dedicated rate-limit budget: 500 requests / 60s on Standard plans, 1,000 requests / 60s on Enterprise. This is a separate budget from other Content Services API groups, not shared with them.
See the Content Services API Rate Limits section for the full breakdown of all endpoint groups.
Editor-managed session
The session is temporary and scoped to a single user and their agent(s). If you have the co-edit enabled, please refer to the API-managed session for the setup.
Step 1: Configure the editor
No additional editor configuration is required beyond your standard Beefree SDK setup. The relevant fields for MCP sessions are covered in Editor Configuration below.
Step 2: Start a session
When the user is ready to involve the agent, your host application calls:
The editor creates an MCP session server-side and returns a templateId. Pass this to your agent(s).
Step 3: Connect your agent
Connect to the v2 MCP endpoint using the templateId from Step 2, exactly as in the API-managed path:
The agent connects and can immediately begin editing the template.
Step 4: End the session
The session ends automatically when agent work is complete (see When the Session Ends Automatically)
Automatic stop means: history entry creation, connection teardown, and a SESSION_ENDED event.
Session participants
An editor-managed MCP session supports exactly one real user — the person using the editor — and any number of AI agents.
The real user stays connected throughout the entire session.
One or more agents join via the MCP server using the
templateId.A second real (non-agent) user cannot join. If one does, the session stops automatically.
The automated disconnect logic relies on this model: once at least one agent has joined and then all agents leave, only the real user remains. The editor treats this as "all agents have finished their work" and automatically ends the session.
When the session ends automatically
The session ends automatically when any of the following occur:
All agents leave (only the real user remains) — the editor treats this as agent work being complete.
The 10-minute client timeout expires — a hard limit regardless of agent activity.
A second real user (non-agent) joins the session.
A new template is loaded into the editor.
History behavior
During an editor-managed MCP session, individual agent modifications are not tracked as separate history entries. Instead, the editor captures the full template state before the session starts and, upon the session end, creates a single history entry representing the diff between the original and final states.
This means users can undo the entire batch of agent changes as one unit, but cannot step through individual agent edits.
Session lifecycle
An editor-managed session is ephemeral. Once it ends — by timeout, automated-stop, or manual stop — it cannot be resumed. To start another agent pass on the same template, call bee.startMcpSession() again. Each call creates a fresh session with its own templateId, timeout and history entry.
Brand Rules, Merge Tags and Reusable Rows
To make the MCP Server work with Brand Rules and Merge Tags in an editor-managed session, set brandRules and mergeTags at the root of your editor configuration. If present there, they're picked up automatically when bee.startMcpSession() creates the session.
Here is an example:
You can also pass brandRules and a reusableRows library directly to bee.startMcpSession(), for the session that call creates:
brandRules: when passed, these are used instead of the ones at the root of the editor configuration. When omitted, the root ones apply as before.reusableRows: has no root-level equivalent. Pass it here to attach a library to the session. See Reusable Rows for AI for the row shape, limits, and what the agent can do with it.Calling it with no arguments works as before.
File Manager
To let the agent work in your user's File Manager, pass the folders it can use as fileManager to bee.startMcpSession(). It has no equivalent at the root of the editor configuration.
Pass only the folders: the agent works in the File Manager of the uid the editor was started with. Without fileManager, the session has no file tools. See File Manager for AI for the defaults, the limits, and how to validate the folders.
Error handling
If bee.startMcpSession() fails, the promise is rejected with an object in this shape:
When the server refused the session creation request, detail holds the HTTP status of the response, the error, and, for an invalid payload, the details list. In other failures, detail is empty or absent.
Common failure scenarios:
Builder not ready — the editor has not finished initializing.
API error — the server-side session creation request failed. This includes an invalid
brandRulesorreusableRowspayload (400), a request over 3.5 MB, or over 2 MB without thereusableRows(413), andbrandRulesorreusableRowson a plan that does not include them (403).
API-managed session
Your host application controls the full session lifecycle: you create the template, connect the agent, and optionally connect the editor — all independently.
Step 1: Create a template
Call the template creation endpoint to initialize a new editing session server-side. You receive a templateId that you will pass to the agent in the next step.
Endpoint
Request body
template
object
Optional. The JSON template to initialize the session with.
mergeTags
object
Optional. Merge tags to be resolved within the template.
brandRules
object
Optional. Brand Rules the agent must follow during the session (presets, permissions, limits). See Brand Rules for the full schema and logic.
reusableRows
object
Optional. A library of the customer's saved rows the agent may search and place. See Reusable Rows for AI for the payload shape and limits.
fileManager
object
Optional. The end user whose File Manager the agent can work in (uid), and the folders it can read, upload to, and delete from. See File Manager for AI for fields, defaults, and limits.
To make the MCP Server work with Brand Rules in an API-managed session, pass a brandRules object in this request body alongside template and mergeTags.
We recommend validating your brandRules payload with the Brand Rules validation endpoint before creating the template. This surfaces schema errors up front instead of only when the session starts.
To let the agent work with your users' saved rows, pass a reusableRows object in the same request. A library over 1,000 rows (or about 1.5 MB of row data) is trimmed, while an invalid row makes the request fail with 400. A request over 3.5 MB, or over 2 MB without the reusableRows, fails with 413. The response then also reports what was stored in reusableRows, droppedEntries is included when the library was trimmed. Validate the library beforehand to catch invalid rows. See Reusable Rows for AI.
To let the agent work in your users' File Manager, pass a fileManager object in the same request body, with the uid of the end user and the folders the agent can read, upload to, and delete from. An invalid fileManager makes the request fail with 400, and no session is created. Validate it beforehand with the validation endpoint. See File Manager for AI.
Response
Returns a templateId. You must pass this as the x-bee-template-id header (or _meta field) when connecting to the MCP endpoint.
When the request carries reusableRows, the response also describes what was stored: how many rows and how many were sent and dropped if the library was trimmed. See Reusable Rows for AI for every field.
Step 2: Connect your agent
Point your MCP client at the v2 endpoint and provide the templateId you received in Step 1. You can pass it in one of two ways:
Option A — HTTP header (recommended)
Option B — _meta field in the MCP initialize request
Use _meta strictly for routing metadata, not for tool arguments.
Step 3: Connect the editor (optional)
The editor can join the same session for real-time collaboration alongside the agent. To configure this, use the join method in the editor configuration.
Step 4: Retrieve the final template
After the agent has finished its work, fetch the modified template from the server:
This returns the current state of the template with all agent modifications applied.
Agent locking behavior
When an agent shares a session with human users, module locks — the mechanism that prevents two users from editing the same module simultaneously — interact with the agent differently depending on whether it has an assigned owner.
The agent's owner is determined by the x-bee-user-handle header passed when the agent connects to the MCP server. If that value matches an existing userHandle value in the session, that user becomes the agent's owner.
Agent without an owner (x-bee-user-handle is absent or does not match any session user):
The agent ignores all locks and can override any module regardless of who is currently editing it.
Agent with an owner (x-bee-user-handle matches a session user's userHandle):
The agent can replace locks held by its owner — it acts on behalf of that user.
The agent honors locks held by other users and will not override modules they are editing.
Assigning an owner is recommended in sessions with multiple real users. It ensures the agent respects the collaborative editing boundaries of other participants.
Editor configuration
For the full editorConfig reference and co-editing setup, see the Co-Editing Integration Guide.
The following fields are relevant to MCP sessions across both integration paths:
userHandle behavior
If
userHandleis provided, it is used as the user's identity in the co-editing session.If
userHandleis omitted in an editor-managed session, the editor auto-generates one asmcp-{randomUUID}, ensuring a unique identity without requiring the host to manage it.In an API-managed session,
userHandleis also used to match an agent's owner via thex-bee-user-handle header(see Agent locking behavior).
Host callbacks: onMcpSessionChange
The editor-managed session exposes a set of callbacks that serve as the co-editing equivalents of onSessionChange and onSessionStarted.
SESSION_STARTED
{ type, templateId }
Connection successfully established
USER_JOINED
{ type, change, sessionData }
A new user enters the session
USER_LEFT
{ type, change, sessionData }
A user leaves the session
SESSION_ENDED
{ type, templateId }
The session stops
Server-Side session TTL
These values define how long session data persists on the backend, independently of any client-side timeouts.
API-managed session
Last user leaves
Set to 24h
24h after last user disconnects
Idle (no writes or keep-alives)
Last set value (up to 33h)
At TTL expiry
Editor-managed session
Last user leaves
Set to 5 min
5 min after last user disconnects
Idle (no writes or keep-alives)
Last set value (up to 1h)
At TTL expiry
Security
Key protection: Never expose your CSAPI keys in client-side code or public repositories.
Secure transport: Always use the provided HTTPS gateway for all MCP interactions.
Validation: Ensure your MCP client correctly handles the
_metafield and authentication headers.
We strongly recommend reviewing the official MCP Client documentation for guidance on transport, lifecycle, and security.
Code examples
In the Beefree SDK MCP v2 demo repository, you can find:
An example of an editor-managed session
An example of an API-managed session
A Code Mode example
Code mode
Code Mode is an alternative way to interact with the Beefree SDK MCP Server that significantly reduces token consumption.
Instead of exposing 33 individual tools — each with a full parameter schema sent on every turn — Code Mode exposes a single tool that accepts a TypeScript script. Your agent writes one script that performs all operations in a single round trip: creating sections, adding content, and setting styles.
Code mode endpoint
In internal benchmarks across five models and three email complexity levels, Code Mode reduced total token consumption by 68–96%, with most results in the 85–95% range (learn more in our blogpost)
Use Code Mode when your agent makes many sequential tool calls to reduce API costs and latency.
Code Mode fully supports brandRules. Pass it the same way as in the standard API-managed or editor-managed paths above. The agent's generated scripts are validated against your Brand Rules guardrails like any other session.
Code Mode also supports reusableRows. Also pass it the same way as in the API-managed or editor-managed paths above. The agent's generated scripts can search the library and place its rows like in any other session. See Reusable Rows for AI.
Code Mode also supports fileManager. Pass it the same way as in the API-managed or editor-managed paths above; the agent's scripts can then list, search, upload, and remove files as with the standard tools, and place a file they just saved in the same script. See File Manager for AI.
Last updated
Was this helpful?

