Skip to content

Commit 31c145e

Browse files
phernandezclaude
andcommitted
fix: resolve pyright type errors from direct tool calls
With .fn removed, pyright now sees the real return types (str | dict) of tools that support output_format. Fix by: - Adding str() narrowing where callers always use text mode - Passing output_format="json" explicitly in CLI search (was implicit) - Providing defaults for depth/timeframe instead of passing None Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: phernandez <paul@basicmachines.co>
1 parent 816aa54 commit 31c145e

3 files changed

Lines changed: 45 additions & 37 deletions

File tree

src/basic_memory/cli/commands/tool.py

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -468,13 +468,15 @@ def read_note(
468468
result["content"] = stripped_content
469469
print(json.dumps(result, indent=2, ensure_ascii=True, default=str))
470470
else:
471-
note = run_with_cleanup(
472-
mcp_read_note(
473-
identifier=identifier,
474-
project=project_name,
475-
workspace=workspace,
476-
page=page,
477-
page_size=page_size,
471+
note = str(
472+
run_with_cleanup(
473+
mcp_read_note(
474+
identifier=identifier,
475+
project=project_name,
476+
workspace=workspace,
477+
page=page,
478+
page_size=page_size,
479+
)
478480
)
479481
)
480482
if strip_frontmatter:
@@ -560,16 +562,18 @@ def edit_note(
560562
)
561563
print(json.dumps(result, indent=2, ensure_ascii=True, default=str))
562564
else:
563-
result = run_with_cleanup(
564-
mcp_edit_note(
565-
identifier=identifier,
566-
operation=operation,
567-
content=content,
568-
project=project_name,
569-
workspace=workspace,
570-
section=section,
571-
find_text=find_text,
572-
expected_replacements=expected_replacements,
565+
result = str(
566+
run_with_cleanup(
567+
mcp_edit_note(
568+
identifier=identifier,
569+
operation=operation,
570+
content=content,
571+
project=project_name,
572+
workspace=workspace,
573+
section=section,
574+
find_text=find_text,
575+
expected_replacements=expected_replacements,
576+
)
573577
)
574578
)
575579
rprint(result)
@@ -713,9 +717,9 @@ def recent_activity(
713717
else:
714718
result = run_with_cleanup(
715719
mcp_recent_activity(
716-
type=type, # pyright: ignore [reportArgumentType]
717-
depth=depth,
718-
timeframe=timeframe,
720+
type=type, # pyright: ignore[reportArgumentType]
721+
depth=depth if depth is not None else 1,
722+
timeframe=timeframe if timeframe is not None else "7d",
719723
project=project_name,
720724
workspace=workspace,
721725
)
@@ -867,6 +871,7 @@ def search_notes(
867871
project=project_name,
868872
workspace=workspace,
869873
search_type=search_type,
874+
output_format="json",
870875
page=page,
871876
after_date=after_date,
872877
page_size=page_size,
@@ -881,8 +886,7 @@ def search_notes(
881886
print(results)
882887
raise typer.Exit(1)
883888

884-
results_dict = results.model_dump(exclude_none=True)
885-
print(json.dumps(results_dict, indent=2, ensure_ascii=True, default=str))
889+
print(json.dumps(results, indent=2, ensure_ascii=True, default=str))
886890
except ValueError as e:
887891
typer.echo(f"Error: {e}", err=True)
888892
raise typer.Exit(1)

src/basic_memory/mcp/tools/chatgpt_tools.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,15 @@ async def fetch(
184184
config = ConfigManager().config
185185
default_project = config.default_project
186186

187-
# Call underlying read_note function
188-
content = await read_note(
189-
identifier=id,
190-
project=default_project, # Use default project for ChatGPT
191-
page=1,
192-
page_size=10, # Default pagination
193-
context=context,
187+
# Call underlying read_note function (default output_format="text" returns str)
188+
content = str(
189+
await read_note(
190+
identifier=id,
191+
project=default_project, # Use default project for ChatGPT
192+
page=1,
193+
page_size=10, # Default pagination
194+
context=context,
195+
)
194196
)
195197

196198
# Format the document for ChatGPT

src/basic_memory/mcp/tools/view_note.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,16 @@ async def view_note(
5858
"""
5959
logger.info(f"Viewing note: {identifier} in project: {project}")
6060

61-
# Call the existing read_note logic
62-
content = await read_note(
63-
identifier=identifier,
64-
project=project,
65-
workspace=workspace,
66-
page=page,
67-
page_size=page_size,
68-
context=context,
61+
# Call the existing read_note logic (default output_format="text" returns str)
62+
content = str(
63+
await read_note(
64+
identifier=identifier,
65+
project=project,
66+
workspace=workspace,
67+
page=page,
68+
page_size=page_size,
69+
context=context,
70+
)
6971
)
7072

7173
# Check if this is an error message (note not found)

0 commit comments

Comments
 (0)