跳到主要内容

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。

另请参阅
另请参阅的直接链接