> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bijection.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Expose tools

`tool(fn, { description })` from `@bijectionhq/library-mcp` offers one query
or mutation as a tool. `tools(subtree, descriptions?)` offers every function
of a subtree, each named by its key, with an optional map from key to
description. The function may be exposed (`allow`) or internal; the server
is then one more way in, so give it the same care as `allow`.

```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { mcp, tool, tools } from "@bijectionhq/library-mcp";
import { archive, mine } from "./notes";

mcp({
  server: { name: "notes", version: "1.0.0" },
  tools: {
    ...tools({ mine }, { mine: "List my notes" }),
    archive: tool(archive, {
      description: "Archive one of my notes",
      annotations: { destructiveHint: true, idempotentHint: true },
    }),
  },
});
```

Tool names are `[A-Za-z0-9_.-]{1,128}`. The tool takes its schemas from the
function's contract. `args` produce a JSON Schema 2020-12 input schema and
`returns` an output schema, which also types `structuredContent`. The
generated skill reference lists the function's `refuses` codes. A tool
cannot redeclare its argument types. The result has a JSON text block, and
`present(value)` can add content blocks. Declare JSON-compatible arguments.
`annotations` are hints to the client and grant nothing. A query tool is
marked `readOnlyHint: true`.

## Who a call runs as

The route runs the tool's function with `ctx.call`, under the server's
`under` label, as the principal the server's verifier admitted. A mutation
tool joins the request's transaction. A query tool reads in the same frame.

Every guard over the acts judges the call. A guard on `act.enter(fn)` judges
entering the function from the server, as it does for any other caller.
Guards on the function's writes, submits and grave acts judge them in the
same transaction:

```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { act, forbid } from "@bijectionhq/bijection";
import { archive } from "./notes";

export const peopleArchive = forbid(act.enter(archive), {
  message: "Agents list notes; a person archives them.",
  where: (a) => a.as.kind.equals("agent"),
});
```

Place the guard in the tree beside the function; its path is its identity.

A view's calls and the model's calls look the same to the server. Put a
confirmation step inside any destructive function rather than relying on
which surface called it.

## Refusals

Every refusal refuses the request's transaction: `ctx.refuse`, a false
assumption of a strict write (`Absent`, `Exists`), a guard (`Forbidden`),
missing authority (`Disallowed`) and any other host code. The host answers
the call as a tool result with `isError: true`. Its text is
`<code>: <message>` for the model, and
`_meta["com.bijection/error"]` carries the typed refusal:

```json theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
{
  "isError": true,
  "content": [{ "type": "text", "text": "Forbidden: Agents list notes; a person archives them." }],
  "_meta": {
    "com.bijection/error": {
      "code": "Forbidden",
      "message": "Agents list notes; a person archives them.",
      "guard": "notes.peopleArchive"
    }
  }
}
```

`code` is a host code, with its public `reason` when it has one, or one of
the function's declared `refuses`, with `kind: "app"` and, when `refuses`
declares a payload for that code, its `data`. On `Forbidden`, `guard` is the
path of the guard that refused. A function that
throws without refusing also answers `isError`, and nothing it wrote
commits.

## Retries answer once

A client that may retry a mutation tool sends an identity for the call in
`params._meta["com.bijection/once"]`. The host answers a call with the same
caller, `once`, tool name and arguments with the first call's result for a
day, committing nothing new. The same `once` with another call refuses
`Invalid`. A refused first call records nothing, so a retry runs again.
Without `once`, every call is a new call.

```json theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
{
  "jsonrpc": "2.0",
  "id": 7,
  "method": "tools/call",
  "params": {
    "name": "archive",
    "arguments": { "id": "note_1" },
    "_meta": {
      "io.modelcontextprotocol/protocolVersion": "2026-07-28",
      "io.modelcontextprotocol/clientCapabilities": {},
      "com.bijection/once": "archive-note_1"
    }
  }
}
```

A lost reply leaves the result `Unknown`: send the same request again with
the same `once`. A view's client does this for you
([Views](https://docs.bijection.com/mcp/views.md)).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.