Skip to content

feat(mcp): add directory listing sorting - #1268

Merged
phernandez merged 1 commit into
mainfrom
feat/directory-list-sorting
Aug 17, 2026
Merged

feat(mcp): add directory listing sorting#1268
phernandez merged 1 commit into
mainfrom
feat/directory-list-sorting

Conversation

@phernandez

Copy link
Copy Markdown
Member

Why

The hosted MCP project and folder browser needs one exact-depth directory read that includes both child folders and notes while supporting title and updated-time sorting.

Core previously exposed only its legacy filename ordering, forcing Cloud to use a notes-only fallback for non-default sorts and lose folder cards. This closes #1267 and unblocks the one-read navigation work in basic-memory-cloud#1764.

What Changed

  • Added the closed title_asc, title_desc, updated_asc, and updated_desc sort contract to the directory API and typed MCP client.
  • Applied deterministic, folders-first ordering before pagination.
  • Exposed sorting through the public list_directory MCP tool without re-sorting the API response.
  • Included the selected sort mode in semantic read-cache keys.
  • Added service, API, client, MCP contract/tool, pagination, and Redis cache regression coverage.

Implementation Details

  • Omitting sort preserves the existing filename-based ordering for compatibility.
  • Explicit title sorts use note titles, with directory path and external ID as deterministic tie-breakers.
  • Explicit updated sorts use the same identity tie-breakers before applying the timestamp as the stable primary key.
  • Implicit directory entries do not have canonical update timestamps, so updated-time modes keep directories name-ascending while still placing them before files.
  • Missing file timestamps fail fast instead of silently producing an unstable order.

Testing

Automated

  • uv run pytest tests/services/test_directory_service.py tests/api/v2/test_directory_router.py tests/mcp/clients/test_clients.py tests/mcp/test_tool_contracts.py tests/mcp/test_tool_list_directory.py -q: 88 passed
  • uv run pytest tests/services/test_directory_service.py tests/mcp/test_tool_list_directory.py -q: 47 passed
  • uv run pytest tests/mcp/test_tool_contracts.py -q: 5 passed
  • uv run pytest test-int/read_cache/test_api_read_cache.py::test_directory_reads_cache_then_project_invalidation_refreshes -q: 1 passed
  • just fast-check: passed
  • just typecheck: passed
  • just doctor: passed
  • just test-smoke: 1 passed

Manual

  • Inspected the generated MCP input schema and confirmed the nullable sort field advertises exactly the four supported enum values.
  • Verified the staged diff contained only the 11 implementation and regression-test files.

Risks / Follow-ups

  • No schema migration or default behavior change.
  • Cloud can remove its notes-only sorting fallback after consuming this Core contract.

Signed-off-by: phernandez <paul@basicmachines.co>
@phernandez
phernandez merged commit 346a519 into main Aug 17, 2026
25 checks passed
@phernandez
phernandez deleted the feat/directory-list-sorting branch August 17, 2026 03:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support sorting in the directory listing API

1 participant