Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
lwphk opened this issue Apr 17, 2025 · 0 comments
Labels

Comments

@lwphk
Copy link

lwphk commented Apr 17, 2025

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

@lwphk lwphk closed this as completed Apr 19, 2025
@lwphk lwphk reopened this Apr 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants