-
Notifications
You must be signed in to change notification settings - Fork 329
[FEL] add logging/setLevel method in MCP server #291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
CodeCasterX
merged 13 commits into
ModelEngine-Group:3.5.x
from
relat-ivity:mcp-handler
Sep 18, 2025
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
09e95be
[FEL] add a handler to the MCP server for handling logging/setLevel r…
relat-ivity 6abbf99
增加RFC-5424协议链接
relat-ivity 63fd3f1
修改LoggingLevel注释
relat-ivity 5c9eb6d
修改LoggingSetLevelHandler注释
relat-ivity fabecf0
修改代码格式
relat-ivity f13ec82
LoggingLevel增加int类型的level属性
relat-ivity 8658983
修改LoggingSetLevelHandler依赖
relat-ivity fa2e800
删除LoggingSetLevelHandler多余import
relat-ivity c5cf514
添加LoggingLevel的默认值,修改注释
relat-ivity 4916f4f
LoggingLevel文档格式化
relat-ivity df80fa0
"logging/setLevel"命名格式TODO
relat-ivity 3a2c0a8
LoggingLevel注释修改
relat-ivity 2841089
LoggingLevel注解逻辑修改
relat-ivity File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...-server/src/main/java/modelengine/fel/tool/mcp/server/handler/LoggingSetLevelHandler.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | ||
relat-ivity marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * 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; | ||
| } | ||
| } | ||
| } | ||
113 changes: 113 additions & 0 deletions
113
.../services/tool-mcp-common/src/main/java/modelengine/fel/tool/mcp/entity/LoggingLevel.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) { | ||
CodeCasterX marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (code == null) { | ||
| return LoggingLevel.getDefault(); | ||
| } | ||
| for (LoggingLevel level : values()) { | ||
| if (level.code.equalsIgnoreCase(code)) { | ||
| return level; | ||
| } | ||
| } | ||
| return LoggingLevel.getDefault(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.