Skip to content
This repository was archived by the owner on Mar 4, 2026. It is now read-only.
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
12 changes: 8 additions & 4 deletions src/agentic_cli/mcp/context7.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,14 @@ def to_markdown(self) -> str:
if document.summary:
detail_lines.append(f"Summary: {document.summary.strip()}")
elif document.content:
preview = document.content.strip().splitlines()[0]
if len(preview) > 160:
preview = preview[:157] + "..."
detail_lines.append(f"Preview: {preview}")
stripped_content = document.content.strip()
if stripped_content:
preview_lines = stripped_content.splitlines()
if preview_lines:
preview = preview_lines[0]
if len(preview) > 160:
preview = preview[:157] + "..."
detail_lines.append(f"Preview: {preview}")
if document.source:
detail_lines.append(f"Source: {document.source}")
if document.metadata:
Expand Down
16 changes: 16 additions & 0 deletions tests/test_mcp_context7.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,22 @@ def fake_timestamped_dir(prefix: str) -> Path:
assert dummy_client.closed is False


def test_docs_markdown_omits_preview_for_whitespace_content() -> None:
"""Whitespace-only content does not produce a preview entry."""

response = Context7DocsResponse(
package="example@1.0.0",
library=Context7Library(id="example", name="Example"),
documents=[
Context7Document(title="Doc", content=" \n\n "),
],
)

markdown = response.to_markdown()

assert "Preview:" not in markdown


def test_run_docs_requires_configuration(capsys) -> None:
"""If Context7 is not configured the command exits early."""

Expand Down
Loading