feat: add auto-injection flag for tools and filter auto-injected tools in UI
This commit is contained in:
@@ -174,6 +174,9 @@ func buildAIAgentResponse(item *models.AIAgent) response.AIAgentResponse {
|
||||
if toolCode == "" {
|
||||
toolCode = toolx.BuildMCPToolCode(tool.ServerCode, tool.ToolName)
|
||||
}
|
||||
if toolx.IsAutoInjectedToolCode(toolCode) {
|
||||
continue
|
||||
}
|
||||
serverCode := strings.TrimSpace(tool.ServerCode)
|
||||
toolName := strings.TrimSpace(tool.ToolName)
|
||||
if toolCode == toolx.BuiltinToolSearchToolCode {
|
||||
|
||||
@@ -39,6 +39,7 @@ func (c *MCPController) AnyCatalog() *web.JsonResult {
|
||||
ServerCode: item.ServerCode,
|
||||
ToolName: item.ToolName,
|
||||
SourceType: item.SourceType,
|
||||
AutoInjected: item.AutoInjected,
|
||||
Title: item.Title,
|
||||
Description: item.Description,
|
||||
InputSchema: item.InputSchema,
|
||||
|
||||
@@ -70,6 +70,7 @@ type MCPToolCatalogResponse struct {
|
||||
ServerCode string `json:"serverCode"`
|
||||
ToolName string `json:"toolName"`
|
||||
SourceType string `json:"sourceType"`
|
||||
AutoInjected bool `json:"autoInjected"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
InputSchema any `json:"inputSchema"`
|
||||
|
||||
@@ -11,3 +11,7 @@ const (
|
||||
BuiltinCreateTicketConfirmToolTitle = "创建工单并发起确认"
|
||||
BuiltinCreateTicketConfirmToolDescription = "当用户明确要求创建工单,且标题和描述已经整理清楚后调用。工具会先向用户确认,确认后才真正创建工单。"
|
||||
)
|
||||
|
||||
func IsAutoInjectedToolCode(toolCode string) bool {
|
||||
return toolCode == BuiltinToolSearchToolCode
|
||||
}
|
||||
|
||||
@@ -294,6 +294,9 @@ func (s *aIAgentService) normalizeDirectTools(input []request.AIAgentMCPToolRequ
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if toolx.IsAutoInjectedToolCode(strings.TrimSpace(normalized.ToolCode)) {
|
||||
continue
|
||||
}
|
||||
if err := ToolCatalogService.ValidateToolCode(normalized.ToolCode); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ type MCPToolCatalogItem struct {
|
||||
ServerCode string
|
||||
ToolName string
|
||||
SourceType string
|
||||
AutoInjected bool
|
||||
Title string
|
||||
Description string
|
||||
InputSchema any
|
||||
@@ -34,23 +35,25 @@ func (s *toolCatalogService) ListMCPTools(ctx context.Context) ([]MCPToolCatalog
|
||||
cfg := config.Current()
|
||||
ret := make([]MCPToolCatalogItem, 0, 2)
|
||||
ret = append(ret, MCPToolCatalogItem{
|
||||
ToolCode: toolx.BuiltinCreateTicketConfirmToolCode,
|
||||
ServerCode: toolx.BuiltinToolCatalogServerCode,
|
||||
ToolName: toolx.BuiltinCreateTicketConfirmToolName,
|
||||
SourceType: toolx.BuiltinToolCatalogServerCode,
|
||||
Title: toolx.BuiltinCreateTicketConfirmToolTitle,
|
||||
Description: toolx.BuiltinCreateTicketConfirmToolDescription,
|
||||
ToolCode: toolx.BuiltinCreateTicketConfirmToolCode,
|
||||
ServerCode: toolx.BuiltinToolCatalogServerCode,
|
||||
ToolName: toolx.BuiltinCreateTicketConfirmToolName,
|
||||
SourceType: toolx.BuiltinToolCatalogServerCode,
|
||||
AutoInjected: false,
|
||||
Title: toolx.BuiltinCreateTicketConfirmToolTitle,
|
||||
Description: toolx.BuiltinCreateTicketConfirmToolDescription,
|
||||
})
|
||||
if !cfg.MCP.Enabled {
|
||||
return ret, nil
|
||||
}
|
||||
ret = append(ret, MCPToolCatalogItem{
|
||||
ToolCode: toolx.BuiltinToolSearchToolCode,
|
||||
ServerCode: toolx.BuiltinToolCatalogServerCode,
|
||||
ToolName: toolx.BuiltinToolSearchToolName,
|
||||
SourceType: toolx.BuiltinToolCatalogServerCode,
|
||||
Title: toolx.BuiltinToolSearchToolTitle,
|
||||
Description: toolx.BuiltinToolSearchToolDescription,
|
||||
ToolCode: toolx.BuiltinToolSearchToolCode,
|
||||
ServerCode: toolx.BuiltinToolCatalogServerCode,
|
||||
ToolName: toolx.BuiltinToolSearchToolName,
|
||||
SourceType: toolx.BuiltinToolCatalogServerCode,
|
||||
AutoInjected: true,
|
||||
Title: toolx.BuiltinToolSearchToolTitle,
|
||||
Description: toolx.BuiltinToolSearchToolDescription,
|
||||
})
|
||||
serverCodes := make([]string, 0, len(cfg.MCP.Servers))
|
||||
for serverCode, server := range cfg.MCP.Servers {
|
||||
@@ -71,6 +74,7 @@ func (s *toolCatalogService) ListMCPTools(ctx context.Context) ([]MCPToolCatalog
|
||||
ServerCode: serverCode,
|
||||
ToolName: strings.TrimSpace(item.Name),
|
||||
SourceType: "mcp",
|
||||
AutoInjected: false,
|
||||
Title: strings.TrimSpace(item.Title),
|
||||
Description: strings.TrimSpace(item.Description),
|
||||
InputSchema: item.InputSchema,
|
||||
|
||||
@@ -66,6 +66,7 @@ type DirectToolOption = {
|
||||
label: string;
|
||||
meta: DirectToolItem;
|
||||
sourceType: string;
|
||||
autoInjected: boolean;
|
||||
groupLabel: string;
|
||||
};
|
||||
|
||||
@@ -354,23 +355,26 @@ function EditDialogBody({
|
||||
const catalog = await fetchMCPCatalog();
|
||||
setToolCatalog(catalog);
|
||||
setDirectToolOptions(
|
||||
catalog.map((tool) => ({
|
||||
value: tool.toolCode,
|
||||
label: `${tool.title || tool.toolName} · ${tool.toolCode}`,
|
||||
sourceType: tool.sourceType,
|
||||
groupLabel:
|
||||
tool.sourceType === "builtin"
|
||||
? "内置工具"
|
||||
: tool.serverCode,
|
||||
meta: {
|
||||
toolCode: tool.toolCode,
|
||||
serverCode: tool.serverCode,
|
||||
toolName: tool.toolName,
|
||||
title: tool.title || tool.toolName,
|
||||
description: tool.description || "",
|
||||
arguments: undefined,
|
||||
},
|
||||
})),
|
||||
catalog
|
||||
.filter((tool) => !tool.autoInjected)
|
||||
.map((tool) => ({
|
||||
value: tool.toolCode,
|
||||
label: `${tool.title || tool.toolName} · ${tool.toolCode}`,
|
||||
sourceType: tool.sourceType,
|
||||
autoInjected: tool.autoInjected,
|
||||
groupLabel:
|
||||
tool.sourceType === "builtin"
|
||||
? "内置工具"
|
||||
: tool.serverCode,
|
||||
meta: {
|
||||
toolCode: tool.toolCode,
|
||||
serverCode: tool.serverCode,
|
||||
toolName: tool.toolName,
|
||||
title: tool.title || tool.toolName,
|
||||
description: tool.description || "",
|
||||
arguments: undefined,
|
||||
},
|
||||
})),
|
||||
);
|
||||
} catch (error) {
|
||||
toast.error(
|
||||
@@ -869,6 +873,7 @@ function EditDialogBody({
|
||||
<div className="mb-1 text-sm font-medium">Direct Tools</div>
|
||||
<div className="mb-4 text-xs text-muted-foreground">
|
||||
用于低风险、原子化的实时查询。可选择 MCP 工具,也可选择系统内置工具。
|
||||
`tool_search` 会由 Runtime 自动注入,这里不需要手动添加。
|
||||
</div>
|
||||
<Field>
|
||||
<FieldContent className="space-y-3">
|
||||
|
||||
@@ -334,6 +334,7 @@ export type MCPToolCatalogItem = {
|
||||
serverCode: string
|
||||
toolName: string
|
||||
sourceType: string
|
||||
autoInjected: boolean
|
||||
title: string
|
||||
description: string
|
||||
inputSchema: unknown
|
||||
|
||||
Reference in New Issue
Block a user