PHP code example of rasuvaeff / yii3-mcp-rbac-bridge
1. Go to this page and download the library: Download rasuvaeff/yii3-mcp-rbac-bridge library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Rasuvaeff\Yii3McpRbacBridge\RequiredPermission;
final readonly class OrderTools
{
#[McpTool(name: 'order.status')]
#[RequiredPermission('orders.view')]
public function status(string $orderId): string { ... }
#[McpTool(name: 'ping')] // no attribute = unrestricted
public function ping(): string { ... }
}
new PermissionMap(['RefundTool' => 'orders.refund']); // invokable RefundTool::__invoke
// config/common/di/mcp-rbac.php
use Rasuvaeff\Yii3McpRbacBridge\ {
CurrentUserIdentitySource, IdentitySourceInterface, PermissionMap,
};
return [
IdentitySourceInterface::class => CurrentUserIdentitySource::class,
PermissionMap::class => static fn () => PermissionMap::fromToolClasses(
[OrderTools::class], // same list as the `tools` params
// ['order.status' => 'orders.admin'], // optional explicit overrides
),
];