Skip to content

Function: useMastraClient()

useMastraClient(): MastraPluginClient

The single MastraPluginClient for the plugin, built once from the published basePath. Use it for everything: stream a turn with client.streamAgent({ agentId, messages, runId, threadId, model, signal }), page history with client.history(), resolve embeds with client.chart(id), etc. Rebuilt only when basePath / defaultAgent change (e.g. a custom mount), so it’s safe as a useMemo / useCallback / useEffect dependency; per-turn thread + model routing is passed per call rather than stored on the client, so concurrent runs stay isolated.

MastraPluginClient