MastraEditor class
The MastraEditor class sets up the editor system. Pass it to the Mastra constructor to turn on editor features like prompt blocks, agent code override, versioning, and tool providers.
See Editor for an introduction to what the editor does.
Usage exampleUsage example的直接链接
import { Mastra } from '@mastra/core'
import { MastraEditor } from '@mastra/editor'
export const mastra = new Mastra({
agents: {/* your agents */},
editor: new MastraEditor(),
})
Constructor parametersConstructor parameters的直接链接
logger?:
toolProviders?:
processorProviders?:
filesystems?:
sandboxes?:
blobStores?:
browsers?:
builder.features.agent.browser is enabled. See the BrowserProvider reference for the provider interface.builder?:
enabled: false to disable the Builder.source?:
codePath?:
Provider interfacesProvider interfaces的直接链接
Each provider field above takes a record keyed by provider id. See the per-provider reference pages for the implementation shape:
Agent BuilderAgent Builder的直接链接
The builder field enables the Agent Builder, a browser-based UI for creating and editing stored agents. See:
- Agent Builder overview: Concepts and getting started.
- AgentBuilderOptions: Full options schema.
- BuilderAgentDefaults: Admin-pinned defaults for new agents.
- builder.configuration.agent.models: Model allowlist and default model.
Registering the Builder agentRegistering the Builder agent的直接链接
The Builder UI runs against an agent created by the createBuilderAgent() factory from @mastra/editor/ee. Import the factory, invoke it, and register the returned agent under agents on your Mastra instance:
import { Mastra } from '@mastra/core'
import { MastraEditor } from '@mastra/editor'
import { createBuilderAgent } from '@mastra/editor/ee'
export const mastra = new Mastra({
agents: { builderAgent: createBuilderAgent() },
editor: new MastraEditor({
builder: { enabled: true },
}),
})
The key name (builderAgent) is conventional. Any key works. The @mastra/editor/ee subpath is gated by the Mastra Enterprise Edition license at runtime.
See the Agent Builder overview for the full setup checklist.
NamespacesNamespaces的直接链接
The editor exposes namespaces for managing different entity types. Access them from any Mastra instance with mastra.getEditor() and call the CRUD methods directly in application code, or rely on the Mastra server routes that use them under the hood.
All namespaces extend a shared CRUD base class, so they expose the same create, getById, update, delete, list, listResolved, and clearCache methods. The namespace-specific property tables below also document any additional methods.
agent:
create:
getById:
update:
delete:
list:
listResolved:
applyStoredOverrides:
clone:
clearCache:
prompt:
create:
getById:
update:
delete:
list:
listResolved:
preview:
clearCache:
mcp:
create:
getById:
update:
delete:
list:
listResolved:
clearCache:
mcpServer:
create:
getById:
update:
delete:
list:
listResolved:
clearCache:
scorer:
create:
getById:
update:
delete:
list:
listResolved:
clearCache:
Agent namespace examplesAgent namespace examples的直接链接
Create a stored override for an existing code-defined agent:
import { mastra } from '../mastra'
const editor = mastra.getEditor()!
await editor.agent.create({
id: 'support-agent',
instructions: 'You are a friendly support agent for Acme.',
tools: {
search_kb: { description: 'Search the Acme knowledge base' },
},
})
Stored agent memoryStored agent memory的直接链接
The memory field of a stored agent accepts one of these shapes:
{ type: 'id', memoryId: string }: Uses a memory instance registered on the Mastra instance. The editor looks upmemoryIdas a registry key first, then as the memory instance'sid. The agent uses that exact instance, including its storage, processors, and working memory settings.{ type: 'inline', config: SerializedMemoryConfig }: Builds a new memory instance from a serializable config.SerializedMemoryConfig: The untagged inline config. Existing stored agents use this shape and keep working.
Reference a registered memory instance so many stored agents share one configuration:
import { mastra } from '../mastra'
const editor = mastra.getEditor()!
await editor.agent.create({
id: 'support-agent',
name: 'Support agent',
instructions: 'You are a friendly support agent for Acme.',
model: { provider: 'openai', name: 'gpt-5' },
memory: { type: 'id', memoryId: 'supportMemory' },
})
The reference is resolved when the editor loads the agent. If no registered memory matches memoryId, the agent loads without memory and the editor logs a warning that names the missing key. The stored reference isn't changed. In conditional memory, a variant whose reference isn't registered is skipped. If you register memory with mastra.addMemory() after an agent has loaded, call editor.agent.clearCache(id) so the next load picks it up. Renaming or removing a key in the Mastra memory config detaches memory from every stored agent that references it, so keep keys stable across deployments.
editor.agent.clone() stores a reference when the source agent uses a registered memory instance, and an inline config otherwise.
MethodsMethods的直接链接
Provider accessProvider access的直接链接
getToolProvider(id)gettoolproviderid的直接链接
Returns a registered tool provider by its ID.
const composio = mastra.getEditor()?.getToolProvider('composio')
getToolProviders()gettoolproviders的直接链接
Returns all registered tool providers as a Record<string, ToolProvider>.
getProcessorProvider(id)getprocessorproviderid的直接链接
Returns a registered processor provider by its ID.
getProcessorProviders()getprocessorproviders的直接链接
Returns all registered processor providers.
getFilesystemProviders()getfilesystemproviders的直接链接
Returns all registered filesystem providers.
getSandboxProviders()getsandboxproviders的直接链接
Returns all registered sandbox providers.
getBlobStoreProviders()getblobstoreproviders的直接链接
Returns all registered blob store providers.
SourceSource的直接链接
getSource()getsource的直接链接
Returns the configured source ('code' or 'db'), or undefined when the editor was constructed without an explicit source.
const source = mastra.getEditor()?.getSource()
Returns: 'code' | 'db' | undefined
When source is omitted, Editor uses the configured database storage even though getSource() returns undefined. See Editor storage options for the storage workflows and code-source versioning for activation and Git history behavior.