How to get the _meta parameter in tools/call

Image

Comment From: quaff

See https://docs.spring.io/spring-ai/reference/1.1-SNAPSHOT/api/mcp/mcp-annotations-special-params.html#_mcpprogresstoken

Comment From: tzolov

@cjpnice , @quaff Here are the general rules (available in 1.1.0-SNAPSHOT and 1.1.0-M1):

MCP Server Side

  • If using the dedicated mcp-annotations like @McpTool, @McpPrompt ... then you can either
  • (1) add the McpMeta argument that provides access to metadata from MCP requests, notifications or
  • (2) use the @McpProgressTooken to obtain the MCP request progress token.

  • If you are using the @Tool then consider adding the ToolContext argument. Later is auto-populated with the MCP request meta.

MCP Client Side

  • On the Spring AI client side use the ChatClient's .toolContext(...) to pass the metadata including the progressToken:

```java ChatClient chatClient = ...

String response = chatClient .prompt("Tell me more about the customer with ID 42") .toolContext(Map.of("progressToken", "my-progress-token")) .call() .content(); ``` Find more info at the Tool Context to MCP Meta Converter.

Comment From: DannySortino

@tzolov I actually have a question on the above suggestion for the server side... I was struggling to figure out why i was not getting my progressToken being passed from my client side to server side. I checked the JSONRPC and it looked good, but when my toolContext was passed through, it had ONLY the exchange key in it.

I looked at the implementation and see that in McpToolUtils.toSharedSyncToolSpecification (looking at 1.1.0-M2) when it does the toolCallback.call it ignores all the _meta passed in from the request, and just creates a new ToolContext for the MCP_EXCHANGE_KEY. I would have thought this would combine the fields from the _meta and the EXCHANGE_KEY to allow passing through the fields to the toolContext.

Comment From: tzolov

@DannySortino thanks for the feedback. This sounds like an issue. I’ll have a look and if necessary fix it for M3

Comment From: tzolov

@DannySortino i don't have much time to look at this today so this would likely slip to M4