Skip to content

Commit a313a59

Browse files
committed
Merge branch 'feat/mcp-support' of github.com:BinarCode/laravel-restify into feat/mcp-support
2 parents 5d37baa + 763056e commit a313a59

17 files changed

+32
-47
lines changed

src/Filters/MatchFilter.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use Binaryk\LaravelRestify\Contracts\RestifySearchable;
66
use Binaryk\LaravelRestify\Http\Requests\RestifyRequest;
7-
use Binaryk\LaravelRestify\MCP\Concerns\FieldMcpSchemaDetection;
87
use Closure;
98
use Illuminate\Database\Eloquent\Builder;
109
use Illuminate\Database\Eloquent\Relations\Relation;

src/Filters/SearchablesCollection.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Binaryk\LaravelRestify\Filters;
44

5-
use Binaryk\LaravelRestify\Http\Requests\RestifyRequest;
65
use Binaryk\LaravelRestify\Repositories\Repository;
76
use Illuminate\Database\Eloquent\Model;
87
use Illuminate\Support\Collection;
@@ -43,7 +42,7 @@ public function __construct($items = [])
4342
*/
4443
public function fieldNames(): array
4544
{
46-
return $this->filter(fn($item) => is_string($item) && !empty($item))
45+
return $this->filter(fn ($item) => is_string($item) && ! empty($item))
4746
->unique()
4847
->values()
4948
->toArray();
@@ -55,7 +54,7 @@ public function fieldNames(): array
5554
public function formatForDocumentation(): string
5655
{
5756
$fields = $this->fieldNames();
58-
57+
5958
if (empty($fields)) {
6059
return 'No searchable fields available';
6160
}
@@ -76,10 +75,10 @@ public function forSearch(Model $model, Repository $repository): Collection
7675

7776
// Create SearchableFilter for string fields
7877
$columnName = is_numeric($key) ? $searchable : $key;
79-
78+
8079
return SearchableFilter::make()
8180
->setColumn($model->qualifyColumn($columnName))
8281
->setRepository($repository);
8382
});
8483
}
85-
}
84+
}

src/MCP/Concerns/McpActionTool.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
namespace Binaryk\LaravelRestify\MCP\Concerns;
44

55
use Binaryk\LaravelRestify\Actions\Action;
6-
use Binaryk\LaravelRestify\Http\Requests\ActionRequest;
76
use Binaryk\LaravelRestify\MCP\Requests\McpActionRequest;
8-
use Binaryk\LaravelRestify\MCP\Requests\McpRequest;
97
use Laravel\Mcp\Server\Tools\ToolInputSchema;
108

