Skip to content

Expose _meta in ClientSession methods #1216

@samchenatti

Description

@samchenatti

Description

Hello!

I'd like to request exposing the argument _meta in the interface ClientSession.call_tool.

If approved, I could implement the feature myself.

Use case for the feature
When calling a tool my, MCP Client needs to send metadata to the MCP Server, such user preferences and other stuff that might affect how the tools works. The LLM shouldn't be aware of such data, so this information doesn't classify as tool arguments.

Taking a look at the protocol documentation it seems like using the _meta field would be appropriated for this scenario.

Demo of how code might look when using the feature
Currently ClientSession.call_tool signature is as follows:

async def call_tool(
        self,
        name: str,
        arguments: dict[str, Any] | None = None,
        read_timeout_seconds: timedelta | None = None,
        progress_callback: ProgressFnT | None = None,
    ) -> types.CallToolResult:

I'm suggesting the following:

    async def call_tool(
        self,
        name: str,
        arguments: dict[str, Any] | None = None,
        read_timeout_seconds: timedelta | None = None,
        progress_callback: ProgressFnT | None = None,
        meta: dict | None # <- Exposes meta in the public interface
    ) -> types.CallToolResult:
        """Send a tools/call request with optional progress callback support."""

        result = await self.send_request(
            types.ClientRequest(
                types.CallToolRequest(
                    method="tools/call",
                    params=types.CallToolRequestParams(
                        name=name,
                        arguments=arguments,
                        meta=meta or {} # <- include meta in the JSONRPC request arguments
                    ),
                )
            ),
            types.CallToolResult,
            request_read_timeout_seconds=read_timeout_seconds,
            progress_callback=progress_callback,
        )

Since _meta is already exposed by CallToolRequestParams it would be a simple change.

Alternatives
Currently it is possible to achieve the same goal if I call ClientSession.send_request directly from my MCP Client, but other projects that make use of this Python SDK heavily relies in the ClientSession.call_tool interface, such as FastMCP and langchain_mcp_adapters.

If this feature is implemented here, it would be easy for them to expose the _meta argument for their users aswell.

Other interfaces could benefit from the same change
I'm focusing in call_tool since it directly affects me, but exposing _meta in other public interfaces could be a good idea.

References

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions