Mastra.getMCPServer()
.getMCPServer() 方法依註冊鍵(在 mcpServers 設定中註冊 server 時使用的鍵)取得 MCP server 執行個體。要依 server 的本身的 id 屬性取得,請改用 .getMCPServerById()。
使用範例「使用範例」的直接連結
// 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(): 依本身的
id屬性取得 MCP server - Mastra.listMCPServers(): 列出所有已註冊的 MCP server