Scope grammar
A scope is a compact declarative statement of the form:
<product>:<verb>(<constraint-list>)
Scopes are the protocol's contract for "what may this agent do, and on what terms." They are parseable, comparable, and composable across orangecheck sub-products.
ShapeLink to this section
scope := product ":" verb [ "(" constraint-list ")" ]
product := lowercase-ident
verb := lowercase-ident
constraint-list := constraint ( "," constraint )*
constraint := key op value
key := lowercase-ident
op := "=" | "!=" | "<" | "<=" | ">" | ">=" | "*"
value := quoted-string | bare-token
No whitespace is permitted inside a scope string. * is the wildcard op and
takes no value. A bare token is made of A-Z a-z 0-9 _ . : / @ + -; any other
character, such as ?, % or ~, needs a quoted string:
mcp:invoke(server="https://example.com/mcp?v=2",tool=search).
MVP scope registryLink to this section
Implementations MUST accept these products and verbs.
| Scope | Registered keys |
|---|---|
lock: | recipient, mime, max_ |
lock: | recipient, max_, max_ |
stamp: | mime, max_, content_ |
vote: | poll_, choice |
nostr: | kind, relay, max_ |
http: | origin, method, max_, max_ |
ln: | max_, node, max_ |
mcp: | server, tool, max_ |
pledge: | max_, mechanism, counterparty |
anthropic: | name (case-sensitive), from agent- |
openai: | name (case-sensitive), from agent- |
vercel: | verb (case-sensitive), from agent- |
langgraph: | verb (case-sensitive), from agent- |
In strict mode (default), verifiers reject unknown products / verbs /
constraint keys. In permissive mode, verifiers accept unknowns and still
apply them: an unknown key in a granted scope is a constraint like any other, so
an exercised scope must meet it. Neither mode drops a constraint or reads one as
a wildcard. OC Pledge refuses an unknown pledge:create key in both modes.
Canonical formLink to this section
To make sub-scope comparison deterministic, scopes are canonicalized before use:
- Constraints sorted lexicographically by key.
- Values kept exactly as written, case included, and compared byte for byte.
- No whitespace.
- Typed values have one spelling, in ASCII: an integer key (
kind, themax_*keys) takes a decimal integer;methodan ASCII token with no lower-case letter;node,poll_idandcontent_hash_prefixlower-case hex;mimea lower-case type/subtype with no parameters; a bech32 address (bc1…,tb1…,bcrt1…) lower case, while a base58 address keeps its case; a URL (origin,server,relay) no backslash and a lower-case scheme and authority, its path as written. Any other value makes the scope malformed (E_BAD_SCOPE_GRAMMAR) in either mode. - A registered prefix key,
content_hash_prefixofstamp:sign, is written with=, meaning "starts with";!=on it is malformed in either mode. A key is a prefix key by registration, not by its name.
ln:send(node=03abc,max_sats<=1000) canonicalizes to
ln:send(max_sats<=1000,node=03abc). The canonical form is what gets written to
scopes and scope_exercised.
Sub-scope containmentLink to this section
An exercised scope S_x is a sub-scope of a granted scope S_g iff:
productandverbare identical.- For every constraint
(k, op, v)inS_g:op = *— no requirement onS_x.op = =—S_xmust contain(k, =, v)exactly. The prefix keycontent_hash_prefixmeans "starts with":=abcmeets=ab.op = !=—S_xmust contain a value that isn'tv(via=or another!=). Integer keys compare as integers, sokind=00is still0. Other values compare byte for byte: for a key whose values can still be spelled two ways, such as a URL with and without its default port, grant with=.- Ordered ops (
<,<=,>,>=) —S_x's implied numeric range must be a subset ofS_g's.
S_xmay add constraints on keys not present inS_g, as long as they're registered for thatproduct:verb.
Keys read from the contentLink to this section
For stamp:sign, three keys describe the action's own content, so a verifier
reads them from the signed content and never from the agent's claim: mime
from content.mime (its type/subtype, lower case), max_bytes from
content.length, and content_hash_prefix from the hex of content.hash.
Those values must meet the grant that admits scope_exercised, else
E_SCOPE_DENIED; agent-signer refuses to sign content its own claim does not
cover. No other registered scope has a key the action's signed fields describe:
a recipient, poll, kind or tool sits inside the content bytes, and the product's
own verifier reads it there.
ExamplesLink to this section
| Granted | Exercised | Result |
|---|---|---|
lock: | lock: | ✓ exact match |
ln: | ln: | ✓ tighter bound + extra key |
stamp: | stamp: | ✗ = value mismatch |
http: | http: | ✗ = value mismatch |
http: | http: | ✓ admissible under != |
http: | http: | ✗ disallowed under != |
http: | http: | ✗ malformed method |
stamp: | stamp: | ✗ MIME parameters |
stamp: | stamp: | ✓ starts with ab |
nostr: | nostr: | ✗ 00 is 0 |
ln: | ln: | ✗ wider range |
http: | http: | ✓ wildcard grants everything |
WildcardsLink to this section
A delegation MAY grant product:verb(key=*) to express "any value for key."
Wildcards widen — use them deliberately. The blanket grant is the scope with no
constraint list, http:request: maximally permissive, and verifiers MAY reject
such delegations by policy. A constraint always names a key, so
http:request(*) is not a scope string.
Adding new scopesLink to this section
New products, verbs, and constraint keys are allocated by PR to the
oc-agent-protocol (opens in a new tab)
repository. Each name is a lowercase identifier ([a-z][a-z0-9_]*). Until a
name is registered, strict-mode verifiers refuse it.
Implementing the sub-scope checkLink to this section
The reference TypeScript implementation lives in
@orangecheck/agent-core (opens in a new tab):
import { isSubScope, parseScope } from '@orangecheck/agent-core';
const granted = parseScope('ln:send(max_sats<=1000,node=03abc)');
const exercised = parseScope('ln:send(max_sats=500,node=03abc,max_fee_sats=5)');
if (!isSubScope(exercised, granted)) {
throw new Error('scope escalation attempt');
}
The algorithm is pure and deterministic — same inputs on any compliant implementation yield the same accept/reject.