Function: buildMcpServer()
buildMcpServer(
opts):ResolvedMcp|null
Build the plugin’s MCP server, or null only when config.mcp is
explicitly false.
Agent exposure is on by default because it’s cheap: the already-
registered agents are wrapped as ask_<agentId> tools and handed to
@mastra/express (already mounted for the chat routes) - no extra
process, dependency, or network cost, and requests run under the same
OBO scope. So undefined (the default) and true both expose every
registered agent under a server id equal to the plugin name; only
false turns MCP off. The object form (MastraMcpConfig) tunes
the id / advertised metadata and can additionally expose the plugin’s
ambient tools or a set of extra MCP-only tools. Ambient tools stay off
unless explicitly enabled - they assume an in-process chat turn, so
they aren’t cheap / safe to expose to a standalone MCP client.
Parameters
Section titled “Parameters”agents
Section titled “agents”Record<string, Agent>
ambientTools
Section titled “ambientTools”config
Section titled “config”displayName
Section titled “displayName”string
pluginName
Section titled “pluginName”string
Returns
Section titled “Returns”ResolvedMcp | null