Skip to content

Commit 32863cd

Browse files
committed
Merge branch '3.5.x'
2 parents 4b9b939 + f6e10f6 commit 32863cd

File tree

4 files changed

+197
-1
lines changed

4 files changed

+197
-1
lines changed

framework/fel/java/plugins/tool-mcp-server/src/main/java/modelengine/fel/tool/mcp/server/McpServerController.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import modelengine.fel.tool.mcp.server.handler.PingHandler;
1717
import modelengine.fel.tool.mcp.server.handler.ToolCallHandler;
1818
import modelengine.fel.tool.mcp.server.handler.ToolListHandler;
19+
import modelengine.fel.tool.mcp.server.handler.LoggingSetLevelHandler;
1920
import modelengine.fel.tool.mcp.server.handler.UnsupportedMethodHandler;
2021
import modelengine.fit.http.annotation.GetMapping;
2122
import modelengine.fit.http.annotation.PostMapping;
@@ -77,6 +78,7 @@ public McpServerController(@Fit(alias = "json") ObjectSerializer serializer, Mcp
7778
this.methodHandlers.put(Method.PING.code(), new PingHandler());
7879
this.methodHandlers.put(Method.TOOLS_LIST.code(), new ToolListHandler(mcpServer));
7980
this.methodHandlers.put(Method.TOOLS_CALL.code(), new ToolCallHandler(mcpServer, this.serializer));
81+
this.methodHandlers.put(Method.LOGGING_SET_LEVEL.code(), new LoggingSetLevelHandler());
8082

8183
ThreadPoolScheduler channelDetectorScheduler = ThreadPoolScheduler.custom()
8284
.corePoolSize(1)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) 2025 Huawei Technologies Co., Ltd. All rights reserved.
3+
* This file is a part of the ModelEngine Project.
4+
* Licensed under the MIT License. See License.txt in the project root for license information.
5+
*--------------------------------------------------------------------------------------------*/
6+
7+
package modelengine.fel.tool.mcp.server.handler;
8+
9+
import modelengine.fel.tool.mcp.entity.LoggingLevel;
10+
import modelengine.fel.tool.mcp.server.MessageRequest;
11+
import modelengine.fitframework.util.StringUtils;
12+
13+
import java.util.Collections;
14+
import java.util.Map;
15+
16+
/**
17+
* A handler for processing logging set level requests in the MCP server.
18+
* This class extends {@link AbstractMessageHandler} and is responsible for handling
19+
* {@link LoggingSetLevelRequest} messages.
20+
*
21+
* @author 黄可欣
22+
* @since 2025-09-10
23+
*/
24+
public class LoggingSetLevelHandler extends AbstractMessageHandler<LoggingSetLevelHandler.LoggingSetLevelRequest> {
25+
private static final Map<Object, Object> SET_LEVEL_RESULT = Collections.emptyMap();
26+
27+
/**
28+
* Constructs a new instance of the LoggingSetLevelHandler class.
29+
*/
30+
public LoggingSetLevelHandler() {
31+
super(LoggingSetLevelHandler.LoggingSetLevelRequest.class);
32+
}
33+
34+
@Override
35+
public Object handle(LoggingSetLevelHandler.LoggingSetLevelRequest request) {
36+
if (request == null) {
37+
throw new IllegalStateException("No logging set level request.");
38+
}
39+
if (StringUtils.isBlank(request.getLevel())) {
40+
throw new IllegalStateException("No logging level in request.");
41+
}
42+
String loggingLevelString = request.getLevel();
43+
LoggingLevel loggingLevel = LoggingLevel.fromCode(loggingLevelString);
44+
// TODO change the logging level of corresponding session.
45+
return SET_LEVEL_RESULT;
46+
}
47+
48+
/**
49+
* Represents a request to set the logging level in the MCP server.
50+
* This request is handled by {@link LoggingSetLevelHandler} to set the logging level in the MCP server.
51+
*
52+
* @since 2025-09-10
53+
*/
54+
public static class LoggingSetLevelRequest extends MessageRequest {
55+
private String level;
56+
57+
/**
58+
* Gets the level of server logging.
59+
*
60+
* @return The level of server logging as a {@link String}.
61+
*/
62+
public String getLevel() {
63+
return this.level;
64+
}
65+
66+
/**
67+
* Sets the level of server logging .
68+
*
69+
* @param level The level of server logging as a {@link String}.
70+
*/
71+
public void setLevel(String level) {
72+
this.level = level;
73+
}
74+
}
75+
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) 2025 Huawei Technologies Co., Ltd. All rights reserved.
3+
* This file is a part of the ModelEngine Project.
4+
* Licensed under the MIT License. See License.txt in the project root for license information.
5+
*--------------------------------------------------------------------------------------------*/
6+
7+
package modelengine.fel.tool.mcp.entity;
8+
9+
import modelengine.fitframework.inspection.Nonnull;
10+
11+
/**
12+
* Represents different logging level in MCP server, following the RFC-5424 severity scale.
13+
*
14+
* @author 黄可欣
15+
* @see <a href="https://datatracker.ietf.org/doc/html/rfc5424#section-6.2.1">RFC 5424</a>
16+
* @since 2025-09-10
17+
*/
18+
public enum LoggingLevel {
19+
/**
20+
* Detailed debugging information (function entry/exit points).
21+
*/
22+
DEBUG(0, "debug"),
23+
24+
/**
25+
* General informational messages (operation progress updates).
26+
*/
27+
INFO(1, "info"),
28+
29+
/**
30+
* Normal but significant events (configuration changes).
31+
*/
32+
NOTICE(2, "notice"),
33+
34+
/**
35+
* Warning conditions (deprecated feature usage).
36+
*/
37+
WARNING(3, "warning"),
38+
39+
/**
40+
* Error conditions (operation failures).
41+
*/
42+
ERROR(4, "error"),
43+
44+
/**
45+
* Critical conditions (system component failures).
46+
*/
47+
CRITICAL(5, "critical"),
48+
49+
/**
50+
* Action must be taken immediately (data corruption detected).
51+
*/
52+
ALERT(6, "alert"),
53+
54+
/**
55+
* System is unusable (complete system failure).
56+
*/
57+
EMERGENCY(7, "emergency");
58+
59+
private final int level;
60+
private final String code;
61+
62+
LoggingLevel(int level, String code) {
63+
this.level = level;
64+
this.code = code;
65+
}
66+
67+
/**
68+
* Returns the level number associated with the logging level.
69+
*
70+
* @return The number of the logging level as an {@code int}.
71+
*/
72+
public int level() {
73+
return this.level;
74+
}
75+
76+
/**
77+
* Returns the code associated with the logging level.
78+
*
79+
* @return The code of the logging level as a {@link String}.
80+
*/
81+
public String code() {
82+
return this.code;
83+
}
84+
85+
/**
86+
* Returns the default logging level which is INFO level.
87+
*
88+
* @return The default INFO logging level as a {@link LoggingLevel}.
89+
*/
90+
public static LoggingLevel getDefault() {
91+
return LoggingLevel.INFO;
92+
}
93+
94+
/**
95+
* Return the corresponding {@link LoggingLevel} from the logging level code.
96+
* If there is no corresponding logging level, return the default logging level.
97+
*
98+
* @param code The code of logging level as a {@link String}.
99+
* @return The corresponding or default logging level as a {@link LoggingLevel}.
100+
*/
101+
@Nonnull
102+
public static LoggingLevel fromCode(String code) {
103+
if (code == null) {
104+
return LoggingLevel.getDefault();
105+
}
106+
for (LoggingLevel level : values()) {
107+
if (level.code.equalsIgnoreCase(code)) {
108+
return level;
109+
}
110+
}
111+
return LoggingLevel.getDefault();
112+
}
113+
}

framework/fel/java/services/tool-mcp-common/src/main/java/modelengine/fel/tool/mcp/entity/Method.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,13 @@ public enum Method {
4040
/**
4141
* Represents the notification method indicating a change in the list of tools.
4242
*/
43-
NOTIFICATION_TOOLS_CHANGED("notifications/tools/list_changed");
43+
NOTIFICATION_TOOLS_CHANGED("notifications/tools/list_changed"),
44+
45+
/**
46+
* Represents the method to set logging level.
47+
* TODO The naming need to be standardized as snake_case.
48+
*/
49+
LOGGING_SET_LEVEL("logging/setLevel");
4450

4551
private final String code;
4652

0 commit comments

Comments
 (0)