> Discover all available pages from the documentation index: https://mastra.zisheng.pro/llms.txt # Mastra.getMCPServer() `.getMCPServer()` 方法按注册键(在 `mcpServers` 配置中注册 server 时使用的键)获取 MCP server 实例。要按 server 的固有 `id` 属性获取,请改用 `.getMCPServerById()`。 ## 使用示例 ```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') ``` ## 参数 **registryKey** (`string`): 在 mcpServers 配置对象中注册 MCP server 时使用的注册键。它是键值对中的配置键,而不是 server 的固有 id 属性。 ## 返回值 **server** (`MCPServerBase | undefined`): 具有指定注册键的 MCP server 实例;如果未找到,则为 undefined。 ## 相关方法 - [Mastra.getMCPServerById()](https://mastra.zisheng.pro/reference/core/getMCPServerById): 按固有 `id` 属性获取 MCP server - [Mastra.listMCPServers()](https://mastra.zisheng.pro/reference/core/listMCPServers): 列出所有已注册的 MCP server ## 另请参阅 - [MCP 概览](https://mastra.zisheng.pro/docs/mcp/overview) - [MCP server 参考](https://mastra.zisheng.pro/reference/tools/mcp-server)