Skip to main content

Connect Your App to Agentic Flows

The Prismatic MCP flow server allows you to connect your app's AI agent or chatbot to your agentic flows.

Example in-app chat using Prismatic MCP

Authentication for embedded customer users​

If your AI client is embedded in your application (for example, you've built a chat bot with the AI SDK), you will need to create an embedded JWT for your customer user and provide that JWT as a bearer token to Prismatic's MCP flow server.

Node AI SDK​

If you're building your own AI client using the AI SDK, use the createMCPClient function from @ai-sdk/mcp to connect to Prismatic's MCP flow server. Configure an HTTP transport that points to Prismatic's MCP flow server, and pass an embedded JWT for the customer user as a bearer token. It can be the same JWT you use to embed Prismatic.

When you invoke your LLM with streamText, pass the tools from Prismatic's MCP flow server to the tools option. The tools include a default me tool that returns information about the current Prismatic user; remove it if your chat bot doesn't need it. Close the MCP client when the response finishes.

This example uses AI SDK 7. It returns a web-standard Response, so you can use the POST function as a route handler in frameworks such as Next.js.

Connecting to Prismatic's MCP flow server with the AI SDK
import { createMCPClient } from "@ai-sdk/mcp";
import { openai } from "@ai-sdk/openai";
import {
convertToModelMessages,
createUIMessageStreamResponse,
isStepCount,
streamText,
toUIMessageStream,
type UIMessage,
} from "ai";
// Your function that signs an embedded JWT for the signed-in customer user
import { generatePrismaticJwt } from "./prismatic-auth";

// Connect to Prismatic's MCP flow server as an embedded customer user
const connectPrismaticMcp = async (prismaticJwt: string) => {
const client = await createMCPClient({
transport: {
type: "http",
url: "https://mcp.prismatic.io/mcp",
headers: {
Authorization: `Bearer ${prismaticJwt}`,
},
},
});

// Remove the default "me" tool, which returns the current Prismatic user
const { me, ...tools } = await client.tools();

return { client, tools };
};

// Handle chat completion requests from a chat bot
export async function POST(req: Request) {
const { messages }: { messages: UIMessage[] } = await req.json();

const { client, tools } = await connectPrismaticMcp(generatePrismaticJwt());

const result = streamText({
model: openai("gpt-5.6-terra"),
messages: await convertToModelMessages(messages),
instructions:
"You are a helpful assistant for Acme SaaS. Help users interact with the integrations they've deployed by invoking MCP tools you have access to.",
tools,
stopWhen: isStepCount(5),
onEnd: async () => {
await client.close();
},
});

// Stream the assistant message back in the format that the useChat hook reads
return createUIMessageStreamResponse({
stream: toUIMessageStream({
stream: result.stream,
tools,
originalMessages: messages,
}),
});
}

For a full example, see the Chat Bot page of the example embedded app on GitHub.