Skip to content
docsv0.2.0

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

Parameters of __construct()
NameTypeDescription
$principal?string
$channelstring
$scopesarray<string>
$request_id?string
$ip?string
$userAgent?string
$extraarray<string, mixed>
$modestring

ToolContext::asPlan()

public function asPlan(): self

Clone this context in plan mode (dry-run). Plan mode validates and authorizes but does NOT execute the tool callback.

ToolContext::isPlanMode()

public function isPlanMode(): bool

Check if context is in plan mode.

ToolContext::isExecuteMode()

public function isExecuteMode(): bool

Check if context is in execute mode.

ToolContext::hasScope()

public function hasScope(string $scope): bool

Check if context has a specific scope.

Parameters

Parameters of hasScope()
NameTypeDescription
$scopestring

ToolContext::hasAnyScope()

public function hasAnyScope(array $scopes): bool

Check if context has any of the given scopes.

Parameters

Parameters of hasAnyScope()
NameTypeDescription
$scopesarray<string>

ToolContext::hasAllScopes()

public function hasAllScopes(array $scopes): bool

Check if context has all of the given scopes.

Parameters

Parameters of hasAllScopes()
NameTypeDescription
$scopesarray<string>

ToolContext::cli()

public static function cli(?string $requestId = null, string $mode = 'execute'): self

Create context for CLI usage (full access).

Parameters

Parameters of cli()
NameTypeDescription
$requestId(string | null)Optional request ID
$modestringExecution mode: 'execute' or 'plan'

ToolContext::mcp()

Deprecated
public static function mcp(string $requestId, ?string $principal = null, array $scopes = [], string $mode = 'execute'): self

Create context for MCP server.

Deprecated: Calling without explicit scopes is deprecated and will be removed in v2.0

Parameters

Parameters of mcp()
NameTypeDescription
$requestIdstringThe MCP request ID
$principal(string | null)The authenticated principal (user/service)
$scopesarray<string>Explicit scopes granted to this context
$modestringExecution mode: 'execute' or 'plan'

ToolContext::telegram()

public static function telegram(string $chatId, ?string $userId = null, string $mode = 'execute'): self

Create context for Telegram.

Parameters

Parameters of telegram()
NameTypeDescription
$chatIdstringTelegram chat ID
$userId(string | null)Telegram user ID
$modestringExecution mode: 'execute' or 'plan'

ToolContext::toArray()

public function toArray(): array

Serialize this context to a plain array for logging or transport.