Skip to content

Commit f082b09

Browse files
authored
fixing run actions on mcp (#673)
* fix: fixing run actions on mcp * Fix styling --------- Co-authored-by: binaryk <binaryk@users.noreply.github.com>
1 parent 09b5e52 commit f082b09

File tree

5 files changed

+8
-8
lines changed

5 files changed

+8
-8
lines changed

src/Http/Requests/Concerns/InteractWithRepositories.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,12 @@ public function modelQuery(?string $repositoryId = null, ?string $uriKey = null)
9696
);
9797
}
9898

99-
public function findModelOrFail($id = null): Model
99+
public function findModelOrFail($id = null, ?string $uriKey = null): Model
100100
{
101101
return $id
102-
? $this->modelQuery($id)->firstOrFail()
103-
: once(function () {
104-
return $this->modelQuery()->firstOrFail();
102+
? $this->modelQuery($id, $uriKey)->firstOrFail()
103+
: once(function () use ($uriKey) {
104+
return $this->modelQuery(uriKey: $uriKey)->firstOrFail();
105105
});
106106
}
107107

src/MCP/Concerns/McpActionTool.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ trait McpActionTool
1414
public function actionTool(Action $action, McpActionRequest $actionRequest): array
1515
{
1616
if ($id = $actionRequest->input('id')) {
17-
if (! $action->authorizedToRun($actionRequest, $actionRequest->findModelOrFail($id))) {
17+
if (! $action->authorizedToRun($actionRequest, $actionRequest->findModelOrFail($id, static::uriKey()))) {
1818
return [
1919
'error' => 'Not authorized to run this action',
2020
'getter' => $action->uriKey(),

src/MCP/Concerns/McpGetterTool.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ trait McpGetterTool
1515
public function getterTool(Getter $getter, McpGetterRequest $getterRequest): array
1616
{
1717
if ($id = $getterRequest->input('id')) {
18-
if (! $getter->authorizedToRun($getterRequest, $getterRequest->findModelOrFail($id))) {
18+
if (! $getter->authorizedToRun($getterRequest, $getterRequest->findModelOrFail($id, static::uriKey()))) {
1919
return [
2020
'error' => 'Not authorized to run this getter',
2121
'getter' => $getter->uriKey(),

src/Repositories/ResolvesActions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function resolveShowActions(ActionRequest $request): Collection
4444
->filter(fn ($action) => $action->isShownOnShow(
4545
$request,
4646
$request->repositoryWith(
47-
$request->findModelOrFail()
47+
$request->findModelOrFail(uriKey: static::uriKey())
4848
)
4949
))->values();
5050
}

src/Repositories/ResolvesGetters.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function resolveShowGetters(GetterRequest $request): Collection
4444
->filter(fn ($getter) => $getter->isShownOnShow(
4545
$request,
4646
$request->repositoryWith(
47-
$request->findModelOrFail()
47+
$request->findModelOrFail(uriKey: static::uriKey())
4848
)
4949
))->values();
5050
}

0 commit comments

Comments
 (0)