> Discover all available pages from the documentation index: https://mastra.zisheng.pro/zh-HK/llms.txt # Mastra.listMCPServers() `.listMCPServers()` 方法用於擷取已在 Mastra 執行個體中註冊的所有 MCP 伺服器執行個體。傳回的記錄以註冊表鍵(即 `mcpServers` 設定中的鍵)作為鍵。 ## 使用範例 ```typescript // Register MCP servers const server1 = new MCPServer({ id: 'server-one', name: 'Server One', version: '1.0.0', tools: {/* ... */}, }) const server2 = new MCPServer({ id: 'server-two', name: 'Server Two', version: '1.0.0', tools: {/* ... */}, }) export const mastra = new Mastra({ mcpServers: { firstServer: server1, // Registry key: 'firstServer' secondServer: server2, // Registry key: 'secondServer' }, }) // List all registered servers const servers = mastra.listMCPServers() // Returns: { firstServer: MCPServerBase, secondServer: MCPServerBase } ``` ## 參數 此方法不接受任何參數。 ## 傳回值 **servers** (`Record | undefined`): 所有已註冊 MCP 伺服器執行個體的記錄,鍵為註冊表鍵(來自 mcpServers 設定),值為 MCPServerBase 執行個體;如沒有已註冊的伺服器,則為 undefined。 ## 相關方法 - [Mastra.getMCPServer()](https://mastra.zisheng.pro/zh-HK/reference/core/getMCPServer):按註冊表鍵擷取 MCP 伺服器 - [Mastra.getMCPServerById()](https://mastra.zisheng.pro/zh-HK/reference/core/getMCPServerById):按 MCP 伺服器本身的 `id` 屬性擷取伺服器 ## 另請參閱 - [MCP 概覽](https://mastra.zisheng.pro/zh-HK/docs/mcp/overview) - [MCP 伺服器參考](https://mastra.zisheng.pro/zh-HK/reference/tools/mcp-server)