Reference

Complete API reference for the Stitch TypeScript SDK.

Installation

npm install @google/stitch-sdk

Exports

All exports are available from @google/stitch-sdk:

import {
  stitch,           // Default singleton instance
  Stitch,           // Domain class: project management
  Project,          // Domain class: screen management within a project
  Screen,           // Domain class: screen operations
  StitchToolClient, // Low-level MCP client
  StitchProxy,      // Local proxy server
  StitchError,      // Error class
  StitchErrorCode,  // Error code enum
} from "@google/stitch-sdk";

AI SDK adapter (separate subpath):

import { stitchTools } from "@google/stitch-sdk/ai";

stitch (Singleton)

The default entry point. A lazily-initialized Proxy that combines Stitch domain methods and StitchToolClient infrastructure methods.

Reads STITCH_API_KEY and STITCH_HOST from environment variables on first access.

import { stitch } from "@google/stitch-sdk";

Domain methods

MethodReturnsDescription
createProject(title)Promise<Project>Creates a new project.
projects()Promise<Project[]>Lists all projects accessible to the authenticated user.
project(id)ProjectCreates a Project handle from an existing project ID or resource name. No API call.

Infrastructure methods

MethodReturnsDescription
listTools()Promise<{ tools: ToolDefinition[] }>Lists all available MCP tools.
callTool<T>(name, params)Promise<T>Calls a raw MCP tool by name.
close()Promise<void>Closes the underlying MCP client connection.

Stitch

Main entry point class. Manages projects.

import { Stitch, StitchToolClient } from "@google/stitch-sdk";

const client = new StitchToolClient({ apiKey: "..." });
const s = new Stitch(client);

Constructor

ParameterTypeDescription
clientStitchToolClientAn initialized tool client instance.

Methods

MethodReturnsDescription
createProject(title)Promise<Project>Creates a new project. Maps to MCP tool create_project.
projects()Promise<Project[]>Lists all projects. Maps to MCP tool list_projects.
project(id)ProjectCreates a Project handle without an API call. Accepts a project ID or full resource name (projects/{id}).

Project

A Stitch project containing screens.

Properties

PropertyTypeDescription
projectIdstringThe project ID (without projects/ prefix).
idstringAlias for projectId.
dataanyRaw API response data, if constructed from server response. undefined if constructed from an ID string.

Methods

MethodParametersReturnsDescription
generate(prompt, deviceType?, modelId?)prompt: string, deviceType?: DeviceType, modelId?: ModelIdPromise<Screen>Generates a new screen from a text prompt. Maps to generate_screen_from_text.
screens()-Promise<Screen[]>Lists all screens in the project. Maps to list_screens.
getScreen(screenId)screenId: stringPromise<Screen>Retrieves a specific screen by ID. Maps to get_screen.
upload(filePath, opts?)filePath: string, opts?: { title?: string, createScreenInstances?: boolean }Promise<UploadResult>Uploads a file (.png, .jpg, .jpeg, .webp, .html, .htm) and creates a screen. Posts directly to REST API. Never throws — returns a discriminated result.
createDesignSystem(ds)ds: { displayName: string }Promise<DesignSystem>Creates a design system for this project.
listDesignSystems()-Promise<DesignSystem[]>Lists all design systems in the project.
designSystem(id)id: stringDesignSystemCreates a DesignSystem handle from an asset ID. No API call.
uploadDesignMd(designMdBase64)designMdBase64: stringPromise<any>Uploads a DESIGN.md file (base64-encoded) to the project. Returns a screen instance. Maps to upload_design_md.
createDesignSystemFromDesignMd(selectedScreenInstance, deviceType?)selectedScreenInstance: SelectedScreenInstance, deviceType?: DeviceTypePromise<DesignSystem>Creates a design system from an uploaded DESIGN.md. Maps to create_design_system_from_design_md.

DesignSystem

A design system asset that defines visual tokens for a project.

Properties

PropertyTypeDescription
idstringThe asset ID.
dataanyRaw API response data. undefined if constructed from an ID string.

Methods

