feat(mcp): Add MCP logging support and refactor code

- Add logging consumer to MCP client specification
- Implement logging notifications for sampling start/finish in WeatherService
- Refactor WeatherService to use McpToolUtils and StringBuilder

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
This commit is contained in:
Christian Tzolov
2025-04-10 20:27:50 +02:00
parent 7e04dc20f9
commit e8a266467c
3 changed files with 46 additions and 28 deletions

View File

@@ -68,6 +68,11 @@ public class McpClientApplication {
McpSyncClientCustomizer samplingCustomizer(Map<String, ChatClient> chatClients) {
return (name, mcpClientSpec) -> {
mcpClientSpec = mcpClientSpec.loggingConsumer(logingMessage -> {
System.out.println("MCP LOGGING: [" + logingMessage.level() + "] " + logingMessage.data());
});
mcpClientSpec.sampling(llmRequest -> {
var userPrompt = ((McpSchema.TextContent) llmRequest.messages().get(0).content()).text();
String modelHint = llmRequest.modelPreferences().hints().get(0).name();