*/ private array $client_info = array(); public function __construct( \WP_User $user, string $session_id, string $protocol_version = '', string $ip = '' ) { $this->user = $user; $this->session_id = $session_id; $this->protocol_version = $protocol_version; $this->ip = $ip; } public function user(): \WP_User { return $this->user; } public function user_id(): int { return (int) $this->user->ID; } /** * Capability check for the authenticated user. * * @param string $capability Capability. * @param mixed ...$args Optional context args (e.g. object id). */ public function user_can( string $capability, ...$args ): bool { return user_can( $this->user, $capability, ...$args ); } public function get_session_id(): string { return $this->session_id; } /** * Note that the session id came from the client. */ public function mark_client_session(): void { $this->client_session = true; } /** * Which of this user's connections the call came from: their MCP session * when the client keeps one, so two chats signed in as one account each * have their own progress card; the account alone otherwise. */ public function connection_key(): string { return $this->client_session && '' !== $this->session_id ? $this->user_id() . '_' . substr( md5( $this->session_id ), 0, 16 ) : (string) $this->user_id(); } public function get_protocol_version(): string { return $this->protocol_version; } public function set_protocol_version( string $version ): void { $this->protocol_version = $version; } public function get_ip(): string { return $this->ip; } /** * Mark this context as running a call that a person has approved. * * Only Approval_Runner does this, after the decision was made on the * capability-checked WordPress approval page. Code that applies the * destructive policy inside a tool (the CLI router, abilities) reads it, so * an approved call runs even with "Destructive actions" off — approval * supersedes that switch, exactly as it does for the dedicated tools. */ public function mark_approved(): void { $this->approved = true; } /** * Whether this context is running an approved call. */ public function is_approved(): bool { return $this->approved; } /** * @param array $info Client info. */ public function set_client_info( array $info ): void { $this->client_info = $info; } /** * @return array */ public function get_client_info(): array { return $this->client_info; } }