Mastra.getMCPServer()
.getMCPServer() 方法通过其注册表键(在 mcpServers 配置中注册服务器时使用的键)检索 MCP 服务器实例。要通过服务器的内在 id 属性进行检索,请改用 .getMCPServerById()。
🌐 The .getMCPServer() method retrieves an MCP server instance by its registry key (the key used when registering the server in the mcpServers configuration). For retrieving by the server's intrinsic id property, use .getMCPServerById() instead.
使用示例Direct link to 使用示例
🌐 Usage example
// 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');
参数Direct link to 参数
🌐 Parameters
registryKey:
string
The registry key used when registering the MCP server in the mcpServers configuration object. This is the key in the key-value pair, not the server's intrinsic id property.
返回Direct link to 返回
🌐 Returns
server:
MCPServerBase | undefined
The MCP server instance with the specified registry key, or undefined if not found.
相关方法Direct link to 相关方法
🌐 Related Methods
- Mastra.getMCPServerById() - 通过其内在的
id属性获取 MCP 服务器 - Mastra.listMCPServers() - 列出所有已注册的 MCP 服务器
另请参阅Direct link to 另请参阅
🌐 See Also