forked from kimhyungsik/ax_hub_mcp_tool
Feat: Externalize McpFunction metadata to application properties
This commit is contained in:
@@ -0,0 +1,22 @@
|
|||||||
|
package io.shinhanlife.axhub.biz.mcp.tool.config;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Configuration
|
||||||
|
@ConfigurationProperties(prefix = "mcp")
|
||||||
|
public class McpProperties {
|
||||||
|
|
||||||
|
private Map<String, FunctionProp> functions;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class FunctionProp {
|
||||||
|
private String description;
|
||||||
|
private String prompt;
|
||||||
|
private String mappingId;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,6 +15,8 @@ import org.springframework.scheduling.annotation.Scheduled;
|
|||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.client.RestClient;
|
import org.springframework.web.client.RestClient;
|
||||||
|
|
||||||
|
import io.shinhanlife.axhub.biz.mcp.tool.config.McpProperties;
|
||||||
|
|
||||||
import jakarta.annotation.PostConstruct;
|
import jakarta.annotation.PostConstruct;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -31,6 +33,7 @@ public class ToolRegistryHeartbeatSender {
|
|||||||
|
|
||||||
private final ApplicationContext applicationContext;
|
private final ApplicationContext applicationContext;
|
||||||
private final ObjectMapper objectMapper;
|
private final ObjectMapper objectMapper;
|
||||||
|
private final McpProperties mcpProperties;
|
||||||
private final RestClient restClient = RestClient.create();
|
private final RestClient restClient = RestClient.create();
|
||||||
|
|
||||||
@Value("${axhub.gateway.url:http://localhost:8081}")
|
@Value("${axhub.gateway.url:http://localhost:8081}")
|
||||||
@@ -55,16 +58,22 @@ public class ToolRegistryHeartbeatSender {
|
|||||||
for (Method method : bean.getClass().getDeclaredMethods()) {
|
for (Method method : bean.getClass().getDeclaredMethods()) {
|
||||||
McpFunction functionAnnotation = method.getAnnotation(McpFunction.class);
|
McpFunction functionAnnotation = method.getAnnotation(McpFunction.class);
|
||||||
if (functionAnnotation != null) {
|
if (functionAnnotation != null) {
|
||||||
|
McpProperties.FunctionProp prop = null;
|
||||||
|
if (mcpProperties.getFunctions() != null) {
|
||||||
|
prop = mcpProperties.getFunctions().get(functionAnnotation.name());
|
||||||
|
}
|
||||||
|
|
||||||
ToolMetadata meta = new ToolMetadata();
|
ToolMetadata meta = new ToolMetadata();
|
||||||
meta.setToolName(functionAnnotation.name());
|
meta.setToolName(functionAnnotation.name());
|
||||||
meta.setDescription(functionAnnotation.description());
|
meta.setDescription(prop != null && prop.getDescription() != null ? prop.getDescription() : functionAnnotation.description());
|
||||||
meta.setDomainGroup(toolAnnotation.group());
|
meta.setDomainGroup(toolAnnotation.group());
|
||||||
meta.setIntegrationType(toolAnnotation.routingType());
|
meta.setIntegrationType(toolAnnotation.routingType());
|
||||||
meta.setMciServiceId(functionAnnotation.mappingId());
|
meta.setMciServiceId(prop != null && prop.getMappingId() != null ? prop.getMappingId() : functionAnnotation.mappingId());
|
||||||
meta.setPodUrl(podUrl);
|
meta.setPodUrl(podUrl);
|
||||||
|
|
||||||
Map<String, String> prompts = new HashMap<>();
|
Map<String, String> prompts = new HashMap<>();
|
||||||
prompts.put(functionAnnotation.name(), functionAnnotation.prompt());
|
String promptText = prop != null && prop.getPrompt() != null ? prop.getPrompt() : functionAnnotation.prompt();
|
||||||
|
prompts.put(functionAnnotation.name(), promptText);
|
||||||
meta.setActionPrompts(prompts);
|
meta.setActionPrompts(prompts);
|
||||||
|
|
||||||
if (method.getParameterCount() > 0) {
|
if (method.getParameterCount() > 0) {
|
||||||
|
|||||||
@@ -29,3 +29,8 @@ spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.kafka.KafkaA
|
|||||||
|
|
||||||
# Suppress Kafka Connection Logs
|
# Suppress Kafka Connection Logs
|
||||||
logging.level.org.apache.kafka=ERROR
|
logging.level.org.apache.kafka=ERROR
|
||||||
|
|
||||||
|
# MCP Function Override Test
|
||||||
|
mcp.functions.send_sms.description=고객에게 SMS 문자를 전송합니다. (프로퍼티 오버라이드 됨)
|
||||||
|
mcp.functions.send_sms.prompt=이 SMS 메시지 전송해줘. (프로퍼티 기반 작동)
|
||||||
|
mcp.functions.send_sms.mappingId=SMS_SEND_001
|
||||||
|
|||||||
Reference in New Issue
Block a user