Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions core/src/main/java/com/google/adk/tools/BaseToolset.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.google.adk.agents.ReadonlyContext;
import io.reactivex.rxjava3.core.Flowable;
import java.util.List;
import java.util.Collection;
import java.util.Optional;

/** Base interface for toolsets. */
Expand Down Expand Up @@ -31,7 +31,7 @@ public interface BaseToolset extends AutoCloseable {
* list of tools of if testing against the given ToolPredicate returns true (otherwise false).
*
* @param tool The tool to check.
* @param toolFilter An Optional containing either a ToolPredicate or a List of tool names.
* @param toolFilter An Optional containing either a ToolPredicate or a Collection of tool names.
* @param readonlyContext The current context.
* @return true if the tool is selected.
*/
Expand All @@ -44,9 +44,9 @@ default boolean isToolSelected(
if (filter instanceof ToolPredicate toolPredicate) {
return toolPredicate.test(tool, readonlyContext);
}
if (filter instanceof List) {
if (filter instanceof Collection) {
@SuppressWarnings("unchecked")
List<String> toolNames = (List<String>) filter;
Collection<String> toolNames = (Collection<String>) filter;
return toolNames.contains(tool.name());
}
Comment on lines +47 to 51
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

You can simplify this block by using pattern matching for instanceof, which you're already using for ToolPredicate earlier in this method. This will make the code more concise and remove the need for @SuppressWarnings("unchecked").

    if (filter instanceof Collection<?> toolNames) {
      return toolNames.contains(tool.name());
    }

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public McpToolset(SseServerParameters connectionParams, ObjectMapper objectMappe
*
* @param connectionParams The local server connection parameters to the MCP server.
* @param objectMapper An ObjectMapper instance for parsing schemas.
* @param toolFilter An Optional containing either a ToolPredicate or a List of tool names.
* @param toolFilter An Optional containing either a ToolPredicate or a Collection of tool names.
*/
public McpToolset(
ServerParameters connectionParams, ObjectMapper objectMapper, Optional<Object> toolFilter) {
Expand Down