Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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,78 @@
/*---------------------------------------------------------------------------------------------
* 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 setLevel request.");
}
if (StringUtils.isBlank(request.getLevel())) {
throw new IllegalStateException("No logging level in request.");
}
String loggingLevelString = request.getLevel();
LoggingLevel loggingLevel = LoggingLevel.fromCode(loggingLevelString);
if (loggingLevel == null) {
throw new IllegalStateException("Error logging level in request.");
}
// 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,98 @@
/*---------------------------------------------------------------------------------------------
* 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;

/**
* 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.
*/
public int level() {
return this.level;
}

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

/**
* Reverse lookup by code (ignore case).
*
* @param code The external code
* @return Corresponding enum or {@code null}
*/
public static LoggingLevel fromCode(String code) {
if (code == null) return null;
for (LoggingLevel level : values()) {
if (level.code.equalsIgnoreCase(code)) {
return level;
}
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ 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.
*/
LOGGING_SET_LEVEL("logging/setLevel");

private final String code;

Expand Down