-
Notifications
You must be signed in to change notification settings - Fork 214
Add Resource and Prompts for Package Guidelines #389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8f83111
WIP
pushpak1300 3569fdc
Merge branch 'main' into 3rd_party_prompt
pushpak1300 1732169
Merge branch 'main' into 3rd_party_prompt
pushpak1300 42e84f1
Add ThirdPartyResource and ThirdPartyPrompt classes
pushpak1300 f1cc9a5
Refactor test
pushpak1300 ba1c52e
Formatting
pushpak1300 9c9c257
Formatting
pushpak1300 3fc3499
Formatting
pushpak1300 7a5ea69
Formatting
pushpak1300 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add ThirdPartyResource and ThirdPartyPrompt classes
Signed-off-by: Pushpak Chhajed <[email protected]>
- Loading branch information
commit 42e84f1431f5df338df7b02e170da126817b78f9
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Laravel\Boost\Mcp\Resources; | ||
|
|
||
| use Laravel\Boost\Install\GuidelineAssist; | ||
| use Laravel\Boost\Mcp\Prompts\Concerns\RendersBladeGuidelines; | ||
| use Laravel\Mcp\Response; | ||
| use Laravel\Mcp\Server\Resource; | ||
|
|
||
| class ThirdPartyResource extends Resource | ||
| { | ||
| use RendersBladeGuidelines; | ||
|
|
||
| public function __construct( | ||
| protected GuidelineAssist $guidelineAssist, | ||
| protected string $packageName, | ||
| protected string $bladePath, | ||
| ) { | ||
| $this->uri = "file://instructions/{$packageName}.md"; | ||
| $this->description = "Guidelines for {$packageName}"; | ||
| $this->mimeType = 'text/markdown'; | ||
| } | ||
|
|
||
| public function handle(): Response | ||
| { | ||
| $content = $this->renderBlade($this->bladePath); | ||
|
|
||
| return Response::text($content); | ||
| } | ||
|
|
||
| protected function getGuidelineAssist(): GuidelineAssist | ||
| { | ||
| return $this->guidelineAssist; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| use Laravel\Boost\Install\GuidelineAssist; | ||
| use Laravel\Boost\Install\GuidelineConfig; | ||
| use Laravel\Boost\Install\Herd; | ||
| use Laravel\Boost\Mcp\Resources\ThirdPartyResource; | ||
| use Laravel\Roster\Roster; | ||
|
|
||
| beforeEach(function (): void { | ||
| $this->testBladePath = sys_get_temp_dir().'/test-resource-guideline.blade.php'; | ||
| file_put_contents($this->testBladePath, '# Test Resource Guideline | ||
|
|
||
| This is a test guideline for resource testing. | ||
|
|
||
| ## Rules | ||
| - Follow best practices | ||
| - Write clean code'); | ||
|
|
||
| $roster = app(Roster::class); | ||
| $herd = app(Herd::class); | ||
| $this->guidelineAssist = new GuidelineAssist($roster, new GuidelineConfig, $herd); | ||
| }); | ||
|
|
||
| afterEach(function (): void { | ||
| if (file_exists($this->testBladePath)) { | ||
| unlink($this->testBladePath); | ||
| } | ||
| }); | ||
|
|
||
| test('it renders blade file as resource', function (): void { | ||
| $resource = new ThirdPartyResource($this->guidelineAssist, 'acme/payments', $this->testBladePath); | ||
|
|
||
| $response = $resource->handle(); | ||
|
|
||
| expect($response)->isToolResult() | ||
| ->toolHasNoError() | ||
| ->toolTextContains('Test Resource Guideline') | ||
| ->toolTextContains('Follow best practices') | ||
| ->toolTextContains('Write clean code'); | ||
| }); | ||
|
|
||
| test('it generates correct resource uri from package', function (): void { | ||
| $resource = new ThirdPartyResource($this->guidelineAssist, 'acme/payments', $this->testBladePath); | ||
|
|
||
| expect($resource->uri())->toBe('file://instructions/acme/payments.md'); | ||
| }); | ||
|
|
||
| test('it generates correct description from package', function (): void { | ||
| $resource = new ThirdPartyResource($this->guidelineAssist, 'acme/payments', $this->testBladePath); | ||
|
|
||
| expect($resource->description())->toBe('Guidelines for acme/payments'); | ||
| }); | ||
|
|
||
| test('it has correct mime type', function (): void { | ||
| $resource = new ThirdPartyResource($this->guidelineAssist, 'acme/payments', $this->testBladePath); | ||
|
|
||
| expect($resource->mimeType())->toBe('text/markdown'); | ||
| }); | ||
|
|
||
| test('it handles non-existent blade file gracefully', function (): void { | ||
| $resource = new ThirdPartyResource($this->guidelineAssist, 'acme/test', '/non/existent/path.blade.php'); | ||
|
|
||
| $response = $resource->handle(); | ||
|
|
||
| expect($response)->isToolResult() | ||
| ->toolHasNoError(); | ||
|
|
||
| expect((string) $response->content())->toBe(''); | ||
| }); | ||
|
|
||
| test('it processes backticks in blade content', function (): void { | ||
| $bladeContent = '# Guideline | ||
|
|
||
| Use `Model::factory()` to create models. | ||
|
|
||
| ```php | ||
| User::factory()->create(); | ||
| ```'; | ||
|
|
||
| file_put_contents($this->testBladePath, $bladeContent); | ||
|
|
||
| $resource = new ThirdPartyResource($this->guidelineAssist, 'test/package', $this->testBladePath); | ||
| $response = $resource->handle(); | ||
|
|
||
| expect($response)->isToolResult() | ||
| ->toolTextContains('`Model::factory()`') | ||
| ->toolTextContains('```php'); | ||
| }); | ||
|
|
||
| test('it processes php tags in blade content', function (): void { | ||
| $bladeContent = '# Guideline | ||
|
|
||
| Example code: | ||
|
|
||
| <?php | ||
| echo "Hello World"; | ||
| ?>'; | ||
|
|
||
| file_put_contents($this->testBladePath, $bladeContent); | ||
|
|
||
| $resource = new ThirdPartyResource($this->guidelineAssist, 'test/package', $this->testBladePath); | ||
| $response = $resource->handle(); | ||
|
|
||
| expect($response)->isToolResult() | ||
| ->toolTextContains('<?php') | ||
| ->toolTextContains('echo "Hello World"'); | ||
| }); | ||
|
|
||
| test('it processes boost snippets', function (): void { | ||
| $bladeContent = '# Guideline | ||
|
|
||
| @boostsnippet(\'example\', \'php\') | ||
| function example() { | ||
| return true; | ||
| } | ||
| @endboostsnippet'; | ||
|
|
||
| file_put_contents($this->testBladePath, $bladeContent); | ||
|
|
||
| $resource = new ThirdPartyResource($this->guidelineAssist, 'test/package', $this->testBladePath); | ||
| $response = $resource->handle(); | ||
|
|
||
| expect($response)->isToolResult() | ||
| ->toolTextContains('<code-snippet name="example" lang="php">') | ||
| ->toolTextContains('function example()'); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.