package com.claudecode.tool.impl; import com.claudecode.tool.Tool; import com.claudecode.tool.ToolContext; import com.claudecode.tool.ToolRegistry; import java.util.List; import java.util.Map; import java.util.stream.Collectors; /** * 工具搜索工具 —— 对应 claude-code 中 /tools 命令功能。 *
* 在 ToolRegistry 中搜索已注册的工具,按名称或描述关键字匹配。
* 用于帮助 LLM 发现可用工具。
*/
public class ToolSearchTool implements Tool {
private static final String TOOL_REGISTRY_KEY = "TOOL_REGISTRY";
@Override
public String name() {
return "ToolSearch";
}
@Override
public String description() {
return """
Search for available tools by name or keyword. Returns matching tool names and \
their descriptions. Use this when you need to find which tools are available for \
a specific task, or when the user asks about available capabilities.""";
}
@Override
public String inputSchema() {
return """
{
"type": "object",
"properties": {
"query": {
"type": "string",
"description": "Search query to match against tool names and descriptions. Empty string lists all tools."
}
},
"required": ["query"]
}""";
}
@Override
public boolean isReadOnly() {
return true;
}
@Override
public String execute(Map