# Mastra

Connect a Mastra agent to the same chat view used by the Vercel AI SDK.

## Stream v7 UI messages from Mastra

Install the tested Mastra packages on your server.

```bash
npm install @mastra/ai-sdk@1.11.2 @mastra/core@1.79.0
```

Keep your Mastra instance, agent, and authentication on the server. Set version: "v7" to match the client recipe.

```tsx
import { handleChatStream, type ChatStreamHandlerParams } from "@mastra/ai-sdk";
import type { Mastra } from "@mastra/core/mastra";
import { createUIMessageStreamResponse, type UIMessage } from "ai";
export async function streamMastra(mastra: Mastra, agentId: string, params: ChatStreamHandlerParams<UIMessage>) {
  const stream = await handleChatStream({ mastra, agentId, params, version: "v7" });
  return createUIMessageStreamResponse({ stream });
}

```

Supply validated request parameters from your server route. Preserve the returned response headers. Configure memory/resource/thread identity and tool policy in Mastra rather than accepting a client-selected privileged resource.

## Render in React

Point [the Vercel AI SDK client](/libraries/ai-runtime-vercel) at your route with DefaultChatTransport. Its hook tracks messages, and createAiSdkAdapter passes them to Ghost. Workflows and networks can use this client when their outputs use the same protocol.

## Extend and diagnose

Keep native run/thread IDs and resume data for approval/recovery. A local Ghost edit is not a Mastra memory rewrite. For a missing tool or sub-agent view, inspect native UI data parts and supply an intentional renderer rather than silently dropping them. Mismatched SDK/bridge versions can fail at stream decoding even when the endpoint returns 200.

See [Mastra AI SDK UI](https://mastra.ai/integrations/agentic-ui/ai-sdk-ui) for server routes, approval and memory configuration, and [stability](/libraries/ai-stability) for checked frontend versions.
