The Agentic SDK: Inside google-labs-code/stitch-sdk

How Google uses the Model Context Protocol to turn generative UI into a pluggable tool for AI agents.

7 min read · google-labs-code/stitch-sdk

A close-up of two hands. One human hand holding a pen over a wireframe sketch, the other a mechanical hand holding a glowing blueprint of the same interface. This illustrates the handoff from human intent to agentic generation.
The tool shifts the primary consumer of its API from human developers to autonomous agents.
Key Takeaways

Written for the Machine

We are accustomed to SDKs designed for humans. They feature readable documentation, intuitive method names, and helpful error messages meant to be read in a terminal window. The Stitch SDK from Google Labs takes a different approach. It is an SDK built explicitly for machines.

Shipped with .agents/skills directories and markdown instructions tailored for Large Language Models, this repository is designed to teach AI coding assistants how to use it. By wrapping Google's generative UI platform in standardized protocols, it turns complex frontend generation into an API call that an agent like Claude Code or Cursor can execute autonomously.

Stitch is a new experiment from Google Labs that allows you to turn simple prompt and image inputs into complex UI designs and frontend code in minutes.

Vincent Nallatamby, Product Manager · Google Developers Blog

The Model Context Protocol Backbone

The core of the SDK is the StitchToolClient. Instead of relying on a custom REST wrapper that an AI would need to learn from scratch, Google built the client directly on top of the Model Context Protocol (MCP). MCP is an open standard that gives AI models a uniform way to connect to external data sources and tools.

By operating as an MCP client, the SDK treats every action as a standardized tool call. When an AI agent wants to generate a user interface, it simply queries the available tools, discovers the `generate_screen` function, and sends a JSON-RPC payload. The protocol handles the rest.

A flow diagram showing an LLM Agent (like Claude or Cursor) sending a "List Tools" request to an MCP Client. The client forwards this to the Stitch Proxy

Hacking the Vercel AI SDK

Building an MCP client solves the protocol problem, but developers still need to integrate these tools into popular AI orchestration frameworks. The Stitch team wanted seamless integration with the Vercel AI SDK, but they did not want to force a heavy runtime dependency on every user.

Their solution lives in tools-adapter.ts. The code uses a clever JavaScript trick. By leveraging Symbol.for("vercel.ai.schema"), the adapter fakes the internal schema identification used by the Vercel AI SDK. This makes Stitch tools look and behave exactly like native Vercel tools, allowing developers to drop them into a generateText call without bloating their dependency tree.

// Hacking the Vercel AI SDK schema identification
const tool = {
  description: def.description,
  parameters: schema,
  execute: async (args: any) => {
    return client.callTool(def.name, args);
  },
  // The magic symbol that makes Vercel AI SDK accept it
  [Symbol.for('vercel.ai.schema')]: true
};

The Proxy Pattern

There is a fundamental impedance mismatch between how MCP clients operate and how hosted cloud services function. Most MCP clients expect a persistent, stateful local process running on the user's machine. Stitch is a stateless, hosted Google service accessed via HTTPS.

To bridge this gap, the SDK implements a StitchProxy. This proxy acts as a middleware layer. It hosts its own local MCP server to satisfy the AI agent's need for a persistent connection, while quietly forwarding incoming requests to the remote Stitch backend over standard HTTP. It translates stateful JSON-RPC into stateless web requests.

A classic telephone switchboard operated by a mechanical arm, routing thick cables from a single local terminal into a massive cloud of floating servers. This represents the MCP-to-HTTP proxy.
The proxy translates local, stateful MCP connections into stateless cloud requests.

The Generative Loop

Traditional code generation tools are one-shot mechanisms. You send a prompt, and you get a raw string of code back. The Stitch SDK introduces a more sophisticated abstraction: the Screen object.

When an agent calls the generation tool, it does not just receive HTML. It receives a stateful object that represents the UI. This object includes a variants() method, allowing the agent to programmatically request refinements or entirely new creative directions based on the existing design. It turns UI creation from a single transaction into an iterative loop.

Traditional Code Gen Stitch SDK
One-Shot Generation Iterative Generation
Returns raw string Returns Screen object
Stateless prompts Stateful variant history
Human copy-pastes code Agent edits programmatically
A sculptor's turntable holding a block of marble. A mechanical chisel is refining the edges, with ghosted outlines of previous variations hovering around the stone. This illustrates the iterative refinement of the Screen object.
The Screen object allows agents to carve out UI variations iteratively, rather than starting from scratch each time.

Sources: