79683784

Date: 2025-06-29 13:54:32
Score: 4.5
Natty:
Report link

I’m encountering the same problem when trying to pass data from an MCP client to an MCP server using Spring AI. I haven’t found a solution yet — any help or direction would be greatly appreciated!

MCP Client Code:

@Service
public class ChatbotService {
    protected Logger logger = LoggerFactory.getLogger(getClass());

    private ChatClient chatClient;

    public ChatbotService(ChatClient chatClient) {
        this.chatClient = chatClient;
        logger.info("ChatbotService is ready");
    }

    String chat(String question, String apiKey ) {
        return chatClient
                .prompt()
                .user(question)
                .toolContext(Map.of("apiKey", apiKey))
                .call()
                .content();
    }
}

MCP Server Code:

@Tool(name = "getUserPermissionsByUsername", description = "Get user permissions by username. This tool is used to retrieve the permissions of a user by their username. Must supply the username and an apiKey for authentication.")
private List<String> getUserPermissionsByUsername(@ToolParam(description = "User Name") String username, String apiKey, ToolContext toolContext) {
    try {
        //apiKey not passed at String or at toolContext
        return userProxy.getUserPermissionsByUsername(username);
    } catch (Exception e) {
        return new ArrayList<>();
    }
}
Reasons:
  • Blacklisted phrase (1): appreciated
  • Blacklisted phrase (1): any help
  • RegEx Blacklisted phrase (3): any help or direction would be greatly appreciated
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Raz