ToolContext
Context for tool execution. Contains information about who/where/what permissions for authorization.
ToolContext::__construct()
public function __construct(?string $principal = null, string $channel = 'unknown', array $scopes = [], ?string $request_id = null, ?string $ip = null, ?string $userAgent = null, array $extra = [], string $mode = 'execute'):Parameters
| Name | Type | Description |
|---|---|---|
| $principal | ?string | |
| $channel | string | |
| $scopes | array<string> | |
| $request_id | ?string | |
| $ip | ?string | |
| $userAgent | ?string | |
| $extra | array<string, mixed> | |
| $mode | string |
ToolContext::asPlan()
public function asPlan(): selfClone this context in plan mode (dry-run). Plan mode validates and authorizes but does NOT execute the tool callback.
ToolContext::isPlanMode()
public function isPlanMode(): boolCheck if context is in plan mode.
ToolContext::isExecuteMode()
public function isExecuteMode(): boolCheck if context is in execute mode.
ToolContext::hasScope()
public function hasScope(string $scope): boolCheck if context has a specific scope.
Parameters
| Name | Type | Description |
|---|---|---|
| $scope | string |
ToolContext::hasAnyScope()
public function hasAnyScope(array $scopes): boolCheck if context has any of the given scopes.
Parameters
| Name | Type | Description |
|---|---|---|
| $scopes | array<string> |
ToolContext::hasAllScopes()
public function hasAllScopes(array $scopes): boolCheck if context has all of the given scopes.
Parameters
| Name | Type | Description |
|---|---|---|
| $scopes | array<string> |
ToolContext::cli()
public static function cli(?string $requestId = null, string $mode = 'execute'): selfCreate context for CLI usage (full access).
Parameters
| Name | Type | Description |
|---|---|---|
| $requestId | (string | null) | Optional request ID |
| $mode | string | Execution mode: 'execute' or 'plan' |
ToolContext::mcp()
public static function mcp(string $requestId, ?string $principal = null, array $scopes = [], string $mode = 'execute'): selfCreate context for MCP server.
Deprecated: Calling without explicit scopes is deprecated and will be removed in v2.0
Parameters
| Name | Type | Description |
|---|---|---|
| $requestId | string | The MCP request ID |
| $principal | (string | null) | The authenticated principal (user/service) |
| $scopes | array<string> | Explicit scopes granted to this context |
| $mode | string | Execution mode: 'execute' or 'plan' |
ToolContext::telegram()
public static function telegram(string $chatId, ?string $userId = null, string $mode = 'execute'): selfCreate context for Telegram.
Parameters
| Name | Type | Description |
|---|---|---|
| $chatId | string | Telegram chat ID |
| $userId | (string | null) | Telegram user ID |
| $mode | string | Execution mode: 'execute' or 'plan' |
ToolContext::toArray()
public function toArray(): arraySerialize this context to a plain array for logging or transport.