メインコンテンツへ移動

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。

関連情報
関連情報への直接リンク