Malla文档

MCP server

Connect an agent with an API key, and every MCP tool, action, resource, error and limit.

用户指南New

此页面尚未翻译,暂以英文显示。

Malla runs a Model Context Protocol (MCP) server, so AI agents such as Claude can do everything you can do in the web app: edit pages and styles, manage the CMS, tables and forms, upload assets, run server workflows, publish and more. This page lists how to connect, what each tool does and the limits that apply.

Every document edit goes through the same operations as the editor. It is validated the same way, shows up live on the canvas for everyone who has the page open, and you can undo it in your editor.

Connect a client

The server speaks MCP over streamable HTTP at one endpoint:

text
POST https://<your MCP host>/mcp
Authorization: Bearer mk_…

There is no public MCP address yet: use the MCP host of your Malla installation, for example https://mcp.example.com/mcp. Each request is answered with JSON; the server never opens a stream, so GET /mcp answers 405.

In Claude Code:

bash
claude mcp add --transport http malla https://mcp.example.com/mcp \
  --header "Authorization: Bearer mk_your_key"

In clients that read a JSON config:

json
{
  "mcpServers": {
    "malla": {
      "type": "http",
      "url": "https://mcp.example.com/mcp",
      "headers": { "Authorization": "Bearer mk_your_key" }
    }
  }
}

The tutorial Build a page with an AI agent over MCP walks through a full session.

API keys and scopes

An agent signs in with a workspace API key. To create one, open a page in the editor, press Ask AI, then the key icon (API keys). Type a name, check Write if the agent should make changes, and press Create. The key starts with mk_ and is shown only once: press Copy and store it in your agent's secret settings.

ScopeLets the agent
Read (always on)Call every read tool and every action that only reads (list, get…).
Write (Write checked)Everything Read allows (a write key can always read), plus document edits and every action that changes something.

A key without Write gets This API key is read-only (or the api error read_only_key) when it tries to change something.

  • Only workspace owners and admins can create, list and revoke keys.
  • A key belongs to one workspace. Sites of other workspaces answer “not found”, even if you are a member there.
  • An agent can create keys with the api_keys tool, but only with scopes its own key has. A read key can never create a write key.
  • Press Revoke in API keys to stop a key at once.

Roles

The agent can do what your role allows, on each site, exactly as in the web app. See Team and roles.

Your role on the siteThrough MCP
ViewerEvery read tool and resource.
Content editorReads, CMS content, and text edits of plain text nodes on pages. Any other page or style change is refused, by the MCP server and again by the live page.
EditorEvery document edit, pages, CMS, tables, forms, assets, server workflows, publish to staging.
Admin, ownerEverything above, plus integrations, custom domains, members, production publishes, code export, billing and API keys.

Tools

Tools come in six families. Ids (sites, pages, nodes, classes) always come from a read tool first: start with list_sites, then list_pages, get_site and get_page.

Read

ToolReturns
list_sitesThe sites of the key's workspace you can open.
list_pagesThe pages and components of a site, with their path, kind and SEO.
get_siteThe live site document: page records, classes, design tokens, breakpoints, site variables and formulas.
get_pageThe live document of a page or component: nodes, styles, props, interactions, variables, queries and workflows.
get_site_stylesJust the classes, tokens and breakpoints of a site.

High-level edits

The same tools as the AI panel. Page tools take siteId and pageId; site tools take siteId.

ToolDoes
insert_subtreeAdd a section or element tree, reusing your classes.
set_stylesSet or clear styles of a node per breakpoint and state.
set_propsChange text, links, tags and classes, or bind them to expressions.
create_classCreate a reusable class.
create_queryAdd a page query.
create_workflowAdd a client workflow with a trigger and steps.
set_page_seoWrite the SEO title and description of a page.
set_alt_textDescribe an image.

Editor commands

editor_command runs a command from the editor's menus and shortcuts on a page, with the same cleanup (for example, deleting a node also removes the interactions that target it). Input: { siteId, pageId, command, input }. Nodes are addressed by id.

CommandInput
deleteids
duplicateids
cutids; returns the clipboard payload for paste
pastepayload, optional parent, index
moveUp, moveDownids (siblings)
wrapInFrameids (siblings), optional frameId
wrapInLinkids (siblings), optional linkId
unwrapLinkid of a link block
toggleHiddenids, optional hidden
toggleLockedids, optional locked
insertNodetype, optional parent, index, props, styles, name, preset: "linkBlock"
insertInstancecomponentId, optional parent, index, styles, name
createComponentid of the node, optional name; the component page is created for you, and deleted again if the command then fails
detachInstanceid of an instance; replaces it by a plain copy of its component
nudgeids, optional dx, dy (pixels), breakpoint

The tool's input schema lists each command's input shape. A command with nothing to do (for example, deleting only locked nodes) is refused with an error instead of doing nothing silently.

Raw operations

For full control, send the document operations themselves. Each call is one batch of up to 500 operations, applied in order in one transaction. The whole batch is checked against the live document first: if one operation is invalid, nothing is applied and the error names its index.

  • page_ops (siteId, pageId, ops): setProp, setStyle, setMeta, insert, insertSubtree, move, delete, setInteraction, setVariable, setQuery, setWorkflow, setStyleBinding.
  • site_ops (siteId, ops): setClass, renameClass, setClassStyle, setColorToken, setFontToken, setSpacingToken, setBreakpoints, setSiteVariable, setFormula, addPage, removePage, setPageSeo, setPage.

Each operation has a t field with its type; the tool's input schema describes every field. See The page document for the model behind them.

Refactors

These change the site document and every page that uses the token or class, in one go.

