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
+225Lines changed: 225 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -180,6 +180,7 @@ The MCP integration respects your existing Restify configuration and adds MCP-sp
180
180
'server_name' => 'My App MCP Server',
181
181
'server_version' => '1.0.0',
182
182
'default_pagination' => 25,
183
+
'mode' => env('RESTIFY_MCP_MODE', 'direct'), // 'direct' or 'wrapper'
183
184
'tools' => [
184
185
'exclude' => [
185
186
// Tools to exclude from discovery
@@ -190,3 +191,227 @@ The MCP integration respects your existing Restify configuration and adds MCP-sp
190
191
],
191
192
],
192
193
```
194
+
195
+
## MCP Mode: Direct vs Wrapper
196
+
197
+
Laravel Restify offers two modes for exposing your repositories through MCP: **Direct Mode** and **Wrapper Mode**. Each mode has different trade-offs in terms of token usage and discoverability.
198
+
199
+
### Direct Mode (Default)
200
+
201
+
In direct mode, every repository operation (index, show, store, update, delete) and custom action/getter is exposed as a separate MCP tool. This provides maximum discoverability for AI agents.
202
+
203
+
**When to use Direct Mode:**
204
+
- You have a small number of repositories (< 10)
205
+
- You want AI agents to instantly see all available operations
206
+
- Token usage is not a concern
207
+
- You prefer simpler, more straightforward tool discovery
208
+
209
+
**Example:** With 10 repositories, each having 5 CRUD operations plus 2 actions, you would expose **70 tools** to the AI agent.
210
+
211
+
**Configuration:**
212
+
```php
213
+
// .env
214
+
RESTIFY_MCP_MODE=direct
215
+
```
216
+
217
+
### Wrapper Mode (Token-Efficient)
218
+
219
+
Wrapper mode uses a progressive discovery pattern that exposes only **4 wrapper tools** regardless of how many repositories you have. AI agents discover and execute operations through a multi-step workflow.
220
+
221
+
**When to use Wrapper Mode:**
222
+
- You have many repositories (10+)
223
+
- Token usage efficiency is important (e.g., working with large context windows)
224
+
- You want to reduce the initial tool list size
225
+
- You're building complex applications with dozens of repositories
226
+
227
+
**Token Savings Example:**
228
+
- Direct mode with 50 repositories: ~250+ tools exposed
229
+
- Wrapper mode with 50 repositories: **4 tools exposed**
230
+
-**Token reduction: ~98% fewer tokens used for tool definitions**
231
+
232
+
**Configuration:**
233
+
```php
234
+
// .env
235
+
RESTIFY_MCP_MODE=wrapper
236
+
```
237
+
238
+
### The 4 Wrapper Tools
239
+
240
+
When using wrapper mode, AI agents use these 4 tools in a progressive discovery workflow:
241
+
242
+
#### 1. `discover-repositories`
243
+
Lists all available MCP-enabled repositories with metadata. Supports optional search filtering.
Returns the complete JSON schema and documentation for a specific operation, including all parameters, validation rules, and examples.
304
+
305
+
**Example Request:**
306
+
```json
307
+
{
308
+
"repository": "users",
309
+
"operation_type": "store"
310
+
}
311
+
```
312
+
313
+
**Example Response:**
314
+
```json
315
+
{
316
+
"success": true,
317
+
"operation": "store",
318
+
"type": "create",
319
+
"title": "Create User",
320
+
"description": "Create a new user account",
321
+
"schema": {
322
+
"type": "object",
323
+
"properties": {
324
+
"name": {
325
+
"type": "string",
326
+
"description": "The user's full name",
327
+
"required": true
328
+
},
329
+
"email": {
330
+
"type": "string",
331
+
"description": "The user's email address",
332
+
"required": true
333
+
}
334
+
}
335
+
},
336
+
"examples": [
337
+
{
338
+
"name": "John Doe",
339
+
"email": "john@example.com"
340
+
}
341
+
]
342
+
}
343
+
```
344
+
345
+
#### 4. `execute-operation`
346
+
Executes a repository operation with the provided parameters. This is the final step after discovering the repository, listing operations, and getting operation details.
347
+
348
+
**Example Request:**
349
+
```json
350
+
{
351
+
"repository": "users",
352
+
"operation_type": "store",
353
+
"parameters": {
354
+
"name": "John Doe",
355
+
"email": "john@example.com"
356
+
}
357
+
}
358
+
```
359
+
360
+
**Example Response:**
361
+
```json
362
+
{
363
+
"success": true,
364
+
"data": {
365
+
"id": 123,
366
+
"name": "John Doe",
367
+
"email": "john@example.com"
368
+
}
369
+
}
370
+
```
371
+
372
+
### Wrapper Mode Workflow
373
+
374
+
Here's a typical workflow when an AI agent uses wrapper mode:
375
+
376
+
1.**Discover repositories**: Agent calls `discover-repositories` to see what repositories are available
377
+
2.**Explore operations**: Agent calls `get-repository-operations` for the target repository
378
+
3.**Get schema**: Agent calls `get-operation-details` to understand required parameters
379
+
4.**Execute**: Agent calls `execute-operation` with the correct parameters
380
+
381
+
This progressive discovery pattern reduces token usage while maintaining full functionality.
382
+
383
+
### Switching Between Modes
384
+
385
+
You can switch between modes at any time by updating your `.env` file:
386
+
387
+
```bash
388
+
# Direct mode (default)
389
+
RESTIFY_MCP_MODE=direct
390
+
391
+
# Wrapper mode (token-efficient)
392
+
RESTIFY_MCP_MODE=wrapper
393
+
```
394
+
395
+
No code changes are required. The MCP server automatically adapts to the configured mode.
0 commit comments