Reference
The SDK
@tabs-and-spaces/sdk has no dependencies and two entry points:
@tabs-and-spaces/sdk, for your page:connect(), and for your action's own view,connectView().@tabs-and-spaces/sdk/server, for your server:verifyToken(),fetchKeys(), for actions,dataClient(), and for events at any time,reportEvent().
npm install @tabs-and-spaces/sdkIt's ES modules, with TypeScript types, for Node 22 or later and browsers. Apps made with tands new don't need it: they come with a built copy, in plain JavaScript. Without the SDK, speak the frame protocol directly. It's a few messages.
connect()
function connect(options?: ConnectOptions): Promise<Connection>;Connects your page to the workspace showing it. It says hello, then resolves when the workspace answers with who's looking.
| Option | Default | What it does |
|---|---|---|
timeoutMs | 10000 | How long to wait for the workspace before rejecting |
applyTheme | false | Follows the workspace's look on <html>: data-theme set to its theme, and its colours (styles) set as CSS variables, kept up to date. For pages using the design stylesheet. |
window | window | The window your page runs in (for tests) |
It rejects with an Error when:
- the page isn't open in a workspace ("This page isn't open in a Tabs & Spaces workspace.");
- the workspace doesn't answer in time ("The workspace didn't answer.").
Connection
| Member | What it is |
|---|---|
context | Who's looking, and where: a TabContext in a tab, a HomeContext on Home (isHome(context) tells them apart; see Home pages) |
theme | "light" or "dark", now |
styles | The workspace's own colours for that theme, as the design language's CSS variables ({ "--color-accent": "#0f766e", … }): its accent, when it has one. Empty when it keeps the default ink, or from a workspace before 0.10. See Design language. |
readOnly | Whether the workspace is read-only now (its bill is unpaid): your data can be read, not changed. Kept in step with context.workspace.readOnly. See When the workspace is read-only. |
token() | Promise<string>: the current token, or a fresh one when less than a minute is left. Calls made together share one request. It rejects if the workspace refuses, for example if your app was removed. |
values(scope) | Free-form values in a scope (workspace, space, tab or user): get(key), set(key, value), delete(key), list(). See Keeping data. |
collection(name) | A collection your manifest declares: list(options), get(id), create(data), update(id, data), delete(id). See Keeping data. |
read | The workspace as the person looking can read it: workspace(), spaces(), members(), agents(), tasks(query), countTasks(query), files(query), fileContent(id), messages(query). Each needs a permission in your manifest. See Reading the workspace. |
data(request) | Any data request, as values(), collection() and read send it |
emit(name, data) | Promise<void>: reports an event your manifest declares, for the person looking, in this space. See Events. |
requestEventKey() | Promise<{ key, eventsUrl }>: a key your server reports events with, in this tab, at any time, once the person allows it. Rejects with DECLINED or FORBIDDEN. See Events. |
openTrigger(event?) | Promise<void>: opens a new trigger in this space, starting on one of your events in this tab (the first, without event), for the person to finish and save. Rejects with NO_TASKS_TAB when the space has no Tasks tab. See Events. |
open(target) | Promise<void>: takes the person to a space ({ space }) or one of its tabs ({ space, tab }). Your page is left. |
onTheme(listener) | Calls listener(theme, styles) when the reader switches theme, or the workspace changes its colours. Returns a function that stops it. |
onReadOnly(listener) | Calls listener(readOnly) when the workspace becomes read-only, or writable again, while your page is open. Returns a function that stops it. |
onDataChange(listener) | Calls listener({ scope, collection }) when your app's data that this page can see changes (by anyone, this page too): a collection's records, or collection: null for values. Read it again. Returns a function that stops it. See Keeping data. |
onEvent(type, listener) | Calls listener(event) when something your app listens for happens while this page is open, here or across the workspace, as the person looking may see it. onEvent(listener) hears every type. Returns a function that stops it. See Hearing the workspace. |
events.since(cursor?, { limit? }) | Promise<{ events, cursor, missed, more }>: what your app heard after cursor (none: from the oldest kept), as the person looking may see it, everywhere. Keep cursor and pass it next time. |
close() | Stops listening. Pending token() calls reject. |
TabContext
interface TabContext {
user: { id: string; name: string };
workspace: {
id: string;
slug: string;
name: string;
readOnly: boolean; // read-only until its bill is paid (false from older workspaces)
};
space: {
id: string;
kind: "general" | "personal" | "normal" | "dm";
name: string; // as the reader sees it, in their language
};
tab: { id: string; appTabId: string };
app: { id: string };
locale: string; // "en", "fr", …
}WorkspaceError
Data calls reject with a WorkspaceError when the workspace refuses. Its code says why:
| Code | When |
|---|---|
INVALID | The data doesn't fit the collection, or the request is malformed |
NOT_FOUND | No such collection or record, here |
FORBIDDEN | Only people in the space can change its data |
TOO_LARGE | A value over 16 KB, a record over 32 KB, or a request over 64 KB |
APP_DATA_FULL | Your app keeps 100 MB here already |
APP_NOT_INSTALLED | Your app was removed from the workspace |
WORKSPACE_READ_ONLY | The workspace is read-only until its bill is paid: reads work, writes don't |
verifyToken()
function verifyToken(
token: string,
options: { keys: PublicKey[]; audience: string; issuer?: string; now?: number },
): Promise<VerifiedToken>;Checks a token and returns who's looking:
| Option | What it is |
|---|---|
keys | The deployment's public keys, from fetchKeys() |
audience | Your app's origin, like https://crm.example.com |
issuer | The deployment's address. Pass it; see Decide which workspaces you serve. |
now | The time, in milliseconds (for tests) |
It resolves with { context: TabContext, issuer: string, expiresAt: Date, action: string | null }; action names the action an action's token is for. It throws a TokenError when the token:
- isn't a token;
- uses another algorithm;
- names a key it doesn't know;
- has a signature that doesn't match;
- is meant for another app;
- comes from another deployment;
- has expired;
- is an events token, not a page's.
verifyEvents()
function verifyEvents(
request: Request | { body: string; authorization: string | null },
options: { keys: PublicKey[]; audience: string; issuer?: string; now?: number },
): Promise<EventBatch>;Checks what the workspace sent your app's webhook, and returns the batch: { issuer, workspace: { id, slug, name }, app: { id }, events: WorkspaceEvent[], missed }. The options are verifyToken()'s. Each WorkspaceEvent has id, seq, type, at and data (typed by type: see WorkspaceEventData). It throws a TokenError when there's no token, or it isn't the deployment's, for your app, current, an events token, or for this body. See Hearing the workspace.
fetchKeys()
function fetchKeys(deploymentUrl: string, fetcher?: typeof fetch): Promise<PublicKey[]>;Fetches a deployment's public keys from <deploymentUrl>/api/apps/keys. It throws a TokenError if they can't be fetched. Cache the result. See Keys.
dataClient()
function dataClient(
request: { dataKey: string; dataUrl: string },
fetcher?: typeof fetch,
): {
values(scope): Values;
collection(name): Collection;
read: WorkspaceReader;
data(request): Promise<unknown>;
emit(name: string, data?: Record<string, unknown>): Promise<void>;
};Your app's data from your server, with the key an action's request carries (pass the whole ActionRequest). The same values(), collection() and read as in your page, for the action's place and person, for five minutes. Refusals throw a DataError with a code. See Your data, from your server. emit() reports an event with the same key.
ActionRequest<Input> is the type of an action request's body: action, input, context, agent, dataKey and dataUrl. ActionAnswer is what you answer with: result, and optionally cards (ActionCard[]) showing what it found (see Showing what you found), and data for your action's own view (see Your action's own view).
reportEvent()
function reportEvent(
eventKey: { key: string; eventsUrl: string },
name: string,
data?: Record<string, unknown>,
fetcher?: typeof fetch,
): Promise<void>;Reports an event from your server at any time, with the tab's event key from requestEventKey(): in that tab's space, for the person who allowed it. Refusals throw a DataError with a code (401 once the key is turned off). See Reporting from your server, at any time.
connectView()
function connectView<Data, Input>(options?: ConnectViewOptions): Promise<View<Data, Input>>;Connects your action's own view to the workspace showing it, under an agent's answer. It speaks MCP Apps for you: it introduces itself, takes the workspace's theme and colours, resolves once it's told what your action was asked and answered, and keeps the frame as tall as your page.
import { connectView } from "@tabs-and-spaces/sdk";
const view = await connectView<{ notes: { message: string }[] }>({ name: "Hello" });
draw(view.data.notes ?? []);
// Another of your actions that only reads, as whoever is looking.
const busy = await view.call("list_notes", { mood: "busy" });| Option | Default | What it does |
|---|---|---|
name | "app" | Your app's name, as the view introduces itself |
timeoutMs | 10000 | How long to wait for the workspace before rejecting |
applyTheme | true | Sets data-theme on <html> and the workspace's colours as CSS variables, so var(--color-text-primary, …) follows it |
autoResize | true | Tells the workspace your page's height as it changes (up to 720 px) |
window | window | The window your page runs in (for tests) |
It rejects when the page isn't open in a workspace, or the workspace doesn't answer in time. Once the workspace has answered, only messages from its origin count.
View
| Member | What it is |
|---|---|
data | Your action's data (empty when it sent none) |
text | Its words: your result |
input | What your action was asked |
result | The answer as MCP Apps tells it: content, structuredContent |
context | Where it's shown: theme, locale, timeZone, platform, the workspace's colours (styles.variables), and the action (toolInfo) |
call(action, input) | Promise<{ text, data }>: runs another of your app's actions that only read, in the same tab, as whoever is looking. Rejects with the reason when it fails, or when the action changes something (the agent asks for those). |
open(url) | Opens a web address in a new tab |
ask(text) | Promise<boolean>: asks the agent, as whoever is looking, once they've clicked in your view. Resolves with whether the workspace took it. |
onContext(listener) | Calls listener(context) when the reader switches theme. Returns a function that stops it. |
close() | Stops listening. |
isHome()
isHome(context: PageContext): context is HomeContextWhether a context is a home page's (no space or tab, a home, and user.guest) rather than a tab's. Exported by both @tabs-and-spaces/sdk and @tabs-and-spaces/sdk/server. verifyToken() returns either kind; an action's is always a tab's.
Messages
The SDK also exports the frame protocol's types and readers (AppMessage, HostMessage, DataRequest, DataRecord, readAppMessage(), readHostMessage() and PROTOCOL_VERSION), and what your app hears (WorkspaceEvent, WorkspaceEventData, EventsPage), for anyone speaking it directly. See The frame protocol.
The design language
The package carries the workspace's look for your pages in design/ (see Design language):
| Path | What it is |
|---|---|
@tabs-and-spaces/sdk/design/tabs-and-spaces.css | The stylesheet: Inter, the tokens, the base styles and the ts- parts |
@tabs-and-spaces/sdk/design/fonts/ | Inter's files, which the stylesheet loads from beside it, and its licence (SIL Open Font License 1.1) |
@tabs-and-spaces/sdk/design/menus | menus(): makes every ts-menu move like the workspace's menus (focus in, arrow keys, Home, End, Tab out). Call once. |
@tabs-and-spaces/sdk/design/icons | icon(name, { size?, label? }): an icon as SVG markup; renderIcons(root?): draws <span data-icon="…">; ICONS |
import "@tabs-and-spaces/sdk/design/tabs-and-spaces.css"; // with a bundler; or copy design/ beside your page
import { icon } from "@tabs-and-spaces/sdk/design/icons";
button.innerHTML = `${icon("plus")} New request`;