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