ToolInputDoes
token_usagesiteId, kind, keyCount the references to a token across classes, tokens and pages.
rename_tokensiteId, kind, from, toRename a token and rewrite every var(--<kind>-<from>).
remove_tokensiteId, kind, keyDelete a token; each reference is replaced by its value.
delete_classsiteId, classIdDelete a class and its combo classes and remove them from every node.

kind is color, font or space.

Domain tools

Everything that is not a document edit is one tool per area, with an action argument. The arguments are { action, <ids>, query?, body? }: ids such as siteId or collectionId are top-level, query holds filters and paging, body holds what you create or change. workspaceId defaults to the key's workspace. Each action is one call of the HTTP API, with the same roles, plan limits and checks.

ToolActions
siteslist, create, get, update, delete
workspacesend_invite
pageslist, create, get, update, delete
cmslist_collections, create_collection, get_collection, update_collection, delete_collection, list_items, create_item, get_item, update_item, delete_item, publish_item, unpublish_item, archive_item, schedule_item, list_versions, restore_version
tableslist, create, update, delete, list_rows, insert_row, update_row, delete_row
visitorslist, update, delete, get_roles, set_roles
formslist, list_recipients, get, update, list_submissions, export_csv, delete_submission
assetslist, upload, read, delete
integrationslist_plugins, list, create, update, delete, test
pluginscatalog_list, catalog_get, catalog_upload, catalog_submit, catalog_withdraw, list_installed, install, update_installed, uninstall
server_workflowslist, create, get, update, delete, test, call, list_runs, get_run
publishpublish, history, rollback, export
domainslist, add, refresh, remove
templateslist, save_site, create_section, get, bundle, delete, use
memberslist, add, remove
billingplans, get_workspace, set_workspace_plan, portal, get_site, set_site_plan
api_keyslist, create, revoke
airun (the editor AI assistant over a selection; prefer the page tools), expression (write, fix or explain one expression from a scope shape; answers a checked proposal, not applied)
runquery (run a data query as the editor previews it)

Notes on a few actions:

  • pages create, update and delete also update the editor's page list, like the Pages panel. A component is a page with kind: "component" and no path.
  • pages update with seo: null clears the SEO settings; access sets the visitor access rule of a page ({ rule: { $expr }, redirect? }, or null to remove it).
  • pages update with a doc replaces the stored document and is refused while the page is open live; edit open pages with the tools above.
  • cms update_item and server_workflows update take an optional version: if someone changed the record since, the call answers 409 instead of overwriting their work.
  • billing set_workspace_plan and set_site_plan answer a checkout URL when payment is needed. Open it in a browser.
  • workspace send_invite answers 501 while invite emails are not set up on the server.

Resources

The server also offers the live documents as MCP resources, as JSON:

URIContent
malla://site/{siteId}The live site document, the same as get_site.
malla://page/{siteId}/{pageId}The live page or component document, the same as get_page.

resources/list lists every site the key can open and its pages. Subscriptions are not supported: read a resource again to see changes.

Undo

Changes an agent makes with your key reach your open editors as your own undoable steps. Press ⌘Z to take one back. Each change the agent sends is its own step and never merges with your typing. Nobody else can undo it, and your undo never overwrites a change someone made after it.

The agent itself has no undo tool: undo is part of your editor session. To revert a change from the agent, ask it to make the opposite change.

Errors

A tool that fails returns a result with isError: true and a message, so the agent can read it and try again.

  • Document tools say what went wrong and, for batches, which operation: for example ops[3]: ….
  • Domain tools also return structuredContent.error with the api's status, code, message and details. Common codes: not_found (404, also for sites you cannot open), forbidden (403, role too low), read_only_key (403), plan_limit (402), version_conflict (409, the record changed since you read it), live_document (409, the page is open live), asset_in_use (409), payload_too_large (413).

Problems with the request itself are JSON-RPC errors:

CodeHTTPMeaning
-32001401Missing, malformed, unknown or revoked API key.
-32700400The body is not valid JSON.
-32600200 or 413Not a JSON-RPC request, or the body is over 32 MiB.
-32601200Unknown method.
-32602200Missing or invalid parameters, or an unknown resource URI.
-32002200Resource not found.

Limits

WhatLimit
Request body32 MiB per JSON-RPC request (room for a 20 MB file as base64).
Raw operations500 per page_ops or site_ops call.
Asset upload20 MB. Send base64 (or a data: URL) or a public https url, plus a filename with its extension. URLs are fetched by the server under the same rules as integrations: https only, no private or local addresses.
Binary readsassets.read and publish.export return base64 up to 5 MB. Larger files: download them in the web app.
CSV exportforms.export_csv returns up to 1 MB of text, then says it was cut; page through the rest with list_submissions.
Workflow test runsserver_workflows.test waits for the run to end, up to waitMs (default 30 s, max 120 s). If it is still running, you get its latest state; poll with get_run.
AI runsai.run waits for the assistant up to 120 s.

Plan limits, quotas and AI usage are the same as in the web app. See Plans and billing.

What is not available

A few api routes have no MCP tool on purpose:

  • Account and session routes: sign up, log in and out, change password, email verification, password reset and accepting an invite. They manage a person's browser account, so an API key is refused there. Do these in the web app.
  • The current user (/auth/me) and the editor's realtime token: a key already acts as you, and MCP writes to the live rooms directly.
  • The Stripe webhook: only Stripe calls it.
  • The live step stream of a workflow run: it is a WebSocket. server_workflows.test and get_run poll the run instead.
  • Replacing a stored page document (PUT /pages/:id/doc): edit documents with the page tools.
  • Editor-only commands: selection, zoom, panels, preview, copy, and undo or redo have no effect on a document.