> Discover all available pages from the documentation index: https://mastra.zisheng.pro/zh-TW/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/zh-TW/reference/core/getMCPServerById): 依本身的 `id` 屬性取得 MCP server - [Mastra.listMCPServers()](https://mastra.zisheng.pro/zh-TW/reference/core/listMCPServers): 列出所有已註冊的 MCP server ## 另請參閱 - [MCP 概覽](https://mastra.zisheng.pro/zh-TW/docs/mcp/overview) - [MCP server 參考](https://mastra.zisheng.pro/zh-TW/reference/tools/mcp-server)