Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
gsc
/
gsc-vcp-thirdparty-facade
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 1d8178d3
authored
Sep 11, 2026
by
章家宝
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
feat(report):修复mcp数据接口问题
1 parent
0b701232
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
0 deletions
src/main/java/com/gsc4cloud/gsc/facade/vpcthirdparty/handler/McpExceptionHandler.java
src/main/java/com/gsc4cloud/gsc/facade/vpcthirdparty/response/mcp/McpErrorResponse.java
src/main/java/com/gsc4cloud/gsc/facade/vpcthirdparty/response/mcp/McpSchemaField.java
src/main/java/com/gsc4cloud/gsc/facade/vpcthirdparty/handler/McpExceptionHandler.java
0 → 100644
View file @
1d8178d
package
com
.
gsc4cloud
.
gsc
.
facade
.
vpcthirdparty
.
handler
;
import
com.gsc4cloud.gsc.facade.vpcthirdparty.controller.mcp.McpReportController
;
import
com.gsc4cloud.gsc.facade.vpcthirdparty.response.mcp.McpErrorResponse
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.core.Ordered
;
import
org.springframework.core.annotation.Order
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.http.converter.HttpMessageNotReadableException
;
import
org.springframework.validation.ObjectError
;
import
org.springframework.web.bind.MethodArgumentNotValidException
;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
import
org.springframework.web.bind.annotation.RestControllerAdvice
;
import
java.util.stream.Collectors
;
/**
* MCP 接口异常处理
* <p>
* /mcp/** 的入参校验与请求体解析失败需按 MCP 契约返回 {error_code, message} + HTTP 400,
* 而不是项目统一的 R 包装({code, msg, data, success} + HTTP 200)。
* </p>
*/
@Order
(
Ordered
.
HIGHEST_PRECEDENCE
)
@RestControllerAdvice
(
assignableTypes
=
McpReportController
.
class
)
@Slf4j
public
class
McpExceptionHandler
{
@ExceptionHandler
(
MethodArgumentNotValidException
.
class
)
public
ResponseEntity
<
McpErrorResponse
>
handleValidationException
(
MethodArgumentNotValidException
e
)
{
String
message
=
e
.
getBindingResult
().
getAllErrors
().
stream
()
.
map
(
ObjectError:
:
getDefaultMessage
)
.
collect
(
Collectors
.
joining
(
"; "
));
if
(
message
.
isEmpty
())
{
message
=
"参数校验失败"
;
}
log
.
warn
(
"MCP 参数校验失败: {}"
,
message
);
return
ResponseEntity
.
status
(
HttpStatus
.
BAD_REQUEST
)
.
body
(
McpErrorResponse
.
of
(
"INVALID_PARAM"
,
message
));
}
@ExceptionHandler
(
HttpMessageNotReadableException
.
class
)
public
ResponseEntity
<
McpErrorResponse
>
handleNotReadableException
(
HttpMessageNotReadableException
e
)
{
log
.
warn
(
"MCP 请求体解析失败: {}"
,
e
.
getMessage
());
return
ResponseEntity
.
status
(
HttpStatus
.
BAD_REQUEST
)
.
body
(
McpErrorResponse
.
of
(
"INVALID_PARAM"
,
"请求体格式错误,需为 UTF-8 编码的合法 JSON"
));
}
}
src/main/java/com/gsc4cloud/gsc/facade/vpcthirdparty/response/mcp/McpErrorResponse.java
View file @
1d8178d
package
com
.
gsc4cloud
.
gsc
.
facade
.
vpcthirdparty
.
response
.
mcp
;
package
com
.
gsc4cloud
.
gsc
.
facade
.
vpcthirdparty
.
response
.
mcp
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
import
lombok.AllArgsConstructor
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
lombok.NoArgsConstructor
;
...
@@ -15,6 +16,7 @@ public class McpErrorResponse {
...
@@ -15,6 +16,7 @@ public class McpErrorResponse {
/**
/**
* 错误码
* 错误码
*/
*/
@JsonProperty
(
"error_code"
)
private
String
errorCode
;
private
String
errorCode
;
/**
/**
...
...
src/main/java/com/gsc4cloud/gsc/facade/vpcthirdparty/response/mcp/McpSchemaField.java
View file @
1d8178d
package
com
.
gsc4cloud
.
gsc
.
facade
.
vpcthirdparty
.
response
.
mcp
;
package
com
.
gsc4cloud
.
gsc
.
facade
.
vpcthirdparty
.
response
.
mcp
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
import
lombok.AllArgsConstructor
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
lombok.NoArgsConstructor
;
...
@@ -20,6 +21,7 @@ public class McpSchemaField {
...
@@ -20,6 +21,7 @@ public class McpSchemaField {
/**
/**
* 中文名称
* 中文名称
*/
*/
@JsonProperty
(
"name_cn"
)
private
String
nameCn
;
private
String
nameCn
;
/**
/**
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment