> Discover all available pages from the documentation index: https://mastra.zisheng.pro/zh-HK/llms.txt # Mastra.getMCPServer() `.getMCPServer()` 方法會按註冊表鍵(在 `mcpServers` 設定中註冊伺服器時使用的鍵)擷取 MCP 伺服器執行個體。如要按伺服器本身的 `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 伺服器時使用的註冊表鍵。這是鍵值配對中的設定鍵,而不是伺服器本身的 id 屬性。 ## 傳回值 **server** (`MCPServerBase | undefined`): 具有指定註冊表鍵的 MCP 伺服器執行個體;如找不到,則為 undefined。 ## 相關方法 - [Mastra.getMCPServerById()](https://mastra.zisheng.pro/zh-HK/reference/core/getMCPServerById):按 MCP 伺服器本身的 `id` 屬性擷取伺服器 - [Mastra.listMCPServers()](https://mastra.zisheng.pro/zh-HK/reference/core/listMCPServers):列出所有已註冊的 MCP 伺服器 ## 另請參閱 - [MCP 概覽](https://mastra.zisheng.pro/zh-HK/docs/mcp/overview) - [MCP 伺服器參考](https://mastra.zisheng.pro/zh-HK/reference/tools/mcp-server)