Feat/resource meta - #258
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
There was a problem hiding this comment.
Pull request overview
This PR fixes MCP spec compliance in the adapter by preserving the optional _meta field on individual resources/read content items, ensuring metadata returned by resource callbacks is carried through into the serialized response.
Changes:
- Forward
_metafrom raw resource content items intoTextResourceContents::fromArray()andBlobResourceContents::fromArray(). - Add fixture resources that return
_metafor both text and blob contents. - Add unit tests verifying
_metais preserved end-to-end forresources/read.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| includes/Handlers/Resources/ResourcesHandler.php | Extracts _meta from content items and forwards it into resource content DTO creation. |
| tests/phpunit/Fixtures/DummyAbility.php | Adds two test resource abilities that return _meta on text/blob content items. |
| tests/phpunit/Unit/Handlers/ResourcesHandlerReadTest.php | Adds coverage asserting _meta is preserved in ReadResourceResult contents for text and blob responses. |
| tests/phpunit/Unit/Core/McpAdapterConfigTest.php | Updates expected auto-discovered resources list to include the new meta test resources. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## trunk #258 +/- ##
=========================================
Coverage 87.94% 87.95%
- Complexity 1257 1259 +2
=========================================
Files 53 53
Lines 4066 4069 +3
=========================================
+ Hits 3576 3579 +3
Misses 490 490
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
What?
Closes #245
Preserve the MCP
_metafield when buildingresources/readresponse contents, so metadata returned by resource ability callbacks is passed through to MCP clients.Why?
The MCP spec allows any resource content object to carry an optional
_metafield for arbitrary client-side hints. Previously,ResourcesHandler::create_content_dto()never extracted_metafrom the raw content item array, meaning it was silently dropped before the DTO was constructed and the response was serialised. This broke spec compliance and caused clients to lose metadata they depended on.How?
In
ResourcesHandler::create_content_dto(), extract_metafrom the raw content item and forward it into bothBlobResourceContents::fromArray()andTextResourceContents::fromArray().The
is_array()guard ensures a callback that returns a non-array_metavalue still produces a well-typednullrather than crashing the DTO constructor.Use of AI Tools
AI assistance: Yes
Tool(s): Antigravity
Model(s): Claude Sonnet 4.6
Used for: Generating PHPUnit test stubs and drafting this PR description. The core bug fix in
ResourcesHandler.php, fixture design, and final review were done by me.Testing Instructions
npm run wp-env:test -- startnpm run test:phpOK (1011 tests, 3901 assertions)and no failures.