119
/**
@@ -20,17 +18,16 @@ public function actionTool(Action $action, array $arguments, McpActionRequest $a
2018
$this->sanitizeToolRequest($actionRequest, $arguments);
2119

2220
if ($id = $actionRequest->input('id')) {
23-
if (!$action->authorizedToRun($actionRequest, $actionRequest->findModelOrFail($id))) {
21+
if (! $action->authorizedToRun($actionRequest, $actionRequest->findModelOrFail($id))) {
2422
return [
2523
'error' => 'Not authorized to run this action',
2624
'getter' => $action->uriKey(),
2725
];
2826
}
2927
}
3028

31-
3229
// Set up the action request context based on action type
33-
if (!$action->isStandalone()) {
30+
if (! $action->isStandalone()) {
3431
if (isset($arguments['id'])) {
3532
// Single model action (show context)
3633
$actionRequest->merge(['id' => $arguments['id']]);
@@ -41,7 +38,7 @@ public function actionTool(Action $action, array $arguments, McpActionRequest $a
4138
}
4239

4340
// Check authorization
44-
if (!$action->authorizedToSee($actionRequest)) {
41+
if (! $action->authorizedToSee($actionRequest)) {
4542
return [
4643
'error' => 'Not authorized to see this action',
4744
'action' => $action->uriKey(),
@@ -102,7 +99,7 @@ public static function actionToolSchema(Action $action, ToolInputSchema $schema,
10299
$shownOnShow = $action->isShownOnShow($mcpRequest, app(static::class));
103100
$shownOnIndex = $action->isShownOnIndex($mcpRequest, app(static::class));
104101

105-
if ($shownOnShow && !$shownOnIndex) {
102+
if ($shownOnShow && ! $shownOnIndex) {
106103
// Show action - requires single ID
107104
$schema->string('id')
108105
->description("The ID of the {$modelName} to perform the action on")

src/MCP/Concerns/McpDestroyTool.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ public static function destroyToolSchema(ToolInputSchema $schema): void
3131
->description("The ID of the $modelName to delete")
3232
->required();
3333
}
34-
}
34+
}

src/MCP/Concerns/McpGetterTool.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
namespace Binaryk\LaravelRestify\MCP\Concerns;
44

55
use Binaryk\LaravelRestify\Getters\Getter;
6-
use Binaryk\LaravelRestify\Http\Requests\GetterRequest;
76
use Binaryk\LaravelRestify\MCP\Requests\McpGetterRequest;
8-
use Binaryk\LaravelRestify\MCP\Requests\McpRequest;
97
use Illuminate\Http\JsonResponse;
108
use Laravel\Mcp\Server\Tools\ToolInputSchema;
119

@@ -21,7 +19,7 @@ public function getterTool(Getter $getter, array $arguments, McpGetterRequest $g
2119
$this->sanitizeToolRequest($getterRequest, $arguments);
2220

2321
if ($id = $getterRequest->input('id')) {
24-
if (!$getter->authorizedToRun($getterRequest, $getterRequest->findModelOrFail($id))) {
22+
if (! $getter->authorizedToRun($getterRequest, $getterRequest->findModelOrFail($id))) {
2523
return [
2624
'error' => 'Not authorized to run this getter',
2725
'getter' => $getter->uriKey(),
@@ -84,7 +82,7 @@ public static function getterToolSchema(Getter $getter, ToolInputSchema $schema,
8482
$shownOnShow = $getter->isShownOnShow($mcpRequest, app(static::class));
8583
$shownOnIndex = $getter->isShownOnIndex($mcpRequest, app(static::class));
8684

87-
if ($shownOnShow && !$shownOnIndex) {
85+
if ($shownOnShow && ! $shownOnIndex) {
8886
// Show getter - requires single ID
8987
$schema->string('id')
9088
->description("The ID of the {$modelName} to execute the getter on")

src/MCP/Concerns/McpIndexTool.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use Binaryk\LaravelRestify\Filters\MatchesCollection;
77
use Binaryk\LaravelRestify\Filters\MatchFilter;
88
use Binaryk\LaravelRestify\Filters\SearchablesCollection;
9-
use Binaryk\LaravelRestify\Http\Requests\RestifyRequest;
109
use Binaryk\LaravelRestify\MCP\Requests\McpRequest;
1110
use Laravel\Mcp\Server\Tools\ToolInputSchema;
1211

@@ -57,7 +56,7 @@ public static function indexToolSchema(ToolInputSchema $schema): void
5756

5857
$schema->string('sort')
5958
->description("Sorting criteria for the $key. Available options: ".implode(', ',
60-
$sortOptions).' (e.g., sort=field or sort=-field for descending)');
59+
$sortOptions).' (e.g., sort=field or sort=-field for descending)');
6160

6261
MatchesCollection::make(static::matches())
6362
->normalize()

src/MCP/Concerns/McpShowTool.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ public static function showToolSchema(ToolInputSchema $schema): void
4545
$schema->string('include')
4646
->description(static::formatRelationshipDocumentation());
4747
}
48-
}
48+
}

src/MCP/Concerns/McpStoreTool.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ public static function storeToolSchema(ToolInputSchema $schema): void
3030
$field->resolveToolSchema($schema, $repository);
3131
});
3232
}
33-
}
33+
}

src/MCP/Concerns/McpToolHelpers.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ protected static function getRelationshipFields(string $repositoryClass): array
3333
// This will call fieldsForMcpIndex if available, providing accurate MCP field documentation
3434
$fields = $repository->collectFields($request)
3535
->forMcpIndex($request, $repository)
36-
->map(fn($field) => $field->attribute)
36+
->map(fn ($field) => $field->attribute)
3737
->unique()
3838
->sort()
3939
->values()
@@ -92,9 +92,9 @@ protected static function formatRelationshipDocumentation(): string
9292
$firstFields = static::getRelationshipFields($firstRepositoryClass);
9393
$exampleFields = array_slice($firstFields, 0, 2);
9494

95-
if (!empty($exampleFields)) {
96-
$documentation .= "- include={$firstRelationName}[" . implode(',', $exampleFields) . "] (selective fields with comma syntax)\n";
97-
$documentation .= "- include={$firstRelationName}[" . implode('|', $exampleFields) . "] (selective fields with pipe syntax)\n";
95+
if (! empty($exampleFields)) {
96+
$documentation .= "- include={$firstRelationName}[".implode(',', $exampleFields)."] (selective fields with comma syntax)\n";
97+
$documentation .= "- include={$firstRelationName}[".implode('|', $exampleFields)."] (selective fields with pipe syntax)\n";
9898
}
9999

100100
// Add comprehensive nested relationship examples based on real test cases
@@ -137,4 +137,4 @@ protected static function extractRepositoryClass($relationConfig): ?string
137137

138138
return null;
139139
}
140-
}
140+
}

src/MCP/Concerns/McpTools.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
*/
88
trait McpTools
99
{
10+
use McpActionTool;
11+
use McpDestroyTool;
12+
use McpGetterTool;
1013
use McpIndexTool;
1114
use McpShowTool;
1215
use McpStoreTool;
13-
use McpUpdateTool;
14-
use McpDestroyTool;
15-
use McpActionTool;
16-
use McpGetterTool;
1716
use McpToolHelpers;
17+
use McpUpdateTool;
1818

1919
public function mcpAllowsIndex(): bool
2020
{

0 commit comments

Comments
 (0)