Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"illuminate/console": "^10.0|^11.0|^12.0",
"illuminate/contracts": "^10.0|^11.0|^12.0",
"illuminate/support": "^10.0|^11.0|^12.0",
"laravel/mcp": "^0.1.1",
"laravel/mcp": "^0.2.0",
"laravel/prompts": "^0.3.6",
"spatie/laravel-package-tools": "^1.16",
"symfony/yaml": "^6.0|^7.0"
Expand Down
76 changes: 47 additions & 29 deletions src/Mcp/Prompts/RestifyHowTo.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,50 +5,68 @@
namespace BinarCode\RestifyBoost\Mcp\Prompts;

use BinarCode\RestifyBoost\Services\DocIndexer;
use Laravel\Mcp\Request;
use Laravel\Mcp\Response;
use Laravel\Mcp\Server\Prompt;
use Laravel\Mcp\Server\Prompts\PromptInputSchema;
use Laravel\Mcp\Server\Prompts\PromptResult;

class RestifyHowTo extends Prompt
{
public function __construct(protected DocIndexer $indexer) {}

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

public function description(): string
{
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.';
}
/**
* The prompt's title.
*/
protected string $title = 'Laravel Restify How-To Guide';

public function schema(PromptInputSchema $schema): PromptInputSchema
/**
* Get the prompt's arguments.
*
* @return array<int, \Laravel\Mcp\Server\Prompts\Argument>
*/
public function arguments(): array
{
return $schema
->string('task')
->description('What you want to accomplish (e.g., "create a repository", "add custom validation", "implement authentication", "create a custom field")')
->required()
->string('context')
->description('Additional context about your specific use case or requirements')
->optional()
->string('difficulty')
->description('Preferred explanation level: "beginner", "intermediate", "advanced"')
->optional();
return [
new \Laravel\Mcp\Server\Prompts\Argument(
name: 'task',
description: 'What you want to accomplish (e.g., "create a repository", "add custom validation", "implement authentication", "create a custom field")',
required: true
),
new \Laravel\Mcp\Server\Prompts\Argument(
name: 'context',
description: 'Additional context about your specific use case or requirements',
required: false
),
new \Laravel\Mcp\Server\Prompts\Argument(
name: 'difficulty',
description: 'Preferred explanation level: "beginner", "intermediate", "advanced"',
required: false
),
];
}

/**
* @param array<string, mixed> $arguments
* Handle the prompt request.
*/
public function handle(array $arguments): PromptResult
public function handle(Request $request): Response
{
try {
$task = trim($arguments['task']);
$context = $arguments['context'] ?? '';
$difficulty = strtolower($arguments['difficulty'] ?? 'intermediate');
$validated = $request->validate([
'task' => 'required|string|max:200',
'context' => 'nullable|string|max:500',
'difficulty' => 'nullable|string|in:beginner,intermediate,advanced',
]);

$task = trim($validated['task']);
$context = $validated['context'] ?? '';
$difficulty = strtolower($validated['difficulty'] ?? 'intermediate');

if (empty($task)) {
return PromptResult::text('Please specify what task you want to accomplish with Laravel Restify.');
return Response::text('Please specify what task you want to accomplish with Laravel Restify.');
}

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

return PromptResult::text($howToGuide);
return Response::text($howToGuide);
} catch (\Throwable $e) {
return PromptResult::text("I encountered an error while generating the how-to guide: {$e->getMessage()}");
return Response::text("I encountered an error while generating the how-to guide: {$e->getMessage()}");
}
}

Expand Down
87 changes: 54 additions & 33 deletions src/Mcp/Prompts/RestifyTroubleshooting.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,54 +5,75 @@
namespace BinarCode\RestifyBoost\Mcp\Prompts;

use BinarCode\RestifyBoost\Services\DocIndexer;
use Laravel\Mcp\Request;
use Laravel\Mcp\Response;
use Laravel\Mcp\Server\Prompt;
use Laravel\Mcp\Server\Prompts\PromptInputSchema;
use Laravel\Mcp\Server\Prompts\PromptResult;

class RestifyTroubleshooting extends Prompt
{
public function __construct(protected DocIndexer $indexer) {}

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

public function description(): string
{
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.';
}
/**
* The prompt's title.
*/
protected string $title = 'Laravel Restify Troubleshooting Guide';

public function schema(PromptInputSchema $schema): PromptInputSchema
/**
* Get the prompt's arguments.
*
* @return array<int, \Laravel\Mcp\Server\Prompts\Argument>
*/
public function arguments(): array
{
return $schema
->string('issue')
->description('Describe the problem you\'re experiencing or paste the error message')
->required()
->string('context')
->description('Additional context: what you were trying to do, recent changes, environment details, etc.')
->optional()
->string('error_type')
->description('Type of issue: "error", "performance", "configuration", "unexpected_behavior", or "other"')
->optional()
->string('code_snippet')
->description('Relevant code snippet where the issue occurs')
->optional();
return [
new \Laravel\Mcp\Server\Prompts\Argument(
name: 'issue',
description: 'Describe the problem you\'re experiencing or paste the error message',
required: true
),
new \Laravel\Mcp\Server\Prompts\Argument(
name: 'context',
description: 'Additional context: what you were trying to do, recent changes, environment details, etc.',
required: false
),
new \Laravel\Mcp\Server\Prompts\Argument(
name: 'error_type',
description: 'Type of issue: "error", "performance", "configuration", "unexpected_behavior", or "other"',
required: false
),
new \Laravel\Mcp\Server\Prompts\Argument(
name: 'code_snippet',
description: 'Relevant code snippet where the issue occurs',
required: false
),
];
}

/**
* @param array<string, mixed> $arguments
* Handle the prompt request.
*/
public function handle(array $arguments): PromptResult
public function handle(Request $request): Response
{
try {
$issue = trim($arguments['issue']);
$context = $arguments['context'] ?? '';
$errorType = strtolower($arguments['error_type'] ?? 'other');
$codeSnippet = $arguments['code_snippet'] ?? '';
$validated = $request->validate([
'issue' => 'required|string|max:1000',
'context' => 'nullable|string|max:1000',
'error_type' => 'nullable|string|in:error,performance,configuration,unexpected_behavior,other',
'code_snippet' => 'nullable|string|max:2000',
]);

$issue = trim($validated['issue']);
$context = $validated['context'] ?? '';
$errorType = strtolower($validated['error_type'] ?? 'other');
$codeSnippet = $validated['code_snippet'] ?? '';

if (empty($issue)) {
return PromptResult::text('Please describe the issue you\'re experiencing with Laravel Restify.');
return Response::text('Please describe the issue you\'re experiencing with Laravel Restify.');
}

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

return PromptResult::text($troubleshootingGuide);
return Response::text($troubleshootingGuide);
} catch (\Throwable $e) {
return PromptResult::text("I encountered an error while generating troubleshooting guidance: {$e->getMessage()}");
return Response::text("I encountered an error while generating troubleshooting guidance: {$e->getMessage()}");
}
}

Expand Down
32 changes: 23 additions & 9 deletions src/Mcp/Resources/RestifyApiReference.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,33 @@
namespace BinarCode\RestifyBoost\Mcp\Resources;

use BinarCode\RestifyBoost\Services\DocParser;
use Laravel\Mcp\Server\Contracts\Resources\Content;
use Laravel\Mcp\Request;
use Laravel\Mcp\Response;
use Laravel\Mcp\Server\Resource;

class RestifyApiReference extends Resource
{
public function __construct(protected DocParser $parser) {}

public function description(): string
{
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.';
}

public function read(): string|Content
/**
* The resource's description.
*/
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.';

/**
* The resource's URI.
*/
protected string $uri = 'file://restify-api-reference.json';

/**
* The resource's MIME type.
*/
protected string $mimeType = 'application/json';

/**
* Handle the resource request.
*/
public function handle(): Response
{
try {
$apiReference = $this->buildApiReference();
Expand All @@ -31,9 +45,9 @@ public function read(): string|Content
'generated_at' => now()->toIso8601String(),
];

return json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
return Response::json($response);
} catch (\Throwable $e) {
return "Error generating Laravel Restify API reference: {$e->getMessage()}";
return Response::error("Error generating Laravel Restify API reference: {$e->getMessage()}");
}
}

Expand Down
32 changes: 23 additions & 9 deletions src/Mcp/Resources/RestifyDocumentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,33 @@
namespace BinarCode\RestifyBoost\Mcp\Resources;

use BinarCode\RestifyBoost\Services\DocParser;
use Laravel\Mcp\Server\Contracts\Resources\Content;
use Laravel\Mcp\Request;
use Laravel\Mcp\Response;
use Laravel\Mcp\Server\Resource;

class RestifyDocumentation extends Resource
{
public function __construct(protected DocParser $parser) {}

public function description(): string
{
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.';
}

public function read(): string|Content
/**
* The resource's description.
*/
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.';

/**
* The resource's URI.
*/
protected string $uri = 'file://restify-documentation.json';

/**
* The resource's MIME type.
*/
protected string $mimeType = 'application/json';

/**
* Handle the resource request.
*/
public function handle(): Response
{
try {
$documentation = $this->loadDocumentation();
Expand All @@ -31,9 +45,9 @@ public function read(): string|Content
'last_updated' => now()->toIso8601String(),
];

return json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
return Response::json($response);
} catch (\Throwable $e) {
return "Error loading Laravel Restify documentation: {$e->getMessage()}";
return Response::error("Error loading Laravel Restify documentation: {$e->getMessage()}");
}
}

Expand Down
Loading