MethodParametersReturnsDescription
update(ds)ds: { displayName?: string }Promise<DesignSystem>Updates the design system’s metadata.
apply(selectedScreenInstances){ id: string, sourceScreen: string }[]Promise<Screen[]>Applies this design system to the given screens. Only pass id and sourceScreen — extra fields cause errors.

Screen

A generated UI screen. Provides access to HTML code and screenshot images.

Properties

PropertyTypeDescription
projectIdstringParent project ID.
screenIdstringThe screen ID.
idstringAlias for screenId.
dataanyRaw API response data.

Methods

MethodParametersReturnsDescription
edit(prompt, deviceType?, modelId?)prompt: string, deviceType?: DeviceType, modelId?: ModelIdPromise<Screen>Edits this screen with a text prompt. Returns a new Screen; original is unchanged. Maps to edit_screens.
variants(prompt, variantOptions, deviceType?, modelId?)prompt: string, variantOptions: VariantOptions, deviceType?: DeviceType, modelId?: ModelIdPromise<Screen[]>Generates design variants. Maps to generate_variants.
getHtml()-Promise<string>Returns the HTML download URL for this screen. Uses cached URL if available.
getImage()-Promise<string>Returns the screenshot download URL. Uses cached URL if available.

StitchToolClient

Low-level MCP client that connects to the Stitch server over HTTP.

import { StitchToolClient } from "@google/stitch-sdk";

Constructor

ParameterTypeDescription
configStitchConfigInputConnection configuration.

StitchConfigInput

FieldTypeRequiredDescription
apiKeystringOne of apiKey or accessTokenAPI key for authentication.
accessTokenstringOne of apiKey or accessTokenOAuth access token.
projectIdstringRequired with accessTokenGoogle Cloud project ID (for OAuth).
baseUrlstringNoOverride the server URL. Defaults to https://stitch.googleapis.com/mcp.

Methods

MethodReturnsDescription
connect()Promise<void>Explicitly connects to the MCP server. Called automatically on first tool call.
callTool<T>(name, params)Promise<T>Calls a named MCP tool with the given parameters.
listTools()Promise<{ tools: ToolDefinition[] }>Lists all available tools from the server.
close()Promise<void>Closes the connection.

stitchTools(options?)

AI SDK adapter. Returns Stitch tools in Vercel AI SDK format.

Import from the /ai subpath:

import { stitchTools } from "@google/stitch-sdk/ai";

Parameters

FieldTypeDescription
options.apiKeystringOverride STITCH_API_KEY env var.
options.includestring[]Only include specific tool names.

Returns

Record<string, Tool> - Drop directly into generateText({ tools: stitchTools() }).


StitchError

Error class thrown by all SDK methods.

PropertyTypeDescription
messagestringHuman-readable error message.
codeStitchErrorCodeStructured error code.

Static methods

MethodDescription
StitchError.fromUnknown(error)Wraps any thrown value into a StitchError.

Enums

DeviceType

"DEVICE_TYPE_UNSPECIFIED" | "MOBILE" | "DESKTOP" | "TABLET" | "AGNOSTIC"

ModelId

"MODEL_ID_UNSPECIFIED" | "GEMINI_3_PRO" | "GEMINI_3_FLASH"

CreativeRange

"CREATIVE_RANGE_UNSPECIFIED" | "REFINE" | "EXPLORE" | "REIMAGINE"

VariantAspect

"VARIANT_ASPECT_UNSPECIFIED" | "LAYOUT" | "COLOR_SCHEME" | "IMAGES" | "TEXT_FONT" | "TEXT_CONTENT"


Environment Variables

VariableDescription
STITCH_API_KEYAPI key for authentication. Used by the stitch singleton and stitchTools().
STITCH_HOSTOverride the MCP server URL. Defaults to https://stitch.googleapis.com/mcp.
STITCH_ACCESS_TOKENOAuth access token (alternative to API key).
GOOGLE_CLOUD_PROJECTGoogle Cloud project ID (required with OAuth).

Original: https://stitch.withgoogle.com/docs/sdk/reference/

Translated from the official Google Stitch documentation. Original content © Google LLC. This is an independent, unofficial translation.