Format JSON payloads for readable HTTP logging
All checks were successful
Deploy Gateway / deploy (push) Successful in 1m34s
All checks were successful
Deploy Gateway / deploy (push) Successful in 1m34s
This commit is contained in:
@@ -58,7 +58,7 @@ public class HttpToolClient implements ToolClient {
|
|||||||
request.toolName(),
|
request.toolName(),
|
||||||
request.version(),
|
request.version(),
|
||||||
request.endpoint(),
|
request.endpoint(),
|
||||||
request.arguments());
|
prettyJson(request.arguments()));
|
||||||
RestClient.RequestBodySpec spec = requestSpec(request, context);
|
RestClient.RequestBodySpec spec = requestSpec(request, context);
|
||||||
var entity =
|
var entity =
|
||||||
spec.retrieve()
|
spec.retrieve()
|
||||||
@@ -68,12 +68,13 @@ public class HttpToolClient implements ToolClient {
|
|||||||
throw statusException(response.getStatusCode().value(), request.toolName());
|
throw statusException(response.getStatusCode().value(), request.toolName());
|
||||||
})
|
})
|
||||||
.toEntity(String.class);
|
.toEntity(String.class);
|
||||||
JsonNode responseBody = parseResponse(entity.getBody(), entity.getHeaders().getContentType()); log.info(
|
JsonNode responseBody = parseResponse(entity.getBody(), entity.getHeaders().getContentType());
|
||||||
|
log.info(
|
||||||
"TEMP_TOOL_HTTP_RESPONSE_BODY direction=tool_server_to_mcp toolName={} version={} statusCode={} body={}",
|
"TEMP_TOOL_HTTP_RESPONSE_BODY direction=tool_server_to_mcp toolName={} version={} statusCode={} body={}",
|
||||||
request.toolName(),
|
request.toolName(),
|
||||||
request.version(),
|
request.version(),
|
||||||
entity.getStatusCode().value(),
|
entity.getStatusCode().value(),
|
||||||
responseBody);
|
prettyJson(responseBody));
|
||||||
return new ToolResponse(entity.getStatusCode().value(), responseBody);
|
return new ToolResponse(entity.getStatusCode().value(), responseBody);
|
||||||
} catch (ToolClientException exception) {
|
} catch (ToolClientException exception) {
|
||||||
throw exception;
|
throw exception;
|
||||||
@@ -88,6 +89,17 @@ public class HttpToolClient implements ToolClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 임시 Tool 본문 로그를 보기 쉽게 출력하기 위해 JSON 값을 개행된 문자열로 변환합니다.
|
||||||
|
* 직렬화 실패 시에도 Tool 호출 결과는 바꾸지 않고 문자열 변환 결과만 로그에 남깁니다.
|
||||||
|
*/
|
||||||
|
private String prettyJson(JsonNode value) {
|
||||||
|
try {
|
||||||
|
return objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(value);
|
||||||
|
} catch (Exception exception) {
|
||||||
|
return String.valueOf(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* URI, bypass 헤더와 JSON body를 조합해 실행 직전 POST 요청 객체를 만듭니다. Agent Builder가 보낸 correlation·사원 식별자는 이름과 값을 바꾸지 않고 그대로 실어 보냅니다. 사원 식별자는 암호문이며 MCP는 복호화하지 않으므로, 이
|
* URI, bypass 헤더와 JSON body를 조합해 실행 직전 POST 요청 객체를 만듭니다. Agent Builder가 보낸 correlation·사원 식별자는 이름과 값을 바꾸지 않고 그대로 실어 보냅니다. 사원 식별자는 암호문이며 MCP는 복호화하지 않으므로, 이
|
||||||
* 경계에서는 전달만 하고 해석하지 않습니다.
|
* 경계에서는 전달만 하고 해석하지 않습니다.
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ public class McpController {
|
|||||||
*/
|
*/
|
||||||
private String toJson(Object value) {
|
private String toJson(Object value) {
|
||||||
try {
|
try {
|
||||||
return objectMapper.writeValueAsString(value);
|
return objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(value);
|
||||||
} catch (Exception exception) {
|
} catch (Exception exception) {
|
||||||
return String.valueOf(value);
|
return String.valueOf(value);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -107,12 +107,13 @@ public class McpExchangeFilter extends OncePerRequestFilter {
|
|||||||
"path",
|
"path",
|
||||||
request.getRequestURI(),
|
request.getRequestURI(),
|
||||||
"mcpMethod",
|
"mcpMethod",
|
||||||
mcpMethod); log.info(
|
mcpMethod);
|
||||||
|
log.info(
|
||||||
"TEMP_MCP_HTTP_REQUEST_BODY direction=agent_to_mcp httpMethod={} path={} mcpMethod={} body={}",
|
"TEMP_MCP_HTTP_REQUEST_BODY direction=agent_to_mcp httpMethod={} path={} mcpMethod={} body={}",
|
||||||
request.getMethod(),
|
request.getMethod(),
|
||||||
request.getRequestURI(),
|
request.getRequestURI(),
|
||||||
mcpMethod,
|
mcpMethod,
|
||||||
cachedRequest.bodyText());
|
prettyJson(cachedRequest.bodyText()));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
protocolVersionValidator.validatePostInitializeRequest(request, mcpMethod);
|
protocolVersionValidator.validatePostInitializeRequest(request, mcpMethod);
|
||||||
@@ -176,6 +177,17 @@ public class McpExchangeFilter extends OncePerRequestFilter {
|
|||||||
*
|
*
|
||||||
* @return method 이름. 읽을 수 없으면 {@code null}
|
* @return method 이름. 읽을 수 없으면 {@code null}
|
||||||
*/
|
*/
|
||||||
|
/**
|
||||||
|
* 임시 요청 본문 로그를 보기 쉽게 출력하기 위해 JSON이면 개행된 문자열로 변환합니다.
|
||||||
|
* JSON 파싱이 실패하면 원문 문자열을 그대로 돌려 요청 처리 흐름에는 영향을 주지 않습니다.
|
||||||
|
*/
|
||||||
|
private String prettyJson(String body) {
|
||||||
|
try {
|
||||||
|
return objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(objectMapper.readTree(body));
|
||||||
|
} catch (Exception exception) {
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
}
|
||||||
private String extractMethod(CachedBodyHttpServletRequest request) {
|
private String extractMethod(CachedBodyHttpServletRequest request) {
|
||||||
try {
|
try {
|
||||||
JsonNode envelope = objectMapper.readTree(request.getInputStream());
|
JsonNode envelope = objectMapper.readTree(request.getInputStream());
|
||||||
|
|||||||
Reference in New Issue
Block a user