We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/mcp-bridge/local-filesystem'
If you have feedback or need assistance with the MCP directory API, please join our Discord server
"""Integration tests for search route handlers."""
from local_filesystem.api.search_routes import register_search_routes
class TestSearchByName:
"""Integration tests for search_by_name route."""
def test_search_by_name_exact_match(self, populated_temp_root, mock_context, capture_handlers):
"""Test searching for files by exact name."""
handlers = capture_handlers(
populated_temp_root, register_search_routes, "local_filesystem.api.search_routes"
)
result = handlers["search_by_name"](
name="nested.txt", path=".", recursive=True, case_sensitive=False
)
assert result["total_matches"] >= 1
assert any("nested.txt" in r["path"] for r in result["matches"])
def test_search_by_name_case_insensitive(
self, populated_temp_root, mock_context, capture_handlers
):
"""Test case-insensitive name search."""
handlers = capture_handlers(
populated_temp_root, register_search_routes, "local_filesystem.api.search_routes"
)
result = handlers["search_by_name"](
name="NESTED.TXT", path=".", recursive=True, case_sensitive=False
)
assert result["total_matches"] >= 1
def test_search_by_name_non_recursive(self, populated_temp_root, mock_context, capture_handlers):
"""Test non-recursive name search."""
handlers = capture_handlers(
populated_temp_root, register_search_routes, "local_filesystem.api.search_routes"
)
result = handlers["search_by_name"](
name="file1.txt", path=".", recursive=False, case_sensitive=False
)
assert result["total_matches"] >= 1
# Should not find nested files
assert not any("subdir" in r["path"] for r in result["matches"])
class TestSearchByGlob:
"""Integration tests for search_by_glob route."""
def test_search_by_glob_all_txt(self, populated_temp_root, mock_context, capture_handlers):
"""Test searching for all .txt files."""
handlers = capture_handlers(
populated_temp_root, register_search_routes, "local_filesystem.api.search_routes"
)
result = handlers["search_by_glob"](pattern="*.txt", path=".", recursive=True)
assert result["total_matches"] >= 4
for match in result["matches"]:
assert match["name"].endswith(".txt")
def test_search_by_glob_recursive_pattern(
self, populated_temp_root, mock_context, capture_handlers
):
"""Test searching with recursive glob pattern."""
handlers = capture_handlers(
populated_temp_root, register_search_routes, "local_filesystem.api.search_routes"
)
result = handlers["search_by_glob"](pattern="**/*.txt", path=".", recursive=True)
assert result["total_matches"] >= 4
def test_search_by_glob_multiple_extensions(
self, populated_temp_root, mock_context, capture_handlers
):
"""Test searching for multiple file extensions."""
handlers = capture_handlers(
populated_temp_root, register_search_routes, "local_filesystem.api.search_routes"
)
result = handlers["search_by_glob"](pattern="*.py", path=".", recursive=True)
assert result["total_matches"] >= 1
assert any("script.py" in r["name"] for r in result["matches"])
class TestSearchByFilenameRegex:
"""Integration tests for search_by_filename_regex route."""
def test_search_by_filename_regex_simple(
self, populated_temp_root, mock_context, capture_handlers
):
"""Test searching by filename regex."""
handlers = capture_handlers(
populated_temp_root, register_search_routes, "local_filesystem.api.search_routes"
)
result = handlers["search_by_filename_regex"](
regex_pattern=r"file\d+\.txt", path=".", recursive=True, case_sensitive=False
)
assert result["total_matches"] >= 2
file_names = {r["name"] for r in result["matches"]}
assert "file1.txt" in file_names
assert "file2.txt" in file_names
def test_search_by_filename_regex_case_sensitive(
self, populated_temp_root, mock_context, capture_handlers
):
"""Test case-sensitive filename regex search."""
handlers = capture_handlers(
populated_temp_root, register_search_routes, "local_filesystem.api.search_routes"
)
# Search for uppercase (should not match)
result = handlers["search_by_filename_regex"](
regex_pattern=r"FILE\d+\.txt", path=".", recursive=True, case_sensitive=True
)
assert result["total_matches"] == 0
def test_search_by_filename_regex_complex_pattern(
self, populated_temp_root, mock_context, capture_handlers
):
"""Test complex regex pattern."""
handlers = capture_handlers(
populated_temp_root, register_search_routes, "local_filesystem.api.search_routes"
)
result = handlers["search_by_filename_regex"](
regex_pattern=r"(file|script)\.(txt|py)", path=".", recursive=True, case_sensitive=False
)
# Should find at least script.py, might also find file*.txt
# depending on regex implementation
assert result["total_matches"] >= 1
class TestSearchByContentText:
"""Integration tests for search_by_content_text route."""
def test_search_by_content_text_simple(
self, populated_temp_root, mock_context, capture_handlers
):
"""Test searching for text in file content."""
handlers = capture_handlers(
populated_temp_root, register_search_routes, "local_filesystem.api.search_routes"
)
result = handlers["search_by_content_text"](
query="SEARCH", path=".", recursive=True, case_sensitive=False, max_results=100
)
assert result["total_matches"] >= 1
# Should find search_test.txt
assert any("search_test.txt" in r["path"] for r in result["matches"])
def test_search_by_content_text_case_sensitive(
self, populated_temp_root, mock_context, capture_handlers
):
"""Test case-sensitive content search."""
handlers = capture_handlers(
populated_temp_root, register_search_routes, "local_filesystem.api.search_routes"
)
# Search for exact case
result = handlers["search_by_content_text"](
query="SEARCH", path=".", recursive=True, case_sensitive=True, max_results=100
)
assert result["total_matches"] >= 1
def test_search_by_content_text_with_context(
self, populated_temp_root, mock_context, capture_handlers
):
"""Test that search results include context preview."""
handlers = capture_handlers(
populated_temp_root, register_search_routes, "local_filesystem.api.search_routes"
)
result = handlers["search_by_content_text"](
query="Python is awesome",
path=".",
recursive=True,
case_sensitive=False,
max_results=100,
)
assert result["total_matches"] >= 1
# Check that results have match_context or line_number from SearchMatch schema
for match in result["matches"]:
assert "match_context" in match or "line_number" in match
def test_search_by_content_text_max_results(
self, populated_temp_root, mock_context, capture_handlers
):
"""Test max_results limit."""
handlers = capture_handlers(
populated_temp_root, register_search_routes, "local_filesystem.api.search_routes"
)
result = handlers["search_by_content_text"](
query="test", path=".", recursive=True, case_sensitive=False, max_results=2
)
# Should respect max_results limit
assert len(result["matches"]) <= 2
class TestSearchByContentRegex:
"""Integration tests for search_by_content_regex route."""
def test_search_by_content_regex_simple(
self, populated_temp_root, mock_context, capture_handlers
):
"""Test searching content with regex pattern."""
handlers = capture_handlers(
populated_temp_root, register_search_routes, "local_filesystem.api.search_routes"
)
result = handlers["search_by_content_regex"](
regex_pattern=r"Hello\s+World",
path=".",
recursive=True,
case_sensitive=False,
max_results=100,
)
assert result["total_matches"] >= 1
assert any("file1.txt" in r["path"] for r in result["matches"])
def test_search_by_content_regex_complex_pattern(
self, populated_temp_root, mock_context, capture_handlers
):
"""Test searching with complex regex pattern."""
handlers = capture_handlers(
populated_temp_root, register_search_routes, "local_filesystem.api.search_routes"
)
result = handlers["search_by_content_regex"](
regex_pattern=r'"[^"]+"\s*:\s*\d+', # JSON pattern like "number": 42
path=".",
recursive=True,
case_sensitive=False,
max_results=100,
)
# Should find data.json
assert result["total_matches"] >= 1
def test_search_by_content_regex_case_sensitive(
self, populated_temp_root, mock_context, capture_handlers
):
"""Test case-sensitive regex content search."""
handlers = capture_handlers(
populated_temp_root, register_search_routes, "local_filesystem.api.search_routes"
)
result = handlers["search_by_content_regex"](
regex_pattern=r"Python", path=".", recursive=True, case_sensitive=True, max_results=100
)
assert result["total_matches"] >= 1
def test_search_by_content_regex_max_results(
self, populated_temp_root, mock_context, capture_handlers
):
"""Test max_results limit for regex search."""
handlers = capture_handlers(
populated_temp_root, register_search_routes, "local_filesystem.api.search_routes"
)
result = handlers["search_by_content_regex"](
regex_pattern=r"\w+", path=".", recursive=True, case_sensitive=False, max_results=3
)
# Should respect max_results limit
assert len(result["matches"]) <= 3