-
Notifications
You must be signed in to change notification settings - Fork 41
Fix metadata appearing in tool response content #72
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
Conversation
…re response creation
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.
Pull Request Overview
This PR fixes a bug where internal _metadata fields were being exposed in client-facing tool response content. The fix ensures metadata is extracted and removed from the result before it's added to the response content, preventing it from appearing in both structuredContent and the JSON-encoded content[0].text field.
- Reordered metadata extraction to occur before result is added to response content
- Added explicit removal of
_metadatafrom result usingunset() - Preserved metadata at response top level where it's properly handled by
RequestRouter
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
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. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## trunk #72 +/- ##
============================================
+ Coverage 68.94% 68.95% +0.01%
Complexity 821 821
============================================
Files 46 46
Lines 3037 3038 +1
============================================
+ Hits 2094 2095 +1
Misses 943 943
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Thanks for explaining! This is good to go, then!
Why
Internal
_metadatafields were appearing in the client-facing response, showing up in both thestructuredContentobject and the JSON-encodedcontent[0].textfield.This metadata is intended only for internal observability tracking and should not be exposed to MCP clients.
What
_metadatafrom the result before adding it to response content/structuredContentunset($result['_metadata'])to ensure metadata is removed from the resultToolsHandler::call_tool()to:This ensures metadata is only present at the top level of the response (where
RequestRouterremoves it) and never reaches the client.