Skip to content

Commit 027088a

Browse files
committed
fix: ignore cache for tools
1 parent d9687d7 commit 027088a

File tree

1 file changed

+15
-42
lines changed

1 file changed

+15
-42
lines changed

src/MCP/Bootstrap/BootMcpTools.php

Lines changed: 15 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
use Binaryk\LaravelRestify\Repositories\Repository;
2222
use Binaryk\LaravelRestify\Restify;
2323
use Illuminate\Support\Collection;
24-
use Illuminate\Support\Facades\App;
25-
use Illuminate\Support\Facades\Cache;
2624

2725
/**
2826
* Bootstrap MCP tools discovery.
@@ -35,36 +33,11 @@ class BootMcpTools
3533
*/
3634
public function boot(): array
3735
{
38-
// In tests, skip caching to avoid database cache table issues
39-
if (app()->environment('testing')) {
40-
return collect()
41-
->merge($this->discoverCustomTools())
42-
->merge($this->discoverRepositoryTools())
43-
->values()
44-
->toArray();
45-
}
46-
47-
// Cache key includes mode to prevent cache pollution between modes
48-
$mode = config('restify.mcp.mode', 'direct');
49-
$cacheKey = "restify.mcp.all_tools_metadata.{$mode}";
50-
51-
if (App::hasDebugModeEnabled()) {
52-
return collect()
53-
->merge($this->discoverCustomTools())
54-
->merge($this->discoverRepositoryTools())
55-
->values()
56-
->toArray();
57-
}
58-
59-
$tools = Cache::remember($cacheKey, 3600, function (): array {
60-
return collect()
61-
->merge($this->discoverCustomTools())
62-
->merge($this->discoverRepositoryTools())
63-
->values()
64-
->toArray();
65-
});
66-
67-
return $tools;
36+
return collect()
37+
->merge($this->discoverCustomTools())
38+
->merge($this->discoverRepositoryTools())
39+
->values()
40+
->toArray();
6841
}
6942

7043
/**
@@ -167,8 +140,8 @@ protected function discoverCustomTools(): Collection
167140
protected function discoverRepositoryTools(): Collection
168141
{
169142
return collect(Restify::$repositories)
170-
->filter(fn (string $repo): bool => in_array(HasMcpTools::class, class_uses_recursive($repo)))
171-
->flatMap(fn (string $repoClass): Collection => $this->discoverRepositoryOperations($repoClass))
143+
->filter(fn(string $repo): bool => in_array(HasMcpTools::class, class_uses_recursive($repo)))
144+
->flatMap(fn(string $repoClass): Collection => $this->discoverRepositoryOperations($repoClass))
172145
->values();
173146
}
174147

@@ -238,10 +211,10 @@ protected function discoverActions(string $repositoryClass, Repository $reposito
238211
$actionRequest = app(McpActionRequest::class);
239212

240213
return $repository->resolveActions($actionRequest)
241-
->filter(fn ($action): bool => $action instanceof Action)
242-
->filter(fn (Action $action): bool => $action->isShownOnMcp($actionRequest, $repository))
243-
->filter(fn (Action $action): bool => $action->authorizedToSee($actionRequest))
244-
->unique(fn (Action $action): string => $action->uriKey())
214+
->filter(fn($action): bool => $action instanceof Action)
215+
->filter(fn(Action $action): bool => $action->isShownOnMcp($actionRequest, $repository))
216+
->filter(fn(Action $action): bool => $action->authorizedToSee($actionRequest))
217+
->unique(fn(Action $action): string => $action->uriKey())
245218
->map(function (Action $action) use ($repositoryClass, $repository): array {
246219
$instance = new ActionTool($repositoryClass, $action);
247220

@@ -268,10 +241,10 @@ protected function discoverGetters(string $repositoryClass, Repository $reposito
268241
$getterRequest = app(McpGetterRequest::class);
269242

270243
return $repository->resolveGetters($getterRequest)
271-
->filter(fn ($getter): bool => $getter instanceof Getter)
272-
->filter(fn (Getter $getter): bool => $getter->isShownOnMcp($getterRequest, $repository))
273-
->filter(fn (Getter $getter): bool => $getter->authorizedToSee($getterRequest))
274-
->unique(fn (Getter $getter): string => $getter->uriKey())
244+
->filter(fn($getter): bool => $getter instanceof Getter)
245+
->filter(fn(Getter $getter): bool => $getter->isShownOnMcp($getterRequest, $repository))
246+
->filter(fn(Getter $getter): bool => $getter->authorizedToSee($getterRequest))
247+
->unique(fn(Getter $getter): string => $getter->uriKey())
275248
->map(function (Getter $getter) use ($repositoryClass, $repository): array {
276249
$instance = new GetterTool($repositoryClass, $getter);
277250

0 commit comments

Comments
 (0)