AI

Agent-first: one set of tools, every entry point

Nov 2026 · 3 min read

There are two ways to build in Codelab. You can click and type in the builder, or you can describe what you want to an AI agent. Neither one is the "real" way. Both are entry points onto the same set of tools.

One set of tools, several entry points

Every change to an app is a builder operation: add an element, update its props, set a style, create a store, bind an action. Three surfaces call those operations:

  • The builder UI. You drag an element onto the canvas, pick a variant in the props panel, type an expression into a field.
  • The in-app AI. The chat rail in the builder. The model calls tools such as add_elements and update_props, and you watch the changes land on the canvas.
  • MCP. Connect Claude, Cursor, Codex or another MCP client to https://mcp.codelab.app/mcp and it calls the same tools from your editor.

Under the hood, a tool is a thin adapter over the same operation the UI calls. The in-app AI and MCP register the same tool definitions, with the same input schemas. There's no second API for agents, no export-and-import step, and no sync. A write from any entry point lands in the same model, so it shows up on the live canvas and on the published site.

Why agent-first

Treating the agent as a first-class entry point, rather than a feature bolted onto a visual editor, shapes how the tools are built:

  • Schemas come from the domain. A tool's input schema is the operation's command schema. The props an agent can set come from the same component metadata the props panel uses, so the agent can't set a prop the component doesn't accept.
  • Edits are patches. The model sends only the keys it wants to change; null clears one. It never has to repeat a whole object, so it can't overwrite values it didn't mean to touch.
  • Validation is shared. A bad value is rejected the same way whether you typed it or a model did, and the model gets the error back as the tool result so it can correct itself.
  • Approval is part of the loop. In the builder, the agent's proposed changes show up as cards you can review before they apply.

Different entry points, different strengths

Having both doesn't mean using them the same way.

The UI is best when you know exactly what you want and can see it: nudging spacing, picking a variant, checking a page at another width.

The agent is best for intent: "add a pricing section with three tiers," "turn this list into cards bound to the products store," "make the header sticky." It turns a sentence into a dozen tool calls.

MCP brings that agent into the tools you already use. The model writing your backend can also lay out the page that calls it, in the same session.

You can switch between them at any point. Ask the agent for a first draft, adjust a prop by hand, then ask for the next section. Every surface sees the same tree, so nothing gets out of step.

The model is the contract

What makes this work is that Codelab's model is small and explicit: elements with kinds, props and children; stores with fields and actions; expressions that read data. The UI is one way to edit that model, and an agent is another. Because both go through the same operations, a better model makes both of them better.

Read what Codelab is for the element libraries those tools work with, and the binding layer for how props read state.