44
55use Binaryk \LaravelRestify \Actions \Action ;
66use Binaryk \LaravelRestify \MCP \Requests \McpActionRequest ;
7- use Laravel \ Mcp \ Server \ Tools \ ToolInputSchema ;
7+ use Illuminate \ JsonSchema \ JsonSchema ;
88
99/**
1010 * @mixin \Binaryk\LaravelRestify\Repositories\Repository
1111 */
1212trait McpActionTool
1313{
14- public function actionTool (Action $ action , array $ arguments , McpActionRequest $ actionRequest ): array
14+ public function actionTool (Action $ action , McpActionRequest $ actionRequest ): array
1515 {
16- $ actionRequest ->merge ($ arguments );
17-
18- $ this ->sanitizeToolRequest ($ actionRequest , $ arguments );
19-
2016 if ($ id = $ actionRequest ->input ('id ' )) {
2117 if (! $ action ->authorizedToRun ($ actionRequest , $ actionRequest ->findModelOrFail ($ id ))) {
2218 return [
@@ -26,17 +22,6 @@ public function actionTool(Action $action, array $arguments, McpActionRequest $a
2622 }
2723 }
2824
29- // Set up the action request context based on action type
30- if (! $ action ->isStandalone ()) {
31- if (isset ($ arguments ['id ' ])) {
32- // Single model action (show context)
33- $ actionRequest ->merge (['id ' => $ arguments ['id ' ]]);
34- } elseif (isset ($ arguments ['repositories ' ])) {
35- // Multiple models action (index context)
36- $ actionRequest ->merge (['repositories ' => $ arguments ['repositories ' ]]);
37- }
38- }
39-
4025 // Check authorization
4126 if (! $ action ->authorizedToSee ($ actionRequest )) {
4227 return [
@@ -61,9 +46,10 @@ public function actionTool(Action $action, array $arguments, McpActionRequest $a
6146 }
6247 }
6348
64- public static function actionToolSchema (Action $ action , ToolInputSchema $ schema , McpActionRequest $ mcpRequest ): void
49+ public static function actionToolSchema (Action $ action , JsonSchema $ schema , McpActionRequest $ mcpRequest ): array
6550 {
6651 $ modelName = class_basename (static ::guessModelClassName ());
52+ $ properties = [];
6753
6854 // Add action-specific validation rules
6955 $ actionRules = $ action ->rules ();
@@ -73,26 +59,27 @@ public static function actionToolSchema(Action $action, ToolInputSchema $schema,
7359
7460 // Determine field type based on rules
7561 if (in_array ('boolean ' , $ rulesArray )) {
76- $ fieldSchema = $ schema ->boolean ($ field );
62+ $ fieldSchema = $ schema ->boolean ();
7763 } elseif (in_array ('integer ' , $ rulesArray ) || in_array ('numeric ' , $ rulesArray )) {
78- $ fieldSchema = $ schema ->number ($ field );
64+ $ fieldSchema = $ schema ->number ();
7965 } elseif (in_array ('array ' , $ rulesArray )) {
80- $ fieldSchema = $ schema ->string ($ field );
66+ $ fieldSchema = $ schema ->string ();
8167 } else {
82- $ fieldSchema = $ schema ->string ($ field );
68+ $ fieldSchema = $ schema ->string ();
8369 }
8470
8571 if ($ isRequired ) {
8672 $ fieldSchema ->required ();
8773 }
8874
8975 $ fieldSchema ->description ("Action parameter: {$ field }" );
76+ $ properties [$ field ] = $ fieldSchema ;
9077 }
9178
9279 // Add context-specific fields based on action type
9380 if ($ action ->isStandalone ()) {
9481 // Standalone actions don't need ID or repositories
95- $ schema ->string (' include ' )
82+ $ properties [ ' include ' ] = $ schema ->string ()
9683 ->description ('Comma-separated list of relationships to include in response ' );
9784 } else {
9885 // Check if it's primarily a show action or index action
@@ -101,21 +88,23 @@ public static function actionToolSchema(Action $action, ToolInputSchema $schema,
10188
10289 if ($ shownOnShow && ! $ shownOnIndex ) {
10390 // Show action - requires single ID
104- $ schema ->string (' id ' )
91+ $ properties [ ' id ' ] = $ schema ->string ()
10592 ->description ("The ID of the {$ modelName } to perform the action on " )
10693 ->required ();
10794
108- $ schema ->string (' include ' )
95+ $ properties [ ' include ' ] = $ schema ->string ()
10996 ->description ('Comma-separated list of relationships to include ' );
11097 } else {
11198 // Index action - requires repositories array
112- $ schema ->string (' repositories ' )
99+ $ properties [ ' repositories ' ] = $ schema ->string ()
113100 ->description ("Array of {$ modelName } IDs to perform the action on. e.g. repositories=[1,2,3] " )
114101 ->required ();
115102
116- $ schema ->string (' include ' )
103+ $ properties [ ' include ' ] = $ schema ->string ()
117104 ->description ('Comma-separated list of relationships to include ' );
118105 }
119106 }
107+
108+ return $ properties ;
120109 }
121110}
0 commit comments