Skip to content
Merged
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
2 changes: 1 addition & 1 deletion mcpunk/file_chunk.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def id_(self) -> str:

def matches_filter(
self,
filter_: None | list[str],
filter_: None | list[str] | str,
filter_on: Literal["name", "content", "name_or_content"],
) -> bool:
"""Return True if the chunk's name matches the given filter.
Expand Down
2 changes: 1 addition & 1 deletion mcpunk/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
ToolResponseSequence = Sequence[ToolResponseSingleItem]
ToolResponse = ToolResponseSequence | ToolResponseSingleItem
FilterType = Annotated[
list[str] | None,
str | list[str] | None,
Field(description="Match if any of these strings appear. Match all if None/null."),
]

Expand Down
6 changes: 4 additions & 2 deletions mcpunk/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def create_file_tree(
project_root: Path,
paths: set[Path],
limit_depth_from_root: int | None = None,
filter_: None | list[str] = None,
filter_: None | list[str] | str = None,
) -> str | None:
"""Create a compact text representation of files in a directory structure.

Expand Down Expand Up @@ -130,7 +130,7 @@ def rand_str(n: int = 10, chars: str = ascii_lowercase) -> str:
return "".join(random.choice(chars) for _ in range(n))


def matches_filter(filter_: None | list[str], data: str | None) -> bool:
def matches_filter(filter_: None | list[str] | str, data: str | None) -> bool:
"""Return True if the data matches the given filter.

filter_ can be:
Expand All @@ -144,6 +144,8 @@ def matches_filter(filter_: None | list[str], data: str | None) -> bool:
return True
if data is None:
return False
if isinstance(filter_, str):
return filter_ in data
if isinstance(filter_, list):
return any(x in data for x in filter_)
assert_never(filter_)