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