Skip to content

Conversation

ishan121028
Copy link

This is a fix for the bug 1224 and implements the parameter and method for the metadata that is passed for cases when the info is to be hidden from LLMs.

Motivation and Context

1224

How Has This Been Tested?

Yes I have tested with

Breaking Changes

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

@ishan121028 ishan121028 requested review from a team and dsp-ant September 17, 2025 20:28
@ishan121028
Copy link
Author

@dsp-ant, @LucaButBoring Request you to review this very small change this is my first contribution just exploring the repo as of now.

self,
name: str,
arguments: dict[str, Any] | None = None,
meta: dict[str, Any] | None = None,
Copy link
Contributor

Choose a reason for hiding this comment

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

Move this to the end for backwards-compatibility — we should have probably added a , *, before, but I'll leave that up to a maintainer to decide if we should start doing that or not (it would also be a breaking change if we started doing that now).

Copy link
Author

Choose a reason for hiding this comment

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

Done, except the second thing would wait on that for the same

@LucaButBoring
Copy link
Contributor

LGTM after changes (I do not have merge permissions, however)

@samchenatti
Copy link

Seems related to #1231

@felixweinberger felixweinberger self-assigned this Sep 30, 2025
@felixweinberger felixweinberger added the needs maintainer action Potentially serious issue - needs proactive fix and maintainer attention label Sep 30, 2025
@felixweinberger felixweinberger added this to the META Improvements milestone Sep 30, 2025
@ishan121028
Copy link
Author

@dsp-ant Are there any changes required in this, would be great if we can merge this.

Copy link
Contributor

@maxisbey maxisbey left a comment

Choose a reason for hiding this comment

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

I've added a few requested changes. Please also add functionality unit testing, currently the unit tests only test the Pydantic models themselves.

Comment on lines +503 to +511
def test_call_tool_method_signature():
"""Test that call_tool method accepts meta parameter in its signature."""

signature = inspect.signature(ClientSession.call_tool)

assert "meta" in signature.parameters, "call_tool method should have 'meta' parameter"

meta_param = signature.parameters["meta"]
assert meta_param.default is None, "meta parameter should default to None"
Copy link
Contributor

@maxisbey maxisbey Oct 6, 2025

Choose a reason for hiding this comment

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

Remove this test, it shouldn't be needed :)

This is a fragile test which relies entirely on implementation details rather than functionality.

This should be tested via other unit tests, such as one that passes a "meta" parameter. If "meta" didn't exist then that test would fail. Similarly, there should be a unit tests which test the default case instead of doing inspection on the signature.


def test_call_tool_request_params_construction():
"""Test that CallToolRequestParams can be constructed with metadata."""
from mcp.types import CallToolRequestParams, RequestParams
Copy link
Contributor

Choose a reason for hiding this comment

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

move imports to top of file


def test_metadata_serialization():
"""Test that metadata is properly serialized with _meta alias."""
from mcp.types import CallToolRequest, CallToolRequestParams, RequestParams
Copy link
Contributor

Choose a reason for hiding this comment

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

move imports to top of file

return str(self.request_context.request_id)

@property
def request_meta(self) -> dict[str, Any]:
Copy link
Contributor

Choose a reason for hiding this comment

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

add unit tests for this

types.EmptyResult,
)

async def call_tool(
Copy link
Contributor

Choose a reason for hiding this comment

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

add a unit test which tests that the metadata is correctly sent to the server. Currently the unit tests only test the metadata pydantic models and not actual functinoality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs maintainer action Potentially serious issue - needs proactive fix and maintainer attention
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants