Skip to content

Commit 17e6617

Browse files
committed
feat: laravel mcp 0.2
1 parent 016a886 commit 17e6617

17 files changed

+620
-543
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"illuminate/console": "^10.0|^11.0|^12.0",
2323
"illuminate/contracts": "^10.0|^11.0|^12.0",
2424
"illuminate/support": "^10.0|^11.0|^12.0",
25-
"laravel/mcp": "^0.1.1",
25+
"laravel/mcp": "^0.2.0",
2626
"laravel/prompts": "^0.3.6",
2727
"spatie/laravel-package-tools": "^1.16",
2828
"symfony/yaml": "^6.0|^7.0"

src/Mcp/Prompts/RestifyHowTo.php

Lines changed: 47 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,50 +5,68 @@
55
namespace BinarCode\RestifyBoost\Mcp\Prompts;
66

77
use BinarCode\RestifyBoost\Services\DocIndexer;
8+
use Laravel\Mcp\Request;
9+
use Laravel\Mcp\Response;
810
use Laravel\Mcp\Server\Prompt;
9-
use Laravel\Mcp\Server\Prompts\PromptInputSchema;
10-
use Laravel\Mcp\Server\Prompts\PromptResult;
1111

1212
class RestifyHowTo extends Prompt
1313
{
1414
public function __construct(protected DocIndexer $indexer) {}
1515

16-
public function name(): string
17-
{
18-
return 'restify-how-to';
19-
}
16+
/**
17+
* The prompt's name.
18+
*/
19+
protected string $name = 'restify-how-to';
2020

21-
public function description(): string
22-
{
23-
return 'Get step-by-step guidance on how to accomplish specific tasks with Laravel Restify. This prompt provides structured tutorials and explanations for common development scenarios like creating repositories, defining fields, implementing authentication, adding custom actions, and more.';
24-
}
21+
/**
22+
* The prompt's title.
23+
*/
24+
protected string $title = 'Laravel Restify How-To Guide';
2525

26-
public function schema(PromptInputSchema $schema): PromptInputSchema
26+
/**
27+
* Get the prompt's arguments.
28+
*
29+
* @return array<int, \Laravel\Mcp\Server\Prompts\Argument>
30+
*/
31+
public function arguments(): array
2732
{
28-
return $schema
29-
->string('task')
30-
->description('What you want to accomplish (e.g., "create a repository", "add custom validation", "implement authentication", "create a custom field")')
31-
->required()
32-
->string('context')
33-
->description('Additional context about your specific use case or requirements')
34-
->optional()
35-
->string('difficulty')
36-
->description('Preferred explanation level: "beginner", "intermediate", "advanced"')
37-
->optional();
33+
return [
34+
new \Laravel\Mcp\Server\Prompts\Argument(
35+
name: 'task',
36+
description: 'What you want to accomplish (e.g., "create a repository", "add custom validation", "implement authentication", "create a custom field")',
37+
required: true
38+
),
39+
new \Laravel\Mcp\Server\Prompts\Argument(
40+
name: 'context',
41+
description: 'Additional context about your specific use case or requirements',
42+
required: false
43+
),
44+
new \Laravel\Mcp\Server\Prompts\Argument(
45+
name: 'difficulty',
46+
description: 'Preferred explanation level: "beginner", "intermediate", "advanced"',
47+
required: false
48+
),
49+
];
3850
}
3951

4052
/**
41-
* @param array<string, mixed> $arguments
53+
* Handle the prompt request.
4254
*/
43-
public function handle(array $arguments): PromptResult
55+
public function handle(Request $request): Response
4456
{
4557
try {
46-
$task = trim($arguments['task']);
47-
$context = $arguments['context'] ?? '';
48-
$difficulty = strtolower($arguments['difficulty'] ?? 'intermediate');
58+
$validated = $request->validate([
59+
'task' => 'required|string|max:200',
60+
'context' => 'nullable|string|max:500',
61+
'difficulty' => 'nullable|string|in:beginner,intermediate,advanced',
62+
]);
63+
64+
$task = trim($validated['task']);
65+
$context = $validated['context'] ?? '';
66+
$difficulty = strtolower($validated['difficulty'] ?? 'intermediate');
4967

5068
if (empty($task)) {
51-
return PromptResult::text('Please specify what task you want to accomplish with Laravel Restify.');
69+
return Response::text('Please specify what task you want to accomplish with Laravel Restify.');
5270
}
5371

5472
// Initialize indexer
@@ -60,9 +78,9 @@ public function handle(array $arguments): PromptResult
6078
// Generate structured how-to guide
6179
$howToGuide = $this->generateHowToGuide($task, $context, $difficulty, $searchResults);
6280

63-
return PromptResult::text($howToGuide);
81+
return Response::text($howToGuide);
6482
} catch (\Throwable $e) {
65-
return PromptResult::text("I encountered an error while generating the how-to guide: {$e->getMessage()}");
83+
return Response::text("I encountered an error while generating the how-to guide: {$e->getMessage()}");
6684
}
6785
}
6886

src/Mcp/Prompts/RestifyTroubleshooting.php

Lines changed: 54 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,54 +5,75 @@
55
namespace BinarCode\RestifyBoost\Mcp\Prompts;
66

77
use BinarCode\RestifyBoost\Services\DocIndexer;
8+
use Laravel\Mcp\Request;
9+
use Laravel\Mcp\Response;
810
use Laravel\Mcp\Server\Prompt;
9-
use Laravel\Mcp\Server\Prompts\PromptInputSchema;
10-
use Laravel\Mcp\Server\Prompts\PromptResult;
1111

1212
class RestifyTroubleshooting extends Prompt
1313
{
1414
public function __construct(protected DocIndexer $indexer) {}
1515

16-
public function name(): string
17-
{
18-
return 'restify-troubleshooting';
19-
}
16+
/**
17+
* The prompt's name.
18+
*/
19+
protected string $name = 'restify-troubleshooting';
2020

21-
public function description(): string
22-
{
23-
return 'Get help troubleshooting Laravel Restify issues. Provide error messages, describe problems, or ask about common issues to receive targeted solutions and debugging guidance. This prompt helps diagnose and resolve configuration, runtime, and implementation problems.';
24-
}
21+
/**
22+
* The prompt's title.
23+
*/
24+
protected string $title = 'Laravel Restify Troubleshooting Guide';
2525

26-
public function schema(PromptInputSchema $schema): PromptInputSchema
26+
/**
27+
* Get the prompt's arguments.
28+
*
29+
* @return array<int, \Laravel\Mcp\Server\Prompts\Argument>
30+
*/
31+
public function arguments(): array
2732
{
28-
return $schema
29-
->string('issue')
30-
->description('Describe the problem you\'re experiencing or paste the error message')
31-
->required()
32-
->string('context')
33-
->description('Additional context: what you were trying to do, recent changes, environment details, etc.')
34-
->optional()
35-
->string('error_type')
36-
->description('Type of issue: "error", "performance", "configuration", "unexpected_behavior", or "other"')
37-
->optional()
38-
->string('code_snippet')
39-
->description('Relevant code snippet where the issue occurs')
40-
->optional();
33+
return [
34+
new \Laravel\Mcp\Server\Prompts\Argument(
35+
name: 'issue',
36+
description: 'Describe the problem you\'re experiencing or paste the error message',
37+
required: true
38+
),
39+
new \Laravel\Mcp\Server\Prompts\Argument(
40+
name: 'context',
41+
description: 'Additional context: what you were trying to do, recent changes, environment details, etc.',
42+
required: false
43+
),
44+
new \Laravel\Mcp\Server\Prompts\Argument(
45+
name: 'error_type',
46+
description: 'Type of issue: "error", "performance", "configuration", "unexpected_behavior", or "other"',
47+
required: false
48+
),
49+
new \Laravel\Mcp\Server\Prompts\Argument(
50+
name: 'code_snippet',
51+
description: 'Relevant code snippet where the issue occurs',
52+
required: false
53+
),
54+
];
4155
}
4256

4357
/**
44-
* @param array<string, mixed> $arguments
58+
* Handle the prompt request.
4559
*/
46-
public function handle(array $arguments): PromptResult
60+
public function handle(Request $request): Response
4761
{
4862
try {
49-
$issue = trim($arguments['issue']);
50-
$context = $arguments['context'] ?? '';
51-
$errorType = strtolower($arguments['error_type'] ?? 'other');
52-
$codeSnippet = $arguments['code_snippet'] ?? '';
63+
$validated = $request->validate([
64+
'issue' => 'required|string|max:1000',
65+
'context' => 'nullable|string|max:1000',
66+
'error_type' => 'nullable|string|in:error,performance,configuration,unexpected_behavior,other',
67+
'code_snippet' => 'nullable|string|max:2000',
68+
]);
69+
70+
$issue = trim($validated['issue']);
71+
$context = $validated['context'] ?? '';
72+
$errorType = strtolower($validated['error_type'] ?? 'other');
73+
$codeSnippet = $validated['code_snippet'] ?? '';
5374

5475
if (empty($issue)) {
55-
return PromptResult::text('Please describe the issue you\'re experiencing with Laravel Restify.');
76+
return Response::text('Please describe the issue you\'re experiencing with Laravel Restify.');
5677
}
5778

5879
// Initialize indexer
@@ -61,9 +82,9 @@ public function handle(array $arguments): PromptResult
6182
// Analyze the issue and generate troubleshooting guidance
6283
$troubleshootingGuide = $this->generateTroubleshootingGuide($issue, $context, $errorType, $codeSnippet);
6384

64-
return PromptResult::text($troubleshootingGuide);
85+
return Response::text($troubleshootingGuide);
6586
} catch (\Throwable $e) {
66-
return PromptResult::text("I encountered an error while generating troubleshooting guidance: {$e->getMessage()}");
87+
return Response::text("I encountered an error while generating troubleshooting guidance: {$e->getMessage()}");
6788
}
6889
}
6990

src/Mcp/Resources/RestifyApiReference.php

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,33 @@
55
namespace BinarCode\RestifyBoost\Mcp\Resources;
66

77
use BinarCode\RestifyBoost\Services\DocParser;
8-
use Laravel\Mcp\Server\Contracts\Resources\Content;
8+
use Laravel\Mcp\Request;
9+
use Laravel\Mcp\Response;
910
use Laravel\Mcp\Server\Resource;
1011

1112
class RestifyApiReference extends Resource
1213
{
1314
public function __construct(protected DocParser $parser) {}
1415

15-
public function description(): string
16-
{
17-
return 'Complete Laravel Restify API reference with detailed method signatures, field types, relationship patterns, and implementation examples. Includes repositories, fields, relations, actions, filters, authentication, and MCP-specific features.';
18-
}
19-
20-
public function read(): string|Content
16+
/**
17+
* The resource's description.
18+
*/
19+
protected string $description = 'Complete Laravel Restify API reference with detailed method signatures, field types, relationship patterns, and implementation examples. Includes repositories, fields, relations, actions, filters, authentication, and MCP-specific features.';
20+
21+
/**
22+
* The resource's URI.
23+
*/
24+
protected string $uri = 'file://restify-api-reference.json';
25+
26+
/**
27+
* The resource's MIME type.
28+
*/
29+
protected string $mimeType = 'application/json';
30+
31+
/**
32+
* Handle the resource request.
33+
*/
34+
public function handle(): Response
2135
{
2236
try {
2337
$apiReference = $this->buildApiReference();
@@ -31,9 +45,9 @@ public function read(): string|Content
3145
'generated_at' => now()->toIso8601String(),
3246
];
3347

34-
return json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
48+
return Response::json($response);
3549
} catch (\Throwable $e) {
36-
return "Error generating Laravel Restify API reference: {$e->getMessage()}";
50+
return Response::error("Error generating Laravel Restify API reference: {$e->getMessage()}");
3751
}
3852
}
3953

src/Mcp/Resources/RestifyDocumentation.php

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,33 @@
55
namespace BinarCode\RestifyBoost\Mcp\Resources;
66

77
use BinarCode\RestifyBoost\Services\DocParser;
8-
use Laravel\Mcp\Server\Contracts\Resources\Content;
8+
use Laravel\Mcp\Request;
9+
use Laravel\Mcp\Response;
910
use Laravel\Mcp\Server\Resource;
1011

1112
class RestifyDocumentation extends Resource
1213
{
1314
public function __construct(protected DocParser $parser) {}
1415

15-
public function description(): string
16-
{
17-
return 'Complete Laravel Restify documentation including installation guides, repositories, fields, filters, authentication, actions, and performance optimization. This resource provides structured access to all documentation content for comprehensive understanding of the framework.';
18-
}
19-
20-
public function read(): string|Content
16+
/**
17+
* The resource's description.
18+
*/
19+
protected string $description = 'Complete Laravel Restify documentation including installation guides, repositories, fields, filters, authentication, actions, and performance optimization. This resource provides structured access to all documentation content for comprehensive understanding of the framework.';
20+
21+
/**
22+
* The resource's URI.
23+
*/
24+
protected string $uri = 'file://restify-documentation.json';
25+
26+
/**
27+
* The resource's MIME type.
28+
*/
29+
protected string $mimeType = 'application/json';
30+
31+
/**
32+
* Handle the resource request.
33+
*/
34+
public function handle(): Response
2135
{
2236
try {
2337
$documentation = $this->loadDocumentation();
@@ -31,9 +45,9 @@ public function read(): string|Content
3145
'last_updated' => now()->toIso8601String(),
3246
];
3347

34-
return json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
48+
return Response::json($response);
3549
} catch (\Throwable $e) {
36-
return "Error loading Laravel Restify documentation: {$e->getMessage()}";
50+
return Response::error("Error loading Laravel Restify documentation: {$e->getMessage()}");
3751
}
3852
}
3953

0 commit comments

Comments
 (0)