Skip to content

Commit 24c11b0

Browse files
committed
fix: fixing store and update via mcp
1 parent b303661 commit 24c11b0

36 files changed

+835
-102
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
coverage: none
2525

2626
- name: Install dependencies
27-
run: composer install --no-dev --prefer-dist --no-interaction --optimize-autoloader
27+
run: composer install --prefer-dist --no-interaction --optimize-autoloader
2828

2929
- name: Run tests
3030
run: |

src/Eager/Related.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function resolveField(Repository $repository): EagerField
6464
{
6565
return $this
6666
->field
67-
->forMcp($repository->isForMcp())
67+
->forMcp($repository->detectMcpRequest())
6868
->columns($this->getColumns())
6969
->resolve($repository);
7070
}

src/Eager/RelatedCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public function forRequest(RestifyRequest $request, Repository $repository): sel
184184
->inRequest($request, $repository)
185185
->when($request->isShowRequest(), fn (self $collection) => $collection->forShow($request, $repository))
186186
->when($request->isIndexRequest(), fn (self $collection) => $collection->forIndex($request, $repository))
187-
->when($repository->isForMcp(), fn (self $collection) => $collection->forIndex($request, $repository));
187+
->when($repository->detectMcpRequest(), fn (self $collection) => $collection->forIndex($request, $repository));
188188
}
189189

190190
public function unserialized(RestifyRequest $request, Repository $repository)

src/Fields/BelongsToMany.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function resolve($repository, $attribute = null)
5858

5959
return $repositoryFromClass
6060
->allowToShow(
61-
$this->isForMcp() ? app(McpRequest::class) : app(RestifyRequest::class)
61+
$this->detectMcpRequest() ? app(McpRequest::class) : app(RestifyRequest::class)
6262
)
6363
->withPivots(
6464
PivotsCollection::make($this->pivotFields)

src/Fields/EagerField.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class EagerField extends Field
3131

3232
private RelatedQuery $relatedQuery;
3333

34-
public bool $forMcp = false;
34+
public ?string $forMcp = null;
3535

3636
public function __construct($attribute, ?string $parentRepository = null)
3737
{
@@ -88,7 +88,7 @@ public function resolve($repository, $attribute = null)
8888
$serializableRepository = $this->repositoryClass::resolveWith($relatedModel);
8989

9090
$this->value = $serializableRepository
91-
->allowToShow($this->isForMcp() ? app(McpRequest::class) : app(RestifyRequest::class))
91+
->allowToShow($this->detectMcpRequest() ? app(McpRequest::class) : app(RestifyRequest::class))
9292
->columns()
9393
->eager($this);
9494
} catch (AuthorizationException) {
@@ -164,7 +164,7 @@ public function qualifySortable(RestifyRequest $request): ?string
164164
return $table.'.attributes.'.$this->sortableColumn;
165165
}
166166

167-
public function forMcp(bool|callable $forMcp = false): self
167+
public function forMcp(null|string|callable $forMcp = null): self
168168
{
169169
if (is_callable($forMcp)) {
170170
$this->forMcp = $forMcp();
@@ -177,7 +177,7 @@ public function forMcp(bool|callable $forMcp = false): self
177177
return $this;
178178
}
179179

180-
public function isForMcp(): bool
180+
public function detectMcpRequest(): ?string
181181
{
182182
return $this->forMcp;
183183
}

src/MCP/Concerns/HasMcpTools.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ public function mcpAllowsActions(): bool
4848

4949
public function mcpAllowsGetters(): bool
5050
{
51-
return true;
51+
return false;
5252
}
5353
}

src/MCP/Concerns/McpDestroyTool.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Binaryk\LaravelRestify\MCP\Concerns;
44

5+
use Binaryk\LaravelRestify\MCP\Requests\McpDestroyRequest;
56
use Binaryk\LaravelRestify\MCP\Requests\McpRequest;
67
use Laravel\Mcp\Server\Tools\ToolInputSchema;
78

@@ -10,7 +11,7 @@
1011
*/
1112
trait McpDestroyTool
1213
{
13-
public function deleteTool(array $arguments, McpRequest $request): array
14+
public function deleteTool(array $arguments, McpDestroyRequest $request): array
1415
{
1516
$id = $arguments['id'] ?? null;
1617
unset($arguments['id']);

src/MCP/Concerns/McpIndexTool.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Binaryk\LaravelRestify\Filters\MatchesCollection;
77
use Binaryk\LaravelRestify\Filters\MatchFilter;
88
use Binaryk\LaravelRestify\Filters\SearchablesCollection;
9+
use Binaryk\LaravelRestify\MCP\Requests\McpIndexRequest;
910
use Binaryk\LaravelRestify\MCP\Requests\McpRequest;
1011
use Laravel\Mcp\Server\Tools\ToolInputSchema;
1112

@@ -14,7 +15,7 @@
1415
*/
1516
trait McpIndexTool
1617
{
17-
public function indexTool(array $arguments, McpRequest $request): array
18+
public function indexTool(array $arguments, McpIndexRequest $request): array
1819
{
1920
$request->merge($arguments);
2021
$this->sanitizeToolRequest($request, $arguments);
@@ -33,7 +34,7 @@ public static function indexToolSchema(ToolInputSchema $schema): void
3334
->description("Number of $key per page");
3435

3536
$schema->string('include')
36-
->description(static::formatRelationshipDocumentation());
37+
->description(static::formatRelationshipDocumentation(app(McpIndexRequest::class)));
3738

3839
$searchableFields = (new SearchablesCollection(static::searchables()))->formatForDocumentation();
3940

@@ -66,11 +67,11 @@ public static function indexToolSchema(ToolInputSchema $schema): void
6667

6768
return match ($matchFilter->getType()) {
6869
RestifySearchable::MATCH_INTEGER, 'integer' => $schema->integer($filterKey)
69-
->description("Filter $key resource. Filter scription: ".$matchFilter->description()),
70+
->description("Filter $key resource. Description: ".$matchFilter->description()),
7071
RestifySearchable::MATCH_BOOL, 'boolean' => $schema->boolean($filterKey)
71-
->description("Filter $key resource. Filter scription: ".$matchFilter->description()),
72+
->description("Filter $key resource. Description: ".$matchFilter->description()),
7273
default => $schema->string($filterKey)
73-
->description("Filter $key resource. Filter scription: ".$matchFilter->description())
74+
->description("Filter $key resource. Description: ".$matchFilter->description())
7475
};
7576
});
7677
}

src/MCP/Concerns/McpShowTool.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
namespace Binaryk\LaravelRestify\MCP\Concerns;
44

55
use Binaryk\LaravelRestify\MCP\Requests\McpRequest;
6+
use Binaryk\LaravelRestify\MCP\Requests\McpShowRequest;
67
use Laravel\Mcp\Server\Tools\ToolInputSchema;
78

89
/**
910
* @mixin \Binaryk\LaravelRestify\Repositories\Repository
1011
*/
1112
trait McpShowTool
1213
{
13-
public function showTool(array $arguments, McpRequest $request): array
14+
public function showTool(array $arguments, McpShowRequest $request): array
1415
{
1516
$id = $arguments['id'] ?? null;
1617
unset($arguments['id']);

src/MCP/Concerns/McpStoreTool.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,30 @@
44

55
use Binaryk\LaravelRestify\Fields\Field;
66
use Binaryk\LaravelRestify\MCP\Requests\McpRequest;
7+
use Binaryk\LaravelRestify\MCP\Requests\McpStoreRequest;
78
use Laravel\Mcp\Server\Tools\ToolInputSchema;
89

910
/**
1011
* @mixin \Binaryk\LaravelRestify\Repositories\Repository
1112
*/
1213
trait McpStoreTool
1314
{
14-
public function storeTool(array $arguments, McpRequest $request): array
15+
public function storeTool(array $arguments, McpStoreRequest $request): array
1516
{
1617
$request->merge($arguments);
1718
$this->sanitizeToolRequest($request, $arguments);
1819

19-
return $this->store($request);
20+
return $this
21+
->allowToStore($request)
22+
->store($request)
23+
->getData(true);
2024
}
2125

2226
public static function storeToolSchema(ToolInputSchema $schema): void
2327
{
2428
$repository = static::resolveWith(static::newModel());
2529

26-
$repository->collectFields($request = app(McpRequest::class))
30+
$repository->collectFields($request = app(McpStoreRequest::class))
2731
->forStore($request, $repository)
2832
->withoutActions($request, $repository)
2933
->each(function (Field $field) use ($schema, $repository) {

0 commit comments

Comments
 (0)