Skip to content

plugin

AppKit plugin that builds one or more Mastra Agent instances and mounts the @mastra/express server. Clients drive the conversation over the standard Mastra agent stream (@mastra/client-js’s getAgent(id).stream()), so there’s no bespoke chat transport to keep in sync.

  • Agents: registered through config.agents at plugin creation (MastraAgentDefinition). Each entry’s tools field accepts either a plain record or a (plugins) => tools callback that gets a typed sibling-plugin index (MastraPlugins). Omit config.agents to get a single built-in default analyst.
  • Model: each agent call resolves a MastraModelConfig via buildModel from ./model.js. Per-agent model overrides (AgentConfig["model"] or a modelId string) flow through buildAgents.
  • Memory / storage: per-agent, built by createMemoryBuilder from ./memory.js. Both auto-default to true when the lakebase plugin is registered (unless the caller passed false or a custom config). Storage namespaces per agent via agentStorageSchemaName per agent; the vector store is a single shared singleton across every agent.
  • Server: the Express subapp wiring lives in ./server.js.
  • HTTP: AppKit mounts this plugin under /api/mastra. Alongside the Mastra agent routes, the plugin registers /route/history (load + clear a thread’s messages), /route/threads (list the caller’s conversations + delete one), /models, /default-model, /suggestions, /route/feedback (log a thumbs / comment to MLflow when feedback is enabled), and the generic /embed/:type/:id resolver for inline chart / data markers. Each is registered through AppKit’s route() so it lands in the plugin’s endpoint map, and every outbound call one makes runs through execute() (see ./defaults.js). The stock @mastra/express surface is gated by config.apiAccess (default "scoped"): only agent inference, read-only agent metadata, the /route/* routes, and (when enabled) MCP are dispatched to Mastra; admin / mutating / bulk-export routes are refused with 403. See isMastraRequestAllowed.
  • MCP: opt in with config.mcp to expose the agents (and optionally tools) as a Mastra MCPServer. It is registered on the Mastra instance via mcpServers, so @mastra/express serves the stock MCP transport routes (/mcp/<serverId>/...) under the mount. See ./mcp.js.