-
Notifications
You must be signed in to change notification settings - Fork 13.1k
[ISSUE #13497]feat: return mcpId when create mcpserver #13561
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
Open
jujiale
wants to merge
8
commits into
alibaba:develop
Choose a base branch
from
jujiale:feat-mcpId-return
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
48fa44a
feat: return mcpId when create mcpserver
jujiale 8b28fda
Merge branch 'alibaba:develop' into feat-mcpId-return
jujiale b3b2563
fix: modify the method name
jujiale 9001c60
fix: modify the test method name
jujiale cf201dc
fix: modify the ci problem
jujiale 95b468f
fix: adjust the createMcpServerWithSpec test method
jujiale dcf0051
fix: adjust the line char length for ci pass
jujiale 3bd4736
fix: enhance ut for mcpserver
jujiale 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
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
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 |
---|---|---|
|
@@ -82,4 +82,14 @@ void testJoin() { | |
collection.add("bar"); | ||
assertEquals("foo,bar", join(collection, ",")); | ||
} | ||
|
||
@Test | ||
void testUUIDPattern() { | ||
// match 8-4-4-4-12 uuid pattern | ||
assertTrue(StringUtils.isUUIDString("123e4567-e89b-12d3-a456-426655440000")); | ||
// not match 8-4-4-4-12 uuid pattern | ||
assertFalse(StringUtils.isUUIDString("123e54567-e89b5-12d35-a4565-426655440000")); | ||
// not match hexadecimal and '-' char | ||
assertFalse(StringUtils.isUUIDString("@23e4567+e89b-12d3-a456-426655440000")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
} |
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
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
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 |
---|---|---|
|
@@ -65,9 +65,10 @@ Page<McpServerBasicInfo> listMcpServers(String namespaceId, String mcpName, Stri | |
* @param serverSpecification mcp server specification, see {@link McpServerBasicInfo} | ||
* @param toolSpecification mcp server included tools, see {@link McpTool}, optional | ||
* @param endpointSpecification mcp server endpoint specification, see {@link McpEndpointSpec}, optional | ||
* @return mcp server id of the new mcp server | ||
* @throws NacosException any exception during handling | ||
*/ | ||
void createMcpServer(String namespaceId, McpServerBasicInfo serverSpecification, | ||
String createMcpServer(String namespaceId, McpServerBasicInfo serverSpecification, | ||
Comment on lines
+68
to
+71
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
McpToolSpecification toolSpecification, McpEndpointSpec endpointSpecification) throws NacosException; | ||
|
||
/** | ||
|
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
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
返回结果未处理异常情况导致潜在空指针风险
📋 问题详情
在createMcpServer方法中,直接返回mcpServerOperationService创建方法的结果,但未处理该方法可能抛出的异常。当服务层返回null时可能导致空指针异常,且未对异常场景进行错误码返回处理
💡 解决方案
需要增加对mcpId的空值检查,并处理异常场景返回错误信息:
有用意见👍 | 无用意见👎 | 错误意见❌
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not true, because if it return mcpId, it must have value
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
根据代码逻辑分析,
createMcpServer
方法的返回值mcpId
确实需要区分两种风险场景:异常场景:即使方法返回值不为空,但若方法内部出现异常(如数据库操作失败),需要捕获
NacosException
并返回错误码。当前方法签名声明了throws NacosException
,但未在调用处处理,可能导致未捕获异常抛出。空值场景:如果
createMcpServer
方法在某些情况下返回空字符串(例如服务端逻辑未正确生成ID但未抛异常),直接返回会导致前端接收空值。虽然您认为"must have value",但需要确认该方法是否严格保证非空返回。建议补充异常捕获逻辑,保持接口的健壮性:
这样既保证了异常场景的可控性,又保留了您的设计逻辑。是否需要空值检查取决于
createMcpServer
的实现规范,建议与服务层开发者确认方法的返回值约束。There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
evenif there occurs error inside method, the createMcpServer method have throw Exception, eventually, the client will get errorcode and errormsg
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jujiale 您的分析需要结合方法抛出异常的传播路径来判断:
异常传播逻辑
当前
createMcpServer
方法声明抛出NacosException
,但调用该方法的客户端(如Controller)若未捕获异常,异常会向上抛出。若未在Spring Boot的全局异常处理器(如@ControllerAdvice
)中捕获NacosException
,则会触发HTTP 500错误,无法返回结构化的错误响应(如包含errorCode
和message
的JSON)。您的方案需要确保全局异常处理已覆盖此场景。显式错误封装的优势
建议的
try-catch
方案能直接返回Result.fail()
结构化响应,即使存在全局异常处理,显式捕获可:若
createMcpServer
保证非空返回(如通过Javadoc标注@Nonnull
),则无需空值检查。但若服务层可能出现空值(如网络超时未抛异常但返回空),则需要补充校验。综上,是否需要修改取决于:
NacosException
createMcpServer
的返回值约束是否严格定义建议与服务层开发者确认方法规范,并检查是否存在未声明的异常场景(如
NullPointerException
)。Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jujiale 您的分析需要结合以下关键点进一步确认:
若当前
NacosException
已被全局异常处理器(如@ControllerAdvice
)捕获并转换为结构化响应(如Result.fail()
格式),则无需本地try-catch
。但需确认:NacosException
errorCode
和message
的正确封装未声明异常的潜在风险
当前方法签名声明抛出
NacosException
,但若服务层可能抛出未声明的异常(如NullPointerException
或IOException
),则这些异常会直接导致HTTP 500,无法返回预期的错误码。空值返回的边界情况
若
createMcpServer
方法在某些场景未抛异常但返回空字符串(例如数据库主键生成失败但未正确抛异常),直接返回会导致前端接收空值。需确认该方法的Javadoc是否明确标注@Nonnull
。建议行动项:
NacosException
的全局异常处理逻辑createMcpServer
的异常边界(是否包含未声明异常)Objects.requireNonNull(mcpId)
)以明确契约