ScopePolicy
Declares which scopes a request needs, enforced by {@see \Mcp\Server\Transport\Http\Middleware\AuthorizationMiddleware}.
A request needs the default scopes, plus those of its JSON-RPC method, plus —
for tools/call — those of the tool it calls. A token lacking any of them is
answered with 403 insufficient_scope naming every scope the request needs, so
the client can step up in one go.
Tags
Table of Contents
Properties
- $default : array<int, string>
- $implies : array<string, array<int, string>>
- $methods : array<string, array<int, string>>
- $tools : array<string, array<int, string>>
Methods
- __construct() : mixed
- expand() : array<int, string>
- The granted scopes plus all scopes they imply through the hierarchy.
- inspectsBody() : bool
- Whether the policy depends on the request body, i.e. on methods or tools.
- requiredFor() : array<int, string>
- Scopes the decoded JSON-RPC message needs; anything but a message means only the defaults.
- normalizeMap() : array<string, array<int, string>>
Properties
$default read-only
private
array<int, string>
$default
$implies read-only
private
array<string, array<int, string>>
$implies
$methods read-only
private
array<string, array<int, string>>
$methods
$tools read-only
private
array<string, array<int, string>>
$tools
Methods
__construct()
public
__construct([array<int, string> $default = [] ][, array<string, array<int, string>> $methods = [] ][, array<string, array<int, string>> $tools = [] ][, array<string, array<int, string>> $implies = [] ]) : mixed
Parameters
- $default : array<int, string> = []
-
scopes every request needs
- $methods : array<string, array<int, string>> = []
-
scopes per JSON-RPC method, e.g.
['tools/call' => ['mcp:tools']] - $tools : array<string, array<int, string>> = []
-
scopes per tool name, e.g.
['delete_file' => ['files:write']] - $implies : array<string, array<int, string>> = []
-
scope hierarchy: a granted key also grants its listed scopes, e.g.
['files:admin' => ['files:write']]
expand()
The granted scopes plus all scopes they imply through the hierarchy.
public
expand(array<int, string> $granted) : array<int, string>
Parameters
- $granted : array<int, string>
Return values
array<int, string>inspectsBody()
Whether the policy depends on the request body, i.e. on methods or tools.
public
inspectsBody() : bool
Return values
boolrequiredFor()
Scopes the decoded JSON-RPC message needs; anything but a message means only the defaults.
public
requiredFor([mixed $message = null ]) : array<int, string>
Parameters
- $message : mixed = null
Return values
array<int, string>normalizeMap()
private
static normalizeMap(array<string|int, mixed> $map) : array<string, array<int, string>>
Parameters
- $map : array<string|int, mixed>