Skip to content

Commit 5b090c2

Browse files
committed
Simplify read_note fallback to JSON dict contract
Signed-off-by: phernandez <paul@basicmachines.co>
1 parent c85d096 commit 5b090c2

2 files changed

Lines changed: 41 additions & 48 deletions

File tree

src/basic_memory/mcp/tools/read_note.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -193,16 +193,10 @@ def _empty_json_payload() -> dict:
193193
}
194194

195195
def _search_results(payload: object) -> list[dict]:
196-
if isinstance(payload, dict):
197-
results = payload.get("results")
198-
return results if isinstance(results, list) else []
199-
model_dump = getattr(payload, "model_dump", None)
200-
if callable(model_dump):
201-
dumped = model_dump()
202-
if isinstance(dumped, dict):
203-
results = dumped.get("results")
204-
return results if isinstance(results, list) else []
205-
return []
196+
if not isinstance(payload, dict):
197+
return []
198+
results = payload.get("results")
199+
return results if isinstance(results, list) else []
206200

207201
def _result_title(item: object) -> str:
208202
if not isinstance(item, dict):

tests/mcp/test_tool_read_note.py

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import pytest
66

77
from basic_memory.mcp.tools import write_note, read_note
8-
from basic_memory.schemas.search import SearchResponse, SearchResult, SearchItemType
98
from basic_memory.utils import normalize_newlines
109

1110

@@ -68,30 +67,30 @@ async def test_read_note_returns_related_results_when_text_search_finds_matches(
6867

6968
async def fake_search_notes_fn(*, query, search_type, **kwargs):
7069
if search_type == "title":
71-
return SearchResponse(results=[], current_page=1, page_size=10)
72-
73-
return SearchResponse(
74-
results=[
75-
SearchResult(
76-
title="Related One",
77-
permalink="docs/related-one",
78-
content="",
79-
type=SearchItemType.ENTITY,
80-
score=1.0,
81-
file_path="docs/related-one.md",
82-
),
83-
SearchResult(
84-
title="Related Two",
85-
permalink="docs/related-two",
86-
content="",
87-
type=SearchItemType.ENTITY,
88-
score=0.9,
89-
file_path="docs/related-two.md",
90-
),
70+
return {"results": [], "current_page": 1, "page_size": 10}
71+
72+
return {
73+
"results": [
74+
{
75+
"title": "Related One",
76+
"permalink": "docs/related-one",
77+
"content": "",
78+
"type": "entity",
79+
"score": 1.0,
80+
"file_path": "docs/related-one.md",
81+
},
82+
{
83+
"title": "Related Two",
84+
"permalink": "docs/related-two",
85+
"content": "",
86+
"type": "entity",
87+
"score": 0.9,
88+
"file_path": "docs/related-two.md",
89+
},
9190
],
92-
current_page=1,
93-
page_size=10,
94-
)
91+
"current_page": 1,
92+
"page_size": 10,
93+
}
9594

9695
# Ensure direct resolution doesn't short-circuit the fallback logic.
9796
class FailingKnowledgeClient(OriginalKnowledgeClient):
@@ -131,21 +130,21 @@ async def resolve_entity(self, identifier: str, *, strict: bool = False) -> int:
131130

132131
async def fake_search_notes_fn(*, query, search_type, **kwargs):
133132
if search_type == "title":
134-
return SearchResponse(
135-
results=[
136-
SearchResult(
137-
title="Existing Note",
138-
permalink="test/existing-note",
139-
content="",
140-
type=SearchItemType.ENTITY,
141-
score=1.0,
142-
file_path="test/Existing Note.md",
143-
)
133+
return {
134+
"results": [
135+
{
136+
"title": "Existing Note",
137+
"permalink": "test/existing-note",
138+
"content": "",
139+
"type": "entity",
140+
"score": 1.0,
141+
"file_path": "test/Existing Note.md",
142+
}
144143
],
145-
current_page=1,
146-
page_size=10,
147-
)
148-
return SearchResponse(results=[], current_page=1, page_size=10)
144+
"current_page": 1,
145+
"page_size": 10,
146+
}
147+
return {"results": [], "current_page": 1, "page_size": 10}
149148

150149
monkeypatch.setattr(clients_mod, "KnowledgeClient", StrictFailingKnowledgeClient)
151150
monkeypatch.setattr(read_note_module.search_notes, "fn", fake_search_notes_fn)

0 commit comments

Comments
 (0)