Skip to content

Commit 7d42823

Browse files
committed
fix: config
1 parent 25d9a2a commit 7d42823

File tree

10 files changed

+146
-20
lines changed

10 files changed

+146
-20
lines changed

src/Concerns/MakesHttpRequests.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function client(): PendingRequest
1717
]);
1818

1919
// Disable SSL verification for local development URLs and testing
20-
if (app()->environment(['local', 'testing']) || str_contains(config('restify-mcp.hosted.api_url', ''), '.test')) {
20+
if (app()->environment(['local', 'testing']) || str_contains(config('restify-boost.hosted.api_url', ''), '.test')) {
2121
$client = $client->withoutVerifying();
2222
}
2323

src/Mcp/Prompts/RestifyHowTo.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ protected function initializeIndexer(): void
7575
protected function getDocumentationPaths(): array
7676
{
7777
$paths = [];
78-
$docsPath = config('restify-mcp.docs.paths.primary');
79-
$legacyPath = config('restify-mcp.docs.paths.legacy');
78+
$docsPath = config('restify-boost.docs.paths.primary');
79+
$legacyPath = config('restify-boost.docs.paths.legacy');
8080

8181
foreach ([$docsPath, $legacyPath] as $basePath) {
8282
if (is_dir($basePath)) {

src/Mcp/Prompts/RestifyTroubleshooting.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ protected function initializeIndexer(): void
7676
protected function getDocumentationPaths(): array
7777
{
7878
$paths = [];
79-
$docsPath = config('restify-mcp.docs.paths.primary');
80-
$legacyPath = config('restify-mcp.docs.paths.legacy');
79+
$docsPath = config('restify-boost.docs.paths.primary');
80+
$legacyPath = config('restify-boost.docs.paths.legacy');
8181

8282
foreach ([$docsPath, $legacyPath] as $basePath) {
8383
if (is_dir($basePath)) {

src/Mcp/ToolRegistry.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class ToolRegistry
2020
public static function initialize(): void
2121
{
2222
self::$allowedTools = self::discoverTools();
23-
self::$excludedTools = config('restify-mcp.mcp.tools.exclude', []);
23+
self::$excludedTools = config('restify-boost.mcp.tools.exclude', []);
2424
}
2525

2626
/**
@@ -76,7 +76,7 @@ private static function discoverTools(): array
7676
}
7777

7878
// Add any additional tools from config
79-
$additionalTools = config('restify-mcp.mcp.tools.include', []);
79+
$additionalTools = config('restify-boost.mcp.tools.include', []);
8080
$tools = array_merge($tools, $additionalTools);
8181

8282
return array_unique($tools);

src/Mcp/Tools/GetCodeExamples.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ protected function initializeIndexer(): void
9191
protected function getDocumentationPaths(): array
9292
{
9393
$paths = [];
94-
$docsPath = config('restify-mcp.docs.paths.primary');
94+
$docsPath = config('restify-boost.docs.paths.primary');
9595

9696
foreach ([$docsPath] as $basePath) {
9797
if (is_dir($basePath)) {

src/Mcp/Tools/InstallRestifyTool.php

Lines changed: 127 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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";

src/Mcp/Tools/NavigateDocs.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ protected function initializeIndexer(): void
7070
protected function getDocumentationPaths(): array
7171
{
7272
$paths = [];
73-
$docsPath = config('restify-mcp.docs.paths.primary');
73+
$docsPath = config('restify-boost.docs.paths.primary');
7474

7575
foreach ([$docsPath] as $basePath) {
7676
if (is_dir($basePath)) {
@@ -257,7 +257,7 @@ protected function browseCategory(?string $category, bool $includeContent, int $
257257

258258
protected function getCategoryName(string $category): string
259259
{
260-
$categories = config('restify-mcp.categories', []);
260+
$categories = config('restify-boost.categories', []);
261261

262262
return $categories[$category]['name'] ?? ucfirst(str_replace(['-', '_'], ' ', $category));
263263
}

src/Services/DocCache.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ class DocCache
1919

2020
public function __construct()
2121
{
22-
$this->cache = Cache::store(config('restify-mcp.cache.store'));
23-
$this->keyPrefix = config('restify-mcp.cache.key_prefix', 'restify_mcp');
24-
$this->ttl = config('restify-mcp.cache.ttl', 3600);
25-
$this->enabled = config('restify-mcp.cache.enabled', true);
22+
$this->cache = Cache::store(config('restify-boost.cache.store'));
23+
$this->keyPrefix = config('restify-boost.cache.key_prefix', 'restify_mcp');
24+
$this->ttl = config('restify-boost.cache.ttl', 3600);
25+
$this->enabled = config('restify-boost.cache.enabled', true);
2626
}
2727

2828
public function remember(string $key, callable $callback): mixed

src/Services/DocIndexer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,15 @@ protected function tokenize(string $text): array
202202
$terms = array_filter(preg_split('/\s+/', $text));
203203

204204
// Remove very short terms
205-
$terms = array_filter($terms, fn ($term) => strlen($term) >= config('restify-mcp.search.min_query_length', 2));
205+
$terms = array_filter($terms, fn ($term) => strlen($term) >= config('restify-boost.search.min_query_length', 2));
206206

207207
return array_unique($terms);
208208
}
209209

210210
protected function calculateRelevanceScore(array $doc, array $queryTerms): float
211211
{
212212
$score = 0;
213-
$boostScores = config('restify-mcp.search.boost_scores', [
213+
$boostScores = config('restify-boost.search.boost_scores', [
214214
'title' => 3.0,
215215
'heading' => 2.0,
216216
'content' => 1.0,
@@ -332,7 +332,7 @@ protected function findMatchingCodeExamples(array $doc, array $queryTerms): arra
332332

333333
protected function getCategoryName(string $category): string
334334
{
335-
$categories = config('restify-mcp.categories', []);
335+
$categories = config('restify-boost.categories', []);
336336

337337
return $categories[$category]['name'] ?? ucfirst(str_replace(['-', '_'], ' ', $category));
338338
}

src/Services/DocParser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ protected function cleanMarkdown(string $markdown): string
147147

148148
protected function extractSummary(string $content): string
149149
{
150-
$summaryLength = config('restify-mcp.docs.processing.summary_length', 300);
150+
$summaryLength = config('restify-boost.docs.processing.summary_length', 300);
151151

152152
$sentences = preg_split('/[.!?]+/', $content, -1, PREG_SPLIT_NO_EMPTY);
153153
$summary = '';
@@ -167,7 +167,7 @@ protected function extractSummary(string $content): string
167167

168168
protected function determineCategory(string $filePath): string
169169
{
170-
$categories = config('restify-mcp.categories', []);
170+
$categories = config('restify-boost.categories', []);
171171

172172
foreach ($categories as $categoryKey => $categoryConfig) {
173173
$paths = $categoryConfig['paths'] ?? [];

0 commit comments

Comments
 (0)