Skip to content

Commit 8b51af8

Browse files
committed
feat: mcp support
1 parent 47c8863 commit 8b51af8

File tree

25 files changed

+3483
-29
lines changed

25 files changed

+3483
-29
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
}
1919
],
2020
"require": {
21-
"php": "^8.2",
21+
"php": "^8.2|^8.3",
2222
"illuminate/contracts": "^11.0|^12.0",
2323
"laravel/pint": "^1.0",
24+
"laravel/mcp": "^0.1.0",
2425
"spatie/laravel-data": "^4.4",
2526
"spatie/laravel-package-tools": "^1.12",
2627
"spatie/once": "^3.0"

config/restify.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,4 +175,42 @@
175175
*/
176176
'max_tokens' => 1000,
177177
],
178+
179+
/*
180+
|--------------------------------------------------------------------------
181+
| Model Context Protocol (MCP)
182+
|--------------------------------------------------------------------------
183+
|
184+
| These settings control the MCP integration that allows AI agents to
185+
| interact with your Restify repositories through structured tool interfaces.
186+
|
187+
*/
188+
'mcp' => [
189+
'tools' => [
190+
'exclude' => [
191+
// Tool classes to exclude from discovery
192+
// 'App\MCP\Tools\SensitiveTool',
193+
],
194+
'include' => [
195+
// Additional tool classes to include
196+
// 'App\MCP\Tools\CustomTool',
197+
],
198+
],
199+
'resources' => [
200+
'exclude' => [
201+
// Resource classes to exclude from discovery
202+
],
203+
'include' => [
204+
// Additional resource classes to include
205+
],
206+
],
207+
'prompts' => [
208+
'exclude' => [
209+
// Prompt classes to exclude from discovery
210+
],
211+
'include' => [
212+
// Additional prompt classes to include
213+
],
214+
],
215+
],
178216
];

docs-v2/content/en/api/fields.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,49 @@ However, you can populate the field value when the entity is stored by using `va
407407
Field::new('token')->value(Str::random(32))->hidden();
408408
```
409409

410+
### MCP Visibility Control
411+
412+
When using Laravel Restify with Model Context Protocol (MCP), you can control field visibility specifically for MCP requests using dedicated methods:
413+
414+
```php
415+
// Hide field from MCP requests completely
416+
Field::new('secret_key')->hideFromMcp()
417+
418+
// Show field only in MCP requests (hide from regular API)
419+
Field::new('mcp_metadata')->showOnIndex(false)->showOnShow(false)->showOnMcp(true)
420+
421+
// Conditionally hide based on user permissions
422+
Field::new('admin_notes')->hideFromMcp(function($request, $repository) {
423+
return !$request->user()->isAdmin();
424+
})
425+
426+
// Show field in MCP based on user role
427+
Field::new('sensitive_data')->showOnMcp(function($request, $repository) {
428+
return $request->user()->can('view-sensitive', $repository);
429+
})
430+
```
431+
432+
#### MCP Visibility Methods
433+
434+
- **`showOnMcp($callback = true)`** - Control whether the field should be visible in MCP requests
435+
- **`hideFromMcp($callback = true)`** - Hide the field from MCP requests (inverse of showOnMcp)
436+
437+
Both methods accept either a boolean value or a callback function that receives the request and repository as parameters.
438+
439+
<alert type="info">
440+
MCP visibility rules take precedence over regular `showOnIndex`/`showOnShow` rules when processing MCP requests. Fields are visible in MCP by default unless explicitly hidden.
441+
</alert>
442+
443+
#### How It Works
444+
445+
The MCP visibility system automatically detects when a request is coming from an MCP tool and applies the appropriate visibility rules:
446+
447+
1. **Regular API requests** use `showOnIndex()` and `showOnShow()` rules
448+
2. **MCP requests** use `showOnMcp()` and `hideFromMcp()` rules
449+
3. **Default behavior** - fields are visible in MCP unless explicitly hidden
450+
451+
This allows you to have different field visibility for your regular API consumers versus AI agents accessing your data through MCP tools.
452+
410453
## Hooks
411454

412455
### After store

0 commit comments

Comments
 (0)