Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import modelengine.fel.tool.mcp.server.handler.PingHandler;
import modelengine.fel.tool.mcp.server.handler.ToolCallHandler;
import modelengine.fel.tool.mcp.server.handler.ToolListHandler;
import modelengine.fel.tool.mcp.server.handler.LoggingSetLevelHandler;
import modelengine.fel.tool.mcp.server.handler.UnsupportedMethodHandler;
import modelengine.fit.http.annotation.GetMapping;
import modelengine.fit.http.annotation.PostMapping;
Expand Down Expand Up @@ -77,6 +78,7 @@ public McpServerController(@Fit(alias = "json") ObjectSerializer serializer, Mcp
this.methodHandlers.put(Method.PING.code(), new PingHandler());
this.methodHandlers.put(Method.TOOLS_LIST.code(), new ToolListHandler(mcpServer));
this.methodHandlers.put(Method.TOOLS_CALL.code(), new ToolCallHandler(mcpServer, this.serializer));
this.methodHandlers.put(Method.LOGGING_SET_LEVEL.code(), new LoggingSetLevelHandler());

ThreadPoolScheduler channelDetectorScheduler = ThreadPoolScheduler.custom()
.corePoolSize(1)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) 2025 Huawei Technologies Co., Ltd. All rights reserved.
* This file is a part of the ModelEngine Project.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

package modelengine.fel.tool.mcp.server.handler;

import modelengine.fel.tool.mcp.entity.LoggingLevel;
import modelengine.fel.tool.mcp.server.MessageRequest;
import modelengine.fitframework.util.StringUtils;

import java.util.Collections;
import java.util.Map;

/**
* A handler for processing logging set level requests in the MCP server.
* This class extends {@link AbstractMessageHandler} and is responsible for handling
* {@link LoggingSetLevelRequest} messages.
*
* @author 黄可欣
* @since 2025-09-10
*/
public class LoggingSetLevelHandler extends AbstractMessageHandler<LoggingSetLevelHandler.LoggingSetLevelRequest> {
private static final Map<Object, Object> SET_LEVEL_RESULT = Collections.emptyMap();

/**
* Constructs a new instance of the LoggingSetLevelHandler class.
*/
public LoggingSetLevelHandler() {
super(LoggingSetLevelHandler.LoggingSetLevelRequest.class);
}

@Override
public Object handle(LoggingSetLevelHandler.LoggingSetLevelRequest request) {
if (request == null) {
throw new IllegalStateException("No logging set level request.");
}
if (StringUtils.isBlank(request.getLevel())) {
throw new IllegalStateException("No logging level in request.");
}
String loggingLevelString = request.getLevel();
LoggingLevel loggingLevel = LoggingLevel.fromCode(loggingLevelString);
// TODO change the logging level of corresponding session.
return SET_LEVEL_RESULT;
}

/**
* Represents a request to set the logging level in the MCP server.
* This request is handled by {@link LoggingSetLevelHandler} to set the logging level in the MCP server.
*
* @since 2025-09-10
*/
public static class LoggingSetLevelRequest extends MessageRequest {
private String level;

/**
* Gets the level of server logging.
*
* @return The level of server logging as a {@link String}.
*/
public String getLevel() {
return this.level;
}

/**
* Sets the level of server logging .
*
* @param level The level of server logging as a {@link String}.
*/
public void setLevel(String level) {
this.level = level;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) 2025 Huawei Technologies Co., Ltd. All rights reserved.
* This file is a part of the ModelEngine Project.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

package modelengine.fel.tool.mcp.entity;

import modelengine.fitframework.inspection.Nonnull;

/**
* Represents different logging level in MCP server, following the RFC-5424 severity scale.
*
* @author 黄可欣
* @see <a href="https://datatracker.ietf.org/doc/html/rfc5424#section-6.2.1">RFC 5424</a>
* @since 2025-09-10
*/
public enum LoggingLevel {
/**
* Detailed debugging information (function entry/exit points).
*/
DEBUG(0, "debug"),

/**
* General informational messages (operation progress updates).
*/
INFO(1, "info"),

/**
* Normal but significant events (configuration changes).
*/
NOTICE(2, "notice"),

/**
* Warning conditions (deprecated feature usage).
*/
WARNING(3, "warning"),

/**
* Error conditions (operation failures).
*/
ERROR(4, "error"),

/**
* Critical conditions (system component failures).
*/
CRITICAL(5, "critical"),

/**
* Action must be taken immediately (data corruption detected).
*/
ALERT(6, "alert"),

/**
* System is unusable (complete system failure).
*/
EMERGENCY(7, "emergency");

private final int level;
private final String code;

LoggingLevel(int level, String code) {
this.level = level;
this.code = code;
}

/**
* Returns the level number associated with the logging level.
*
* @return The number of the logging level as an {@code int}.
*/
public int level() {
return this.level;
}

/**
* Returns the code associated with the logging level.
*
* @return The code of the logging level as a {@link String}.
*/
public String code() {
return this.code;
}

/**
* Returns the default logging level which is INFO level.
*
* @return The default INFO logging level as a {@link LoggingLevel}.
*/
public static LoggingLevel getDefault() {
return LoggingLevel.INFO;
}

/**
* Return the corresponding {@link LoggingLevel} from the logging level code.
* If there is no corresponding logging level, return the default logging level.
*
* @param code The code of logging level as a {@link String}.
* @return The corresponding or default logging level as a {@link LoggingLevel}.
*/
@Nonnull
public static LoggingLevel fromCode(String code) {
if (code == null) {
return LoggingLevel.getDefault();
}
for (LoggingLevel level : values()) {
if (level.code.equalsIgnoreCase(code)) {
return level;
}
}
return LoggingLevel.getDefault();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ public enum Method {
/**
* Represents the notification method indicating a change in the list of tools.
*/
NOTIFICATION_TOOLS_CHANGED("notifications/tools/list_changed");
NOTIFICATION_TOOLS_CHANGED("notifications/tools/list_changed"),

/**
* Represents the method to set logging level.
* TODO The naming need to be standardized as snake_case.
*/
LOGGING_SET_LEVEL("logging/setLevel");

private final String code;

Expand Down