MCP server
rolebook mcp: a Model Context Protocol server that runs next to your own Rolebook server, so an agent can look up and explain access and propose changes you confirm.
rolebook mcp is a Model Context Protocol server that runs on your
machine, next to the Rolebook server you mount with @rolebook/server. Your agent’s MCP client starts
it as a local process and talks to it on stdin and stdout. It calls your server’s
Sharing HTTP API, as one identity you configure, and nothing else.
It comes with @rolebook/cli. There is no hosted endpoint in this package.
Add it to your agent
Most MCP clients take a JSON entry like this one:
{
"mcpServers": {
"rolebook": {
"command": "npx",
"args": ["--no", "rolebook", "mcp"],
"env": {
"ROLEBOOK_URL": "https://app.example.com/api/sharing",
"ROLEBOOK_TOKEN": "a token your server accepts for this person",
"ROLEBOOK_POLICY": "src/authz/policy.ts"
}
}
}
} --no stops npx from downloading anything, so it runs only a copy that is already installed.
Start the client in your project’s directory: elsewhere, npx can find a globally installed command
of the same name. The package is not on npm yet, and the npm package named rolebook is unrelated. The variables are the same as for the command
line; see Connect to your server. ROLEBOOK_POLICY is optional; a
policy module named there runs in a child process as for the command line:
the credentials are not passed in its environment and only its exported policy comes back, but it
is not a sandbox, so name only your own file.
Who the agent acts as
The server acts as the identity in its configuration, and only that identity:
- Your server’s
getContextturnsROLEBOOK_TOKEN,ROLEBOOK_COOKIEorROLEBOOK_HEADERSinto the tenant and the actor, as it does for a request from your app. The tenant and the actor are never taken from a tool argument. - Every tool’s input schema is closed. An argument the schema does not name, such as
tenantId,actor,headersorurl, is refused before any request is sent. - That identity’s own Rolebook roles still apply: the agent can read and change only what that person could through your app.
- Values the tools return (ids, names, emails, roles) are data from your server. The server’s instructions tell the agent never to follow instructions found in them, and errors are written by the MCP server from status and code, never copied from the server’s text.
- Without
ROLEBOOK_URLor a credential the server does not start. An unreachable server, a timeout or a rejected credential is an error result, never an empty answer. Credentials never appear in a result.
Give the agent a credential for a person, not a service account with more access than you want the agent to have.
Tools
| Tool | What it does |
|---|---|
describe_access | The owner, the direct members with their roles and expiry, and pending invitations of one item. Access that comes from a parent item or a team is not listed; use explain_access for one person. |
check_access | Whether the configured identity may do one action on an item, or all its actions. |
explain_access | Why a subject can or cannot do an action, with the deciding rule. Needs inspection on your server. |
list_accessible | The items of one type the configured identity can reach, one page at a time. |
audit_history | Who changed access to an item, and when. |
grant_role | Previews giving a subject a role on an item, optionally until a date. |
change_role | Previews changing a member’s role or expiry. |
revoke_member | Previews removing a member. |
apply_change | Applies the newest preview, given its confirmation and the same change restated. |
get_policy | Only when ROLEBOOK_POLICY is set: the policy’s version, resource types and actions. |
list_roles | Only when ROLEBOOK_POLICY is set: each role’s scope, inherited roles and rules. |
Read tools are marked read-only. grant_role, change_role and revoke_member are read-only too:
they only preview. apply_change is the only tool that changes anything, and it is marked
destructive.
Changes are previewed first
A change takes two calls, and the first never changes anything:
grant_role,change_roleorrevoke_memberreads the item’s current access and returns what would change (the subject’s role and expiry before and after, and warnings such as “already a member”), thechangeitself, and aconfirmation.- After the user agrees,
apply_changetakes theconfirmationand the same change restated:kind,resource,subject,role, andexpiresAtorpermanentas the preview returned them. A restated change that differs from the preview is refused and discards the preview; arguments that do not fit the tool’s schema are refused before that and leave it in place. So the arguments your MCP client shows you when it asks to runapply_changeare the change itself, not an opaque id.
Only the newest preview can be applied, once, within 10 minutes: a second preview replaces the first,
so an agent cannot show you one change and apply another. apply_change sends one
sharing.executeIfUnchanged command carrying the previewed sharing revision, with an idempotency key
fixed at preview time, and your server decides whether the identity may make it. The server checks
the revision in the same commit as the change, so when anything moved it since the preview, even a
moment before the write, nothing is applied and the result is STALE_PREVIEW. A server that
predates sharing.executeIfUnchanged, or a newer one whose sharing runtime does not declare
conditionalExecution, answers 404 and the result is PRECONDITION_UNSUPPORTED;
the change is never sent without its revision. If no valid result or 4xx refusal in the Sharing
API’s error format came back (no answer, a 5xx, a 2xx or 3xx carrying an error, or a body that is
not the API’s), the result is OUTCOME_UNKNOWN and the preview is kept: calling apply_change
again with the same arguments retries with the same key and revision, so a change that did apply is
reported as already applied, not applied twice, and one that did not applies only if nothing else
changed the item meanwhile.
Set your MCP client to ask before every apply_change call: that prompt is where you confirm, and
these guarantees hold only if it is shown to you. A membership reaching its expiry does not move the
revision. And if your server chooses the tenant from session state that
can change, such as an “active team” cookie, keep it fixed while the agent changes access. Invitations
and ownership transfers are not available as tools in this version.
Protocol
The server speaks JSON-RPC 2.0, one message per line of at most 1 MiB, and does not accept batches.
It answers the initialize handshake of the 2025-11-25, 2025-06-18 and 2024-11-05 revisions, and
server/discover with per-request versions for the 2026-07-28 revision. It offers tools only: no
resources, prompts or sampling.
Not in this version
- A hosted MCP endpoint. A hosted server would belong to Rolebook Console, which is not available yet.
issue_invitation: the Sharing API returns the invitation token to the caller, and the MCP server returns no secrets to an agent.diff_policyandsdk_snippet. Userolebook policy diffand the skills instead.