-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Enhancement Description
Hello, guys!
First, thanks (and congrats) for the great work on FastMCP!
Since @jlowin’s PR #1294, servers are now allowed to send metadata in the _meta field to clients.
I’d like to propose (and possibly implement) support for the opposite direction: allowing clients to send _meta arguments to the server.
Use Case
Agents sometimes need to send data during tool calls that don’t qualify as function arguments or HTTP headers. This information could be, for example, user preferences and might determine how tools (and other resources such as prompts) are processed in the server.
In any case, the protocol specification does not forbid MCP clients from sending _meta to MCP servers, so I believe this wouldn't be a bad design decision.
Are there any alternative solutions you've considered?
I’ve considered using HTTP request headers, but I don’t think that would cover all use cases and security necessities.
Proposed Implementation
Since FastMCP relies on SDK's ClientSession.call_tool
interface, it would be required to directly use ClientSession.send_request
(unless _meta
is also exposed in the SDK)
async def call_tool_mcp(
self,
name: str,
arguments: dict[str, Any],
progress_handler: ProgressHandler | None = None,
timeout: datetime.timedelta | float | int | None = None,
meta: dict | None = None # <-- Expose meta in the public interface
) -> mcp.types.CallToolResult:
if isinstance(timeout, int | float):
timeout = datetime.timedelta(seconds=timeout)
# Since self.session.call_tool doesn't expose meta, it would be required to directly use self.session.send_request
result = await self.session.send_request(
types.ClientRequest(
types.CallToolRequest(
method="tools/call",
params=types.CallToolRequestParams(
name=name,
arguments=arguments,
meta=meta <-- Pass metadata down to the MCP SDK
),
)
),
types.CallToolResult,
request_read_timeout_seconds=read_timeout_seconds,
progress_callback=progress_callback,
)
return result