Repository navigation
Capability Scopes and Access
Three options of #[Capability(...)] say who may call a capability: public, scope and level. They are checked
once, in Capabilities::call(), for every channel: a page, a form, REST, the JS client, an agent over MCP, the command
line and the jobs all get the same answer. Since 2.1.0.
Since 2.26.0 an empty scope on a write capability (not readOnly, not public) means a token needs the scope named after the capability (create_book) or *; resource:* does not cover it. Signed-in people and the command line are unchanged. php caligrafer.php doctor lists such capabilities; TOKEN_DEFAULT_SCOPES=false (deprecated) restores the old rule.
Say the scope and who may call it:
/caligrafy-quill:new-capability list_books books:read read-only public: the catalog, 20 per page
/caligrafy-quill:new-capability delete_book books:write destructive: only administrators (level 1)
Check before you say OK:
-
php caligrafer.php capabilitiesshowspublic, the scope, orsigned in(no scope) in the second column; -
php caligrafer.php call <name> --guestanswersunauthenticatedfor a capability that is not public; - a token without the scope gets
403over REST and does not see the tool in MCPtools/list.
#[Capability(name: 'list_books', description: 'Lists the books of the catalog, 20 per page.', readOnly: true, public: true)]
#[Capability(name: 'create_book', description: 'Adds a book to the catalog and returns it.', scope: 'books:write')]
#[Capability(name: 'delete_book', description: 'Deletes a book for good. Returns its id.', scope: 'books:write', level: 1, destructive: true)](one attribute per class). Then try each caller:
php caligrafer.php call create_book title=Dawn published_year=1987 author_id=2 --guest # unauthenticated
php caligrafer.php token create "Reader" --scopes books:read
php caligrafer.php call create_book title=Dawn published_year=1987 author_id=2 --token cq_... # forbiddenThe second call answers {"error":{"code":"forbidden","message":"This needs the scope books:write"}}; with a level
the message ends with and permission level 1.
Capabilities::call():
-
Find it: no such name, or a
webOnlycapability reached by anything butRoute::action, isnot_found. -
public: true: no check at all; anyone may call it, visitors included. -
Someone must act: a guest (nobody signed in, no token) is
unauthenticated(401). -
$context->allows($scope, $level), elseforbidden(403). - Then the inputs are validated and
handle()runs. A capability can still refuse more itself, withServiceError::forbidden()(Refusing a call).
A scope is <resource>:<action>: lowercase letters, digits, _, . and - on each side (books:read,
books:write). The scopes a token was given cover a required scope when one of them is:
- the same scope (
books:write); -
<resource>:*(books:*coversbooks:readandbooks:write); -
*(everything).
scope: '' is met by any token. Scopes apply to tokens only: a signed-in person has every scope, and is checked by
the level.
level is the minimum value of the users' permissions column (Context::$levelAttribute, permissions by default).
0, the default, means anyone signed in. $context->level() is the user's value, 0 without a user.
| Caller | What allows($scope, $level) checks |
|---|---|
the command line, scripts and jobs (Context::cli(), Context::system()), the legacy API key |
nothing: always allowed |
| a signed-in person | permissions >= level |
a token with an owner (token create ... --user 7) |
the scope, and the owner's permissions >= level
|
| a token without an owner | the scope only: the level does not apply |
| a token whose owner was deleted (with authentication on) | refused |
| a guest | refused (only public capabilities) |
public: true skips the checks: a visitor's page, a REST call without a token and any MCP token reach it. Use it for
what anyone may read (the catalog), or for what a visitor must do before having an account. A public capability may still
look at $context and refuse: the framework's register_user is public but refuses every channel but web pages and the
command line (G81).
Capabilities::available($context) keeps the capabilities this caller may call (public, or allowed), web-only ones left
out. MCP tools/list and GET /capabilities show only those, so a token never sees a tool it may not call.
Reference: Context::allows(),
Tokens::allows(),
Capabilities::available().
-
servicewithout--scope(G76):scope: ''lets any token call it. -
Trusting the level with an application token (G53): a token without
--userpasses any level. Create agent tokens with--user <id>when the level matters. - The legacy API key and tokens without an owner never manage users (G85): the user capabilities need a real administrator, so give an agent that manages users a token of an administrator.
Caligrafy: Describe it. Approve it. Ship it. Your idea turned into a complete app: every feature built once, for web pages, Vue apps, a REST API and AI agents, and online.
Why Caligrafy: the benefits, the measurements, and what it is not yet
-
Quickstart with Claude: describe it, approve it, ship it
or the Quickstart: the same three steps by hand, in 5 minutes
- How Caligrafy works: the ideas in 5 minutes
- Your first capability: build a feature, page included
-
Capabilities in depth
-
#[Capability]: every option - Scheduled jobs: capabilities on a timer
- Notifications: web push and email
- Background jobs: capabilities run later
- Migrations: database changes, in order
- The cache
-
Testing your app
- Dependency injection
- Validation rules
-
Web pages
- Views and page components
- Design styles: another look, one setting
- Declarative routes: every request, in one line
-
Route::page·Route::form·Route::auth·Route::webhook·Route::download·Route::redirect·Route::action·Route::snap· capability routes - How to export a list as CSV
- Controllers: moving one to a declared route · how to, step by step
- Forms and helpers
-
Vue apps
-
Mobile and tablet
-
REST API
-
AI agents
-
Snap Cards and the assistant
- Payments: Stripe and crypto
- Face detection and face login
- OpenAI: chat and images · Assistants
- Open models: Llama, Mistral...
- Chatbots with Watson
- Machine learning in the browser
- Phone and tablet apps: iOS and Android
- Languages: translations, right to left
- Metadata and social cards · search and analytics
-
Putting it online: the production image, the database at every start
-
API reference: every class and method
-
Routing ·
Route·AuthRoutes· pages ·Controller· capabilities -
Data ·
Model·Query· sign-in · jobs ·Notify· payments · AI -
Interfaces · Snap ·
Snap\Cards·Snap\Conversation· testing · tooling · helper functions
-
Routing ·
-
Caligrafer: every command
- Project · build · data · agents · jobs and tests · maintenance · deploy
- Installation, configuration and Caligrafer
- Routing · Request · Controllers · Views
- Vue: flow of information · routes · validations
- Security and upgrading
- Release notes: 2.32 · 2.31 · 2.30 · 2.29 · 2.28 · 2.27 · 2.26 · 2.25 · 2.24 · 2.23 · 2.22 · 2.21 · 2.20 · 2.19 · 2.18 · 2.17 · 2.16 · 2.15 · 2.14 · 2.13 · 2.12 · 2.11 · 2.10 · 2.9 · 2.8 · 2.7 · 2.6 · 2.5 · 2.4 · 2.3 · 2.1 · October 2026 · changelog
- Testing Caligrafy (contributors)