44
55namespace Laravel \Boost \Mcp \Tools ;
66
7+ use Exception ;
8+ use Illuminate \Support \Arr ;
79use Illuminate \Support \Facades \Cache ;
810use Illuminate \Support \Facades \DB ;
911use Illuminate \Support \Facades \Log ;
1416use Laravel \Mcp \Server \Tools \ToolInputSchema ;
1517use Laravel \Mcp \Server \Tools \ToolResult ;
1618
17- #[IsReadOnly() ]
19+ #[IsReadOnly]
1820class DatabaseSchema extends Tool
1921{
2022 public function description (): string
@@ -42,7 +44,7 @@ public function handle(array $arguments): ToolResult
4244 {
4345 $ connection = $ arguments ['database ' ] ?? config ('database.default ' );
4446 $ filter = $ arguments ['filter ' ] ?? '' ;
45- $ cacheKey = "boost:mcp:database-schema: { $ connection} : { $ filter} " ;
47+ $ cacheKey = "boost:mcp:database-schema: $ connection: $ filter " ;
4648
4749 $ schema = Cache::remember ($ cacheKey , 20 , function () use ($ connection , $ filter ) {
4850 return $ this ->getDatabaseStructure ($ connection , $ filter );
@@ -53,13 +55,11 @@ public function handle(array $arguments): ToolResult
5355
5456 protected function getDatabaseStructure (?string $ connection , string $ filter = '' ): array
5557 {
56- $ structure = [
58+ return [
5759 'engine ' => DB ::connection ($ connection )->getDriverName (),
5860 'tables ' => $ this ->getAllTablesStructure ($ connection , $ filter ),
5961 'global ' => $ this ->getGlobalStructure ($ connection ),
6062 ];
61-
62- return $ structure ;
6363 }
6464
6565 protected function getAllTablesStructure (?string $ connection , string $ filter = '' ): array
@@ -102,7 +102,7 @@ protected function getTableStructure(?string $connection, string $tableName): ar
102102 'triggers ' => $ triggers ,
103103 'check_constraints ' => $ checkConstraints ,
104104 ];
105- } catch (\ Exception $ e ) {
105+ } catch (Exception $ e ) {
106106 Log::error ('Failed to get table structure for: ' .$ tableName , [
107107 'error ' => $ e ->getMessage (),
108108 'trace ' => $ e ->getTraceAsString (),
@@ -136,15 +136,15 @@ protected function getTableIndexes(?string $connection, string $tableName): arra
136136
137137 foreach ($ indexes as $ index ) {
138138 $ indexDetails [$ index ['name ' ]] = [
139- 'columns ' => $ index[ 'columns ' ] ,
140- 'type ' => $ index[ 'type ' ] ?? null ,
141- 'is_unique ' => $ index[ 'unique ' ] ?? false ,
142- 'is_primary ' => $ index[ 'primary ' ] ?? false ,
139+ 'columns ' => Arr:: get ( $ index, 'columns ' ) ,
140+ 'type ' => Arr:: get ( $ index, 'type ' ) ,
141+ 'is_unique ' => Arr:: get ( $ index, 'unique ' , false ) ,
142+ 'is_primary ' => Arr:: get ( $ index, 'primary ' , false ) ,
143143 ];
144144 }
145145
146146 return $ indexDetails ;
147- } catch (\ Exception $ e ) {
147+ } catch (Exception ) {
148148 return [];
149149 }
150150 }
@@ -153,7 +153,7 @@ protected function getTableForeignKeys(?string $connection, string $tableName):
153153 {
154154 try {
155155 return Schema::connection ($ connection )->getForeignKeys ($ tableName );
156- } catch (\ Exception $ e ) {
156+ } catch (Exception ) {
157157 return [];
158158 }
159159 }
0 commit comments