Repository navigation
[5.x] Let asset_folders_list filter to root folders #20464
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
Open
brandonkelly
wants to merge
2
commits into
5.x
Choose a base branch
from
bugfix/mcp-root-asset-folders
base: 5.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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,78 @@ | ||
| <?php | ||
|
|
||
| namespace crafttests\unit\mcp; | ||
|
|
||
| use Craft; | ||
| use craft\elements\User; | ||
| use craft\mcp\HttpTransportMiddleware; | ||
| use craft\mcp\ServerFactory; | ||
| use craft\models\VolumeFolder; | ||
| use craft\services\Mcp; | ||
| use craft\test\TestCase; | ||
| use crafttests\fixtures\VolumesFolderFixture; | ||
| use GuzzleHttp\Psr7\ServerRequest; | ||
| use Mcp\Server\Transport\StreamableHttpTransport; | ||
|
|
||
| /** Exercises the asset folder tools through the authenticated MCP server, so their input schemas apply. */ | ||
| class AssetFoldersCapabilityTest extends TestCase | ||
| { | ||
| private mixed $originalIdentity; | ||
|
|
||
| public function _fixtures(): array | ||
| { | ||
| return ['folders' => ['class' => VolumesFolderFixture::class]]; | ||
| } | ||
|
|
||
| protected function _before(): void | ||
| { | ||
| $this->originalIdentity = Craft::$app->getUser()->getIdentity(); | ||
| Craft::$app->getUser()->setIdentity(User::find()->admin()->one()); | ||
| } | ||
|
|
||
| protected function _after(): void | ||
| { | ||
| Craft::$app->getUser()->setIdentity($this->originalIdentity); | ||
| } | ||
|
|
||
| public function testListFiltersToRootFoldersForNullParentId(): void | ||
| { | ||
| Craft::$app->getAssets()->storeFolderRecord(new VolumeFolder([ | ||
| 'name' => 'Subfolder', | ||
| 'parentId' => 1000, | ||
| 'volumeId' => 1000, | ||
| 'path' => 'test volume 1/subfolder/', | ||
| ])); | ||
|
|
||
| $result = $this->callTool('asset_folders_list', ['criteria' => ['parentId' => null]]); | ||
|
|
||
| self::assertFalse($result['isError'] ?? true, json_encode($result)); | ||
| self::assertEqualsCanonicalizing([1000, 1001], array_column($result['structuredContent']['folders'], 'id')); | ||
| } | ||
|
|
||
| private function callTool(string $name, array $arguments): array | ||
| { | ||
| Craft::$app->get('mcp')->tokenScopes = [Mcp::SCOPE_READ]; | ||
| $container = Craft::$app->get('mcp')->getCapabilityContainer(); | ||
| $request = new ServerRequest('POST', 'http://localhost/mcp', [ | ||
| 'Content-Type' => 'application/json', | ||
| 'Accept' => 'application/json, text/event-stream', | ||
| 'MCP-Protocol-Version' => '2026-07-28', | ||
| 'Mcp-Method' => 'tools/call', | ||
| 'Mcp-Name' => $name, | ||
| ], json_encode(['jsonrpc' => '2.0', 'id' => 1, 'method' => 'tools/call', 'params' => [ | ||
| 'name' => $name, | ||
| 'arguments' => $arguments, | ||
| '_meta' => [ | ||
| 'io.modelcontextprotocol/protocolVersion' => '2026-07-28', | ||
| 'io.modelcontextprotocol/clientCapabilities' => (object)[], | ||
| ], | ||
| ]])); | ||
| $response = $container->get(ServerFactory::class)->authenticated()->run(new StreamableHttpTransport( | ||
| request: $request, | ||
| middleware: $container->get(HttpTransportMiddleware::class)->forRequest($request), | ||
| )); | ||
| $response = json_decode((string)$response->getBody(), true); | ||
|
|
||
| return $response['result'] ?? $response; | ||
| } | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 52b6968: the test now calls
asset_folders_listthroughtools/callon the authenticated server, so the input schema applies. It fails both whenparentIdreverts to integer-only (-32602 … Expected 'integer', but received 'null') and when the:empty:mapping is removed (the subfolder is included).