|
2 | 2 |
|
3 | 3 | import java.util.Map; |
4 | 4 |
|
| 5 | +import org.slf4j.Logger; |
| 6 | +import org.slf4j.LoggerFactory; |
5 | 7 | import org.springaicommunity.mcp.annotation.McpElicitation; |
6 | 8 | import org.springaicommunity.mcp.annotation.McpLogging; |
7 | 9 | import org.springaicommunity.mcp.annotation.McpProgress; |
8 | 10 | import org.springaicommunity.mcp.annotation.McpSampling; |
9 | 11 | import org.springframework.stereotype.Service; |
10 | 12 |
|
11 | 13 | import io.modelcontextprotocol.spec.McpSchema; |
| 14 | +import io.modelcontextprotocol.spec.McpSchema.CreateMessageRequest; |
12 | 15 | import io.modelcontextprotocol.spec.McpSchema.CreateMessageResult; |
13 | | -import io.modelcontextprotocol.spec.McpSchema.ElicitRequest; |
14 | 16 | import io.modelcontextprotocol.spec.McpSchema.ElicitResult; |
15 | 17 | import io.modelcontextprotocol.spec.McpSchema.LoggingMessageNotification; |
| 18 | +import io.modelcontextprotocol.spec.McpSchema.ProgressNotification; |
16 | 19 |
|
17 | 20 | @Service |
18 | 21 | public class ClientMcpHandlers { |
19 | 22 |
|
| 23 | + private static final Logger logger = LoggerFactory.getLogger(ClientMcpHandlers.class); |
| 24 | + |
20 | 25 | @McpProgress(clientId = "server1") |
21 | | - public void progress(McpSchema.ProgressNotification progressNotification) { |
22 | | - System.out.println("MCP PROGRESS: [" + progressNotification.progressToken() + "] progress: " |
23 | | - + progressNotification.progress() + " total: " + progressNotification.total() + " message: " |
24 | | - + progressNotification.message()); |
| 26 | + public void progressHandler(ProgressNotification progressNotification) { |
| 27 | + logger.info("MCP PROGRESS: [{}] progress: {} total: {} message: {}", |
| 28 | + progressNotification.progressToken(), progressNotification.progress(), |
| 29 | + progressNotification.total(), progressNotification.message()); |
25 | 30 | } |
26 | 31 |
|
27 | 32 | @McpLogging |
28 | | - public void logging(LoggingMessageNotification loggingMessage) { |
29 | | - System.out.println("MCP LOGGING: [" + loggingMessage.level() + "] " + loggingMessage.data()); |
| 33 | + public void loggingHandler(LoggingMessageNotification loggingMessage) { |
| 34 | + logger.info("MCP LOGGING: [{}] {}", loggingMessage.level(), loggingMessage.data()); |
30 | 35 | } |
31 | 36 |
|
32 | 37 | @McpSampling |
33 | | - public CreateMessageResult sampling(McpSchema.CreateMessageRequest llmRequest) { |
| 38 | + public CreateMessageResult samplingHandler(CreateMessageRequest llmRequest) { |
| 39 | + |
| 40 | + logger.info(" MCP SAMPLING REQUEST: {}", llmRequest); |
| 41 | + |
34 | 42 | String userPrompt = ((McpSchema.TextContent) llmRequest.messages().get(0).content()).text(); |
| 43 | + |
35 | 44 | String modelHint = llmRequest.modelPreferences().hints().get(0).name(); |
| 45 | + |
36 | 46 | return CreateMessageResult.builder() |
37 | 47 | .content(new McpSchema.TextContent("Response " + userPrompt + " with model hint " + modelHint)) |
38 | 48 | .build(); |
39 | 49 | }; |
40 | 50 |
|
41 | 51 | @McpElicitation |
42 | | - public ElicitResult elicit(ElicitRequest request) { |
| 52 | + public ElicitResult elicitationHandler(McpSchema.ElicitRequest request) { |
| 53 | + logger.info("MCP ELICITATION REQUEST: {}", request); |
| 54 | + |
43 | 55 | return new ElicitResult(ElicitResult.Action.ACCEPT, Map.of("message", request.message())); |
44 | 56 | } |
45 | 57 |
|
|
0 commit comments