Use with AI SDK
Wire Stitch tools into the Vercel AI SDK and let an LLM generate designs autonomously.
The Stitch SDK ships a dedicated adapter for the Vercel AI SDK. Import stitchTools() from the /ai subpath and drop it directly into generateText() or streamText(). The LLM handles tool orchestration-you just write the prompt.
Install
You need three packages:
npm install @google/stitch-sdk ai @ai-sdk/google
Set your keys
export STITCH_API_KEY="your-stitch-api-key"
export GOOGLE_GENERATIVE_AI_API_KEY="your-gemini-api-key"
Basic usage
import { generateText } from "ai";
import { google } from "@ai-sdk/google";
import { stitchTools } from "@google/stitch-sdk/ai";
const { text } = await generateText({
model: google("gemini-3.1-flash-lite-preview"),
tools: stitchTools(),
maxSteps: 5,
prompt: "Create a new Stitch project called 'Landing Page' and generate a hero section with a CTA button.",
});
console.log(text);
The LLM will call create_project, then generate_screen_from_text, then return a natural language summary of what it built. You don’t need to write any orchestration logic.
Filter tools
If you want to restrict which tools the model can access, pass an include array:
const tools = stitchTools({
include: ["create_project", "generate_screen_from_text", "list_projects"],
});
This is useful for tightening the model’s scope-for example, preventing it from deleting projects.
Override the API key
If you don’t want to rely on the STITCH_API_KEY env var, pass it directly:
const tools = stitchTools({ apiKey: "your-key-here" });
How it works
stitchTools() returns a Record<string, Tool> that is directly compatible with the AI SDK’s tool format. Each tool is pre-wired with an execute function that calls the underlying Stitch MCP server. The adapter has zero runtime dependency on the ai package-it only imports the Tool type.
For a deeper look at the architecture, see Architecture.
Original: https://stitch.withgoogle.com/docs/sdk/ai-sdk/
Translated from the official Google Stitch documentation. Original content © Google LLC. This is an independent, unofficial translation.