Mastra.getMCPServer()
The .getMCPServer() method retrieves an MCP server instance by its registry key (the key used when registering the server in the mcpServers configuration). For retrieving by the server's intrinsic id property, use .getMCPServerById() instead.
Usage example
// Register an MCP server with a registry key
const myServer = new MCPServer({
id: 'my-mcp-server',
name: 'My Server',
version: '1.0.0',
tools: { /* ... */ },
});
export const mastra = new Mastra({
mcpServers: {
customKey: myServer, // 'customKey' is the registry key
},
});
// Retrieve by registry key
const server = mastra.getMCPServer('customKey');
// Alternatively, retrieve by intrinsic ID
const serverById = mastra.getMCPServerById('my-mcp-server');
Parameters
registryKey:
string
The registry key used when registering the MCP server in the mcpServers configuration object. This is the key in the key-value pair, not the server's intrinsic id property.
Returns
server:
MCPServerBase | undefined
The MCP server instance with the specified registry key, or undefined if not found.
Related Methods
- Mastra.getMCPServerById() - Retrieve an MCP server by its intrinsic
idproperty - Mastra.listMCPServers() - List all registered MCP servers