From 027088a892df004d3d936b007f2276518b85f624 Mon Sep 17 00:00:00 2001 From: Eduard Lupacescu Date: Mon, 27 Oct 2025 20:13:03 +0200 Subject: [PATCH] fix: ignore cache for tools --- src/MCP/Bootstrap/BootMcpTools.php | 57 ++++++++---------------------- 1 file changed, 15 insertions(+), 42 deletions(-) diff --git a/src/MCP/Bootstrap/BootMcpTools.php b/src/MCP/Bootstrap/BootMcpTools.php index c84b7337..401c66cc 100644 --- a/src/MCP/Bootstrap/BootMcpTools.php +++ b/src/MCP/Bootstrap/BootMcpTools.php @@ -21,8 +21,6 @@ use Binaryk\LaravelRestify\Repositories\Repository; use Binaryk\LaravelRestify\Restify; use Illuminate\Support\Collection; -use Illuminate\Support\Facades\App; -use Illuminate\Support\Facades\Cache; /** * Bootstrap MCP tools discovery. @@ -35,36 +33,11 @@ class BootMcpTools */ public function boot(): array { - // In tests, skip caching to avoid database cache table issues - if (app()->environment('testing')) { - return collect() - ->merge($this->discoverCustomTools()) - ->merge($this->discoverRepositoryTools()) - ->values() - ->toArray(); - } - - // Cache key includes mode to prevent cache pollution between modes - $mode = config('restify.mcp.mode', 'direct'); - $cacheKey = "restify.mcp.all_tools_metadata.{$mode}"; - - if (App::hasDebugModeEnabled()) { - return collect() - ->merge($this->discoverCustomTools()) - ->merge($this->discoverRepositoryTools()) - ->values() - ->toArray(); - } - - $tools = Cache::remember($cacheKey, 3600, function (): array { - return collect() - ->merge($this->discoverCustomTools()) - ->merge($this->discoverRepositoryTools()) - ->values() - ->toArray(); - }); - - return $tools; + return collect() + ->merge($this->discoverCustomTools()) + ->merge($this->discoverRepositoryTools()) + ->values() + ->toArray(); } /** @@ -167,8 +140,8 @@ protected function discoverCustomTools(): Collection protected function discoverRepositoryTools(): Collection { return collect(Restify::$repositories) - ->filter(fn (string $repo): bool => in_array(HasMcpTools::class, class_uses_recursive($repo))) - ->flatMap(fn (string $repoClass): Collection => $this->discoverRepositoryOperations($repoClass)) + ->filter(fn(string $repo): bool => in_array(HasMcpTools::class, class_uses_recursive($repo))) + ->flatMap(fn(string $repoClass): Collection => $this->discoverRepositoryOperations($repoClass)) ->values(); } @@ -238,10 +211,10 @@ protected function discoverActions(string $repositoryClass, Repository $reposito $actionRequest = app(McpActionRequest::class); return $repository->resolveActions($actionRequest) - ->filter(fn ($action): bool => $action instanceof Action) - ->filter(fn (Action $action): bool => $action->isShownOnMcp($actionRequest, $repository)) - ->filter(fn (Action $action): bool => $action->authorizedToSee($actionRequest)) - ->unique(fn (Action $action): string => $action->uriKey()) + ->filter(fn($action): bool => $action instanceof Action) + ->filter(fn(Action $action): bool => $action->isShownOnMcp($actionRequest, $repository)) + ->filter(fn(Action $action): bool => $action->authorizedToSee($actionRequest)) + ->unique(fn(Action $action): string => $action->uriKey()) ->map(function (Action $action) use ($repositoryClass, $repository): array { $instance = new ActionTool($repositoryClass, $action); @@ -268,10 +241,10 @@ protected function discoverGetters(string $repositoryClass, Repository $reposito $getterRequest = app(McpGetterRequest::class); return $repository->resolveGetters($getterRequest) - ->filter(fn ($getter): bool => $getter instanceof Getter) - ->filter(fn (Getter $getter): bool => $getter->isShownOnMcp($getterRequest, $repository)) - ->filter(fn (Getter $getter): bool => $getter->authorizedToSee($getterRequest)) - ->unique(fn (Getter $getter): string => $getter->uriKey()) + ->filter(fn($getter): bool => $getter instanceof Getter) + ->filter(fn(Getter $getter): bool => $getter->isShownOnMcp($getterRequest, $repository)) + ->filter(fn(Getter $getter): bool => $getter->authorizedToSee($getterRequest)) + ->unique(fn(Getter $getter): string => $getter->uriKey()) ->map(function (Getter $getter) use ($repositoryClass, $repository): array { $instance = new GetterTool($repositoryClass, $getter);