@@ -18,7 +18,7 @@ class InstallRestifyTool extends Tool
1818
1919 public function description (): string
2020 {
21- return 'Install and setup Laravel Restify package with all necessary configurations. This tool handles composer installation, downloads the latest config file from Laravel Restify 10.x, runs setup commands, creates the Restify service provider, scaffolds repositories, and optionally configures authentication middleware and generates mock data. ' ;
21+ return 'Install and setup Laravel Restify package with all necessary configurations. This tool handles composer installation, downloads the latest config file from Laravel Restify 10.x, runs setup commands, creates the Restify service provider, scaffolds repositories, optionally configures authentication middleware, generates mock data, and can setup MCP (Model Context Protocol) server routes for AI integration . ' ;
2222 }
2323
2424 public function schema (ToolInputSchema $ schema ): ToolInputSchema
@@ -47,6 +47,9 @@ public function schema(ToolInputSchema $schema): ToolInputSchema
4747 ->optional ()
4848 ->boolean ('update_config ' )
4949 ->description ('Download and use the latest config file from Laravel Restify 10.x (default: true) ' )
50+ ->optional ()
51+ ->boolean ('setup_mcp ' )
52+ ->description ('Setup MCP (Model Context Protocol) server routes for AI integration (default: false) ' )
5053 ->optional ();
5154 }
5255
@@ -61,6 +64,7 @@ public function handle(array $arguments): ToolResult|Generator
6164 $ generateRepositories = $ arguments ['generate_repositories ' ] ?? false ;
6265 $ force = $ arguments ['force ' ] ?? false ;
6366 $ updateConfig = $ arguments ['update_config ' ] ?? true ;
67+ $ setupMcp = $ arguments ['setup_mcp ' ] ?? false ;
6468
6569 // Step 1: Validate environment
6670 $ validationResult = $ this ->validateEnvironment ();
@@ -128,6 +132,11 @@ public function handle(array $arguments): ToolResult|Generator
128132 $ results [] = $ this ->generateRepositoriesForModels ();
129133 }
130134
135+ // Step 10: Setup MCP if requested
136+ if ($ setupMcp ) {
137+ $ results [] = $ this ->setupMcpRoutes ();
138+ }
139+
131140 return $ this ->generateSuccessResponse ($ results , $ arguments );
132141
133142 } catch (\Throwable $ e ) {
@@ -566,6 +575,90 @@ protected function generateRepositoriesForModels(): array
566575 }
567576 }
568577
578+ protected function setupMcpRoutes (): array
579+ {
580+ try {
581+ $ routesPath = base_path ('routes/ai.php ' );
582+
583+ // Check if routes/ai.php already exists
584+ if (File::exists ($ routesPath )) {
585+ $ existingContent = File::get ($ routesPath );
586+
587+ // Check if MCP routes already exist
588+ if (str_contains ($ existingContent , 'RestifyServer ' ) || str_contains ($ existingContent , 'mcp.restify ' )) {
589+ return [
590+ 'success ' => true ,
591+ 'step ' => 'MCP Setup ' ,
592+ 'message ' => 'MCP routes already configured in routes/ai.php ' ,
593+ ];
594+ }
595+
596+ // Append to existing file
597+ $ mcpRoutes = $ this ->getMcpRoutesContent ();
598+ File::append ($ routesPath , "\n\n" . $ mcpRoutes );
599+
600+ return [
601+ 'success ' => true ,
602+ 'step ' => 'MCP Setup ' ,
603+ 'message ' => 'MCP routes added to existing routes/ai.php file ' ,
604+ ];
605+ }
606+
607+ // Create new routes/ai.php file
608+ $ fullRoutesContent = $ this ->getFullMcpRoutesFile ();
609+ File::put ($ routesPath , $ fullRoutesContent );
610+
611+ return [
612+ 'success ' => true ,
613+ 'step ' => 'MCP Setup ' ,
614+ 'message ' => 'Created routes/ai.php with MCP server configuration ' ,
615+ ];
616+
617+ } catch (\Exception $ e ) {
618+ return [
619+ 'success ' => false ,
620+ 'step ' => 'MCP Setup ' ,
621+ 'message ' => 'Failed to setup MCP routes: ' . $ e ->getMessage (),
622+ ];
623+ }
624+ }
625+
626+ protected function getMcpRoutesContent (): string
627+ {
628+ return '// Laravel Restify MCP Server Routes
629+ use Binaryk\LaravelRestify\MCP\RestifyServer;
630+ use Laravel\Mcp\Facades\Mcp;
631+
632+ // Web-based MCP server with authentication
633+ Mcp::web( \'restify \', RestifyServer::class)
634+ ->middleware([ \'auth:sanctum \'])
635+ ->name( \'mcp.restify \'); ' ;
636+ }
637+
638+ protected function getFullMcpRoutesFile (): string
639+ {
640+ return '<?php
641+
642+ use Binaryk\LaravelRestify\MCP\RestifyServer;
643+ use Laravel\Mcp\Facades\Mcp;
644+
645+ /*
646+ |--------------------------------------------------------------------------
647+ | AI Routes
648+ |--------------------------------------------------------------------------
649+ |
650+ | Here you can register AI-related routes for your application, including
651+ | MCP (Model Context Protocol) servers and other AI integrations.
652+ |
653+ */
654+
655+ // Web-based MCP server with authentication
656+ Mcp::web( \'restify \', RestifyServer::class)
657+ ->middleware([ \'auth:sanctum \'])
658+ ->name( \'mcp.restify \');
659+ ' ;
660+ }
661+
569662 protected function generateSuccessResponse (array $ results , array $ arguments ): ToolResult
570663 {
571664 $ response = "# Laravel Restify Installation Complete! 🎉 \n\n" ;
@@ -609,6 +702,10 @@ protected function generateSuccessResponse(array $results, array $arguments): To
609702 $ response .= "✅ **Config File:** Updated with latest Laravel Restify 10.x configuration \n" ;
610703 }
611704
705+ if ($ arguments ['setup_mcp ' ] ?? false ) {
706+ $ response .= "✅ **MCP Server:** AI integration routes configured in routes/ai.php \n" ;
707+ }
708+
612709 // What was created
613710 $ response .= "\n## Files Created/Updated \n\n" ;
614711 $ response .= "- `config/restify.php` - Latest configuration file (v10.x) \n" ;
@@ -621,6 +718,10 @@ protected function generateSuccessResponse(array $results, array $arguments): To
621718 if ($ arguments ['update_config ' ] ?? true ) {
622719 $ response .= "- `config/restify.php.backup-*` - Backup of previous config (if existed) \n" ;
623720 }
721+
722+ if ($ arguments ['setup_mcp ' ] ?? false ) {
723+ $ response .= "- `routes/ai.php` - MCP server routes for AI integration \n" ;
724+ }
624725
625726 // API endpoints
626727 $ apiPrefix = $ arguments ['api_prefix ' ] ?? '/api/restify ' ;
@@ -634,6 +735,16 @@ protected function generateSuccessResponse(array $results, array $arguments): To
634735 $ response .= "DELETE {$ apiPrefix }/users/{id} # Delete user \n" ;
635736 $ response .= "``` \n" ;
636737
738+ // MCP endpoints if enabled
739+ if ($ arguments ['setup_mcp ' ] ?? false ) {
740+ $ response .= "\n## MCP Server Endpoints \n\n" ;
741+ $ response .= "Your MCP (Model Context Protocol) server is available at: \n\n" ;
742+ $ response .= "``` \n" ;
743+ $ response .= "POST /mcp/restify # MCP server endpoint \n" ;
744+ $ response .= "``` \n" ;
745+ $ response .= "\n**Authentication:** Requires Sanctum token via `auth:sanctum` middleware \n" ;
746+ }
747+
637748 // Next steps
638749 $ response .= "\n## Next Steps \n\n" ;
639750 $ response .= "1. **Test the API:** Make a GET request to ` {$ apiPrefix }/users` \n" ;
@@ -646,6 +757,11 @@ protected function generateSuccessResponse(array $results, array $arguments): To
646757 $ response .= "6. **Configure Sanctum:** Ensure Laravel Sanctum is properly set up \n" ;
647758 }
648759
760+ if ($ arguments ['setup_mcp ' ] ?? false ) {
761+ $ nextStepNumber = ($ arguments ['enable_sanctum_auth ' ] ?? false ) ? "7 " : "6 " ;
762+ $ response .= "{$ nextStepNumber }. **Test MCP Server:** Connect your AI client to `/mcp/restify` endpoint \n" ;
763+ }
764+
649765 // Authentication note
650766 if ($ arguments ['enable_sanctum_auth ' ] ?? false ) {
651767 $ response .= "\n## Authentication Note \n\n" ;
@@ -655,6 +771,16 @@ protected function generateSuccessResponse(array $results, array $arguments): To
655771 $ response .= "- API tokens are configured for your users \n" ;
656772 }
657773
774+ // MCP note
775+ if ($ arguments ['setup_mcp ' ] ?? false ) {
776+ $ response .= "\n## MCP Server Note \n\n" ;
777+ $ response .= "🤖 **MCP server is configured.** To use it: \n" ;
778+ $ response .= "- The MCP server is protected by Sanctum authentication \n" ;
779+ $ response .= "- AI clients need valid API tokens to access the server \n" ;
780+ $ response .= "- The server provides AI tools for repository management, debugging, and more \n" ;
781+ $ response .= "- Configure your AI client to connect to `/mcp/restify` \n" ;
782+ }
783+
658784 // Additional commands
659785 $ response .= "\n## Useful Commands \n\n" ;
660786 $ response .= "```bash \n" ;
0 commit comments