|
11 | 11 | use Binaryk\LaravelRestify\Fields\MorphToMany; |
12 | 12 | use Binaryk\LaravelRestify\Filters\SortableFilter; |
13 | 13 | use Binaryk\LaravelRestify\Http\Requests\RestifyRequest; |
| 14 | +use Binaryk\LaravelRestify\MCP\Concerns\HasMcpTools; |
14 | 15 | use Binaryk\LaravelRestify\Repositories\Repository; |
15 | 16 | use Illuminate\Support\Collection; |
16 | 17 |
|
@@ -97,6 +98,21 @@ public function forIndex(RestifyRequest $request, Repository $repository): self |
97 | 98 | }); |
98 | 99 | } |
99 | 100 |
|
| 101 | + public function forMcp(RestifyRequest $request, Repository $repository): self |
| 102 | + { |
| 103 | + return $this->filter(function (Related $related) { |
| 104 | + // If there's an EagerField, check its repository class |
| 105 | + if ($related->field && $related->field->repositoryClass) { |
| 106 | + return in_array(HasMcpTools::class, class_uses_recursive($related->field->repositoryClass), true); |
| 107 | + } |
| 108 | + |
| 109 | + // For string relationships (without EagerField), we need to find the repository |
| 110 | + // This happens when relationships are defined as static::$related = ['user'] |
| 111 | + // We'll allow these through and let the serialization handle the filtering |
| 112 | + return true; |
| 113 | + }); |
| 114 | + } |
| 115 | + |
100 | 116 | public function inRequest(RestifyRequest $request, Repository $repository): self |
101 | 117 | { |
102 | 118 | return $this->filter(function (mixed $repositoryRelatedField, $repositoryRelatedKey) use ( |
@@ -167,7 +183,8 @@ public function forRequest(RestifyRequest $request, Repository $repository): sel |
167 | 183 | ->authorized($request) |
168 | 184 | ->inRequest($request, $repository) |
169 | 185 | ->when($request->isShowRequest(), fn (self $collection) => $collection->forShow($request, $repository)) |
170 | | - ->when($request->isIndexRequest(), fn (self $collection) => $collection->forIndex($request, $repository)); |
| 186 | + ->when($request->isIndexRequest(), fn (self $collection) => $collection->forIndex($request, $repository)) |
| 187 | + ->when($repository->isForMcp(), fn (self $collection) => $collection->forIndex($request, $repository)); |
171 | 188 | } |
172 | 189 |
|
173 | 190 | public function unserialized(RestifyRequest $request, Repository $repository) |
|
0 commit comments