sdk-python icon indicating copy to clipboard operation
sdk-python copied to clipboard

feat: add meta field support to MCP tool results

Open vamgan opened this issue 3 weeks ago • 1 comments

Description

Add support for the _meta field in MCP tool results to enable MCP servers to pass arbitrary metadata alongside tool outputs. This allows tracking of token usage, performance metrics, and other business-specific information.

Changes:

  • Add meta field to MCPToolResult TypedDict
  • Update _handle_tool_result to extract and pass through meta field
  • Add comprehensive tests for meta field handling
  • Handle MCP SDK's _meta field aliasing via model_dump()

Related Issues

Closes #881

Documentation PR

Type of Change

New feature

Testing

How have you tested the change? Verify that the changes do not break functionality or introduce warnings in consuming repositories: agents-docs, agents-tools, agents-cli

  • [x] I ran hatch run prepare

Checklist

  • [ ] I have read the CONTRIBUTING document
  • [x] I have added any necessary tests that prove my fix is effective or my feature works
  • [ ] I have updated the documentation accordingly
  • [ ] I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • [x] My changes generate no new warnings
  • [ ] Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

vamgan avatar Nov 22 '25 01:11 vamgan

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests.

:loudspeaker: Thoughts on this report? Let us know!

codecov[bot] avatar Nov 24 '25 16:11 codecov[bot]