# 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 ```typescript // 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()](https://mastra.ai/reference/core/getMCPServerById): Retrieve an MCP server by its intrinsic `id` property - [Mastra.listMCPServers()](https://mastra.ai/reference/core/listMCPServers): List all registered MCP servers ## See also - [MCP overview](https://mastra.ai/docs/mcp/overview) - [MCP server reference](https://mastra.ai/reference/tools/mcp-server)