Compare commits

...

1 Commits

Author SHA1 Message Date
claude[bot] f64f7b5cfc fix(mcp): remove hardcoded display cap of 5 in recent_activity formatter
The _format_project_output function was slicing entities[:5] and
relations[:5] (and observations[:10]) regardless of the page_size
parameter. Since the API already paginates by page_size, these caps
caused the formatter to silently drop results that the API returned,
producing misleading output (heading says N items, body shows only 5).

Remove the formatter-side slices entirely; the API is the canonical
source of truth on how many items to return per page.

Add regression test with 9 entities to prevent recurrence.

Fixes #784

Co-authored-by: Drew Cain <groksrc@users.noreply.github.com>
Signed-off-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
2026-05-03 02:03:33 +00:00
2 changed files with 54 additions and 3 deletions
@@ -495,7 +495,7 @@ def _format_project_output(
# Show entities (notes/documents)
if entities:
lines.append(f"\n**📄 Recent Notes & Documents ({len(entities)}):**")
for entity in entities[:5]: # Show top 5
for entity in entities:
title = entity.title or "Untitled"
# Get folder from file_path
folder = ""
@@ -510,7 +510,7 @@ def _format_project_output(
lines.append(f"\n**🔍 Recent Observations ({len(observations)}):**")
# Group by category
by_category = {}
for obs in observations[:10]: # Limit to recent ones
for obs in observations:
category = obs.category
if category not in by_category:
by_category[category] = []
@@ -528,7 +528,7 @@ def _format_project_output(
# Show relations (connections)
if relations:
lines.append(f"\n**🔗 Recent Connections ({len(relations)}):**")
for rel in relations[:5]: # Show top 5
for rel in relations:
rel_type = rel.relation_type
from_entity = rel.from_entity or "Unknown"
to_entity = rel.to_entity
+51
View File
@@ -534,3 +534,54 @@ def test_format_project_output_no_more_pages():
)
assert "1 items found." in out
assert "Use page=" not in out
def test_format_project_output_shows_all_entities_beyond_five():
"""Formatter must not cap entity or relation display at 5 regardless of page_size.
Regression test for: https://github.com/basicmachines-co/basic-memory/issues/784
The API already paginates by page_size; the formatter should not impose a lower cap.
"""
import importlib
import uuid
recent_activity_module = importlib.import_module("basic_memory.mcp.tools.recent_activity")
now = datetime.now(timezone.utc)
def make_entity(idx: int) -> ContextResult:
return ContextResult(
primary_result=EntitySummary(
external_id=str(uuid.uuid4()),
entity_id=idx,
permalink=f"notes/note-{idx:02d}",
title=f"Note {idx:02d}",
content=None,
file_path=f"notes/note-{idx:02d}.md",
created_at=now,
),
observations=[],
related_results=[],
)
# Build 9 entity results — more than the old hardcoded cap of 5
results = [make_entity(i) for i in range(1, 10)]
activity = GraphContext(
results=results,
metadata=MemoryMetadata(depth=1, generated_at=now),
has_more=False,
)
out = recent_activity_module._format_project_output(
project_name="proj",
activity_data=activity,
timeframe="today",
type_filter="entity",
page=1,
)
# All 9 titles must appear in the output
for i in range(1, 10):
assert f"Note {i:02d}" in out, f"Note {i:02d} missing from output"
assert "9 items found." in out