uiResource(spec) and
attach it to tools by value. The backend never imports the view’s code.
notes.ts
app.ts
name is lowercase words joined by -. entry is a string literal,
relative to the directory that holds app.ts. At deploy the
CLI bundles it with its imports into one HTML document, with scripts and
styles inline, served at ui://<server path>/<view name>.<digest>.html. Its
URI changes when its bytes change. csp (connectDomains,
resourceDomains, frameDomains, baseUriDomains) and permissions
(camera, microphone, geolocation, clipboardWrite) default to none,
so a view reaches no network origin. bijection.lock records each origin
and permission you add.
Which tools a view may call
app sets which tools a view may call, and views may call none by default.
app: true lets the model and views call the tool. app: "only" hides it
from the model. The library always states _meta.ui.visibility, because
the MCP Apps default would let views call every tool. A tool with a view
also needs app if its view reads it again.
app controls what the host offers; it grants nothing. A view’s call runs
as the user, under the function’s label, and every guard judges it. The
server cannot tell a view’s call from the model’s, so put a confirmation
step inside any destructive function.
A client without MCP Apps support gets no _meta.ui and no app: "only"
tools. Every tool still returns content and structuredContent, so the
text answer works on its own.
Write the view
@bijectionhq/library-mcp/view starts the view and gives the transport for
connect. In React, render your component under <Bijection client={client}>
from @bijectionhq/bijection/react, so useWatch and useMutation work as
in any React app, and subscribe to view.state() with useSyncExternalStore:
views/board.tsx
client.query and client.mutate directly:
views/standalone.ts
mountView() performs the ui/initialize handshake over postMessage.
The iframe holds no credential. Each client.query or client.mutate is
one host tools/call, made by the host as the user, of the tool the server
names for that function’s tree path in _meta["com.bijection/tools"], else
of the tool named by the path itself. mountView({ tools }) maps other
paths to tool names. view.state() exposes input, result and
hostContext as sent by the host. mountView applies the host’s style
variables, and applyHostTheme maps them to the tokens the Elements read.
How a view stays current
The Apps protocol gives a view no subscription, soclient.watch and
useWatch keep their signatures and read again:
- The first value comes from the tool result, when the query and its arguments are those of the tool that opened the view.
- It reads again after each call the view makes that is not a watched query.
- It reads again when the view becomes visible.
- It polls from 2 s, doubling while unchanged up to 60 s, and pauses while
hidden.
mountView({ refresh: { min, max } })changes the bounds in milliseconds, andrefresh: "manual"turns polling off.
_meta["com.bijection/ifVersion"] with the version it
holds, and the server answers “unchanged” without the body when nothing
changed.
Results in a view
Every call answers aResult. A refused call answers the typed refusal the
host or the server set in _meta["com.bijection/error"]: its code, its
public reason, message, an app refusal’s declared data and, on
Forbidden, guard. A failure in the view itself is
Failed, and a lost host reply is Unknown.
client.mutate and useMutation mint a fresh once for each call by
default and send it as _meta["com.bijection/once"]. To retry an Unknown,
pass its once with the original arguments. See
Retries answer once.
client.trial, optimistic edits and framed clients (.as, .under,
.in, .at) are not available in a view. They answer Failed with an
UnsupportedInView sentence that names the alternative.