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(): Server 自体の
idプロパティで MCP Server を取得 - Mastra.listMCPServers(): 登録済みのすべての MCP Server を一覧表示