Skip to content

Can custom parameters of the context be added in MCP? Similar to "ToolCalling - ToolContext" #2784

Open
@lwphk

Description

@lwphk

Expected Behavior
MCP Server

 @Service
  public class MemberTool {
      @Tool(description = "Query the user's order")
      public Map memberOrderInfo(Long memberId, Long orderNo){
          //...
      }
  }

MCP client

 ChatClient.create(chatModel)
        .user("query my order by 100001")
        .mcpContext(Map.of("memberId", "10"))    //Expected Behavior 
        .call()
        .content();

org.springframework.ai.tool.ToolCallback
default String call(String toolInput, @Nullable ToolContext tooContext) {
        if (tooContext != null && !tooContext.getContext().isEmpty()) {
            throw new UnsupportedOperationException("Tool context is not supported!");
        }
        return call(toolInput);
}

org.springframework.ai.mcp.AsyncMcpToolCallback || SyncMcpToolCallback
@Override
    public String call(String functionInput) {
        Map<String, Object> arguments = ModelOptionsUtils.jsonToMap(functionInput);
        // Expected Behavior  , If there is a duplicate of "memberId", "mcpContext" will be given the highest priority
        arguments.putAll(mcpContext);  
        return this.asyncMcpClient.callTool(new CallToolRequest(this.getToolDefinition().name(), arguments))
            .map(response -> ModelOptionsUtils.toJsonString(response.content()))
            .block();
}

Of course, the solution won't be as simple as mentioned above. This is also related to the parameter extraction and transformation of the "ai model". Or there could be other ways to pass additional parameters each time interacting with the "MCP Server". This might conflict with the "MCP" protocol

MCP Server

 @Service
  public class MemberTool {
      @Tool(description = "Query the user's order")
      public Map memberOrderInfo(Long memberId, Long orderNo){
          // Long other = xxxContext.get("other")
      }
  }

I know this function can be achieved through "Tool Calling".
Service interfaces are provided among project teams through MCP. It is necessary to customize the Settings of sensitive parameters to prevent users from tampering through "ai model prompt"
If MCP could achieve the same function, it would be a very good solution.
Looking forward to your reply. Thank

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions