You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs-v3/content/docs/mcp/mcp.md
+217Lines changed: 217 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -415,3 +415,220 @@ No code changes are required. The MCP server automatically adapts to the configu
415
415
3.**Use wrapper mode** when working with AI agents that have limited context windows
416
416
4.**Monitor token usage** to determine which mode is best for your application
417
417
5.**Document your choice** so team members understand which mode is active
418
+
419
+
## Fine-Grained Tool Permissions
420
+
421
+
Laravel Restify's MCP integration includes a powerful permission system that allows you to control which tools each API token can access. This is essential for multi-tenant applications or when you need to restrict AI agent capabilities.
422
+
423
+
### How Permission Control Works
424
+
425
+
The `RestifyServer` class provides a `canUseTool()` method that is called whenever a tool is accessed. By default, this method returns `true` (all tools are accessible), but you can override it in your application server to implement custom permission logic.
426
+
427
+
**Key Behavior:**
428
+
-`canUseTool()` is called during **tool discovery** (what tools the AI agent sees)
429
+
-`canUseTool()` is called during **tool execution** (whether the operation is allowed)
430
+
- In **wrapper mode**, permissions are checked for individual operations, not just the 4 wrapper tools
431
+
- Tools without permission are completely hidden from the AI agent
432
+
433
+
### Implementing Token-Based Permissions
434
+
435
+
Create a custom MCP server that extends `RestifyServer` and implements permission checks:
436
+
437
+
```php
438
+
<?php
439
+
440
+
namespace App\Mcp;
441
+
442
+
use Binaryk\LaravelRestify\MCP\RestifyServer;
443
+
use App\Models\McpToken;
444
+
445
+
class ApplicationServer extends RestifyServer
446
+
{
447
+
public function canUseTool(string|object $tool): bool
0 commit comments