Skip to content

Feat/resource meta - #258

Open
AshishJii wants to merge 2 commits into
WordPress:trunkfrom
AshishJii:feat/resource-meta
Open

Feat/resource meta#258
AshishJii wants to merge 2 commits into
WordPress:trunkfrom
AshishJii:feat/resource-meta

Conversation

@AshishJii

Copy link
Copy Markdown

What?

Closes #245

Preserve the MCP _meta field when building resources/read response 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 _meta field for arbitrary client-side hints. Previously, ResourcesHandler::create_content_dto() never extracted _meta from 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 _meta from the raw content item and forward it into both BlobResourceContents::fromArray() and TextResourceContents::fromArray().

The is_array() guard ensures a callback that returns a non-array _meta value still produces a well-typed null rather 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

  1. Check out this branch.
  2. Start the test environment: npm run wp-env:test -- start
  3. Run the full PHPUnit suite: npm run test:php
  4. Confirm output ends with OK (1011 tests, 3901 assertions) and no failures.

Copilot AI review requested due to automatic review settings July 27, 2026 15:14
@github-actions

Copy link
Copy Markdown

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: AshishJii <ashishjii@git.wordpress.org>
Co-authored-by: Utsav-Ladani <utsavladani@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 _meta from raw resource content items into TextResourceContents::fromArray() and BlobResourceContents::fromArray().
  • Add fixture resources that return _meta for both text and blob contents.
  • Add unit tests verifying _meta is preserved end-to-end for resources/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

codecov Bot commented Jul 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.95%. Comparing base (4d19d22) to head (79a74c6).

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           
Flag Coverage Δ
unit 87.95% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

resources/read strips the _meta field from resource contents

2 participants