One package—@matter.work/app-sdk—works across browser pages, background workers, and MCP tools.
npm install @matter.work/app-sdkimport matter from '@matter.work/app-sdk'
The package holds the SDK’s types and a small loader. When your app runs, the loader hands over to the SDK
the member’s Matter serves, so your app always gets the one that matches their version.
matter app create sets up the package and bundler for you.
Bundler setup for pages#
In the browser, Matter serves the runtime module from the app’s own origin at /_matter/sdk.js.
Configure your bundler to leave that import external so the browser loads it directly from Matter:
import { defineConfig, type Plugin } from 'vite'
const matterSdk: Plugin = {
name: 'matter-sdk',
enforce: 'pre',
resolveId: (id) =>
id === '@matter.work/app-sdk' || id === '/_matter/sdk.js'
? { id: '/_matter/sdk.js', external: true }
: null,
load: (id) => (id === '/_matter/sdk.js' ? 'export {}' : null),
}
export default defineConfig({
plugins: [matterSdk],
optimizeDeps: { exclude: ['@matter.work/app-sdk'] },
build: { rollupOptions: { external: ['/_matter/sdk.js'] } },
})In Node processes (worker, tools)#
In Node, @matter.work/app-sdk dynamically loads the module path Matter provides in
MATTER_SDK_URL and authenticates with MATTER_APP_TOKEN. Bundle your Node
entrypoints (for example with esbuild), or import
process.env.MATTER_SDK_URL directly in unbundled scripts:
const { default: matter } = await import(process.env.MATTER_SDK_URL)Viewer & workspace context#
In browser pages, identity properties are available synchronously on matter before your script
runs:
| Property | Shape |
|---|---|
matter.user |
{ id, memberId, name, role, timezone, image } |
matter.role |
'owner' | 'admin' | 'member' | 'guest' |
matter.app |
{ id, name } |
matter.space |
{ id, name } |
matter.workspace |
{ id, name } |
Call await matter.context() (required first in Node processes) to get those same fields plus:
deployment:{ id, preview, local }describing the running version.-
setup:{ deviceId, thisDevice }if the member has added the app, ornull. device:{ id }of the current computer.member:{ id, name, image }, the member using the app.
Subscribe to live context changes (such as space renames, role updates, or setup changes) with
matter.onContextChange:
const stop = matter.onContextChange((ctx) => renderHeader(ctx.user.name))Workspace lookups & error handling#
-
await matter.tables(): lists all tables in the app’s space along with their field metadata ({ id, key, name, type, options, declared }). -
await matter.boards(): lists the boards in the app’s space with their statuses and fields ({ id, key?, name, statuses, fields }). -
await matter.members(): lists active workspace members ({ id, name, role, image }).imageis the URL of their profile photo, ornull. To show one as Matter does, use<matter-avatar>.
Failed SDK calls reject with a MatterError exposing error.code,
error.message, and HTTP error.status. The common codes are below; pages for
models and
connections list their own.
| Error code | When it occurs |
|---|---|
invalid |
Malformed query option, unknown field/option key, or invalid argument. |
not_found |
Table, index, routine, or row does not exist (or needs a deploy first). |
precondition_failed |
A write’s if didn’t match the row.
|
conflict |
A write violated a unique index constraint. |
forbidden |
The current member’s role does not allow the operation. |
too_large |
A file, prompt or request is over its limit. |
index_building |
A large table’s index is still being built. Try again shortly. |
offline |
A read that needs the server, like one of a large table, couldn’t reach it. |
unavailable |
Matter can’t reach what the call needs right now, like its local service or an account that’s off. |