跳至主要內容

Mastra.getMCPServer()

.getMCPServer() 方法會按註冊表鍵(在 mcpServers 設定中註冊伺服器時使用的鍵)擷取 MCP 伺服器執行個體。如要按伺服器本身的 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 伺服器時使用的註冊表鍵。這是鍵值配對中的設定鍵,而不是伺服器本身的 id 屬性。

傳回值
傳回值 的直接連結

server:

MCPServerBase | undefined
具有指定註冊表鍵的 MCP 伺服器執行個體;如找不到,則為 undefined。

另請參閱
另請參閱 的直接連結