|
2 | 2 |
|
3 | 3 | import asyncio |
4 | 4 | import sys |
5 | | -from typing import Optional, List, Annotated |
| 5 | +from typing import Annotated, List, Optional |
6 | 6 |
|
7 | 7 | import typer |
8 | 8 | from loguru import logger |
9 | 9 | from rich import print as rprint |
10 | 10 |
|
11 | 11 | from basic_memory.cli.app import app |
12 | | -from basic_memory.mcp.tools import build_context as mcp_build_context |
13 | | -from basic_memory.mcp.tools import read_note as mcp_read_note |
14 | | -from basic_memory.mcp.tools import recent_activity as mcp_recent_activity |
15 | | -from basic_memory.mcp.tools import search_notes as mcp_search |
16 | | -from basic_memory.mcp.tools import write_note as mcp_write_note |
17 | 12 |
|
18 | 13 | # Import prompts |
19 | 14 | from basic_memory.mcp.prompts.continue_conversation import ( |
20 | 15 | continue_conversation as mcp_continue_conversation, |
21 | 16 | ) |
22 | | - |
23 | 17 | from basic_memory.mcp.prompts.recent_activity import ( |
24 | 18 | recent_activity_prompt as recent_activity_prompt, |
25 | 19 | ) |
26 | | - |
| 20 | +from basic_memory.mcp.tools import build_context as mcp_build_context |
| 21 | +from basic_memory.mcp.tools import read_note as mcp_read_note |
| 22 | +from basic_memory.mcp.tools import recent_activity as mcp_recent_activity |
| 23 | +from basic_memory.mcp.tools import search_notes as mcp_search |
| 24 | +from basic_memory.mcp.tools import write_note as mcp_write_note |
27 | 25 | from basic_memory.schemas.base import TimeFrame |
28 | 26 | from basic_memory.schemas.memory import MemoryUrl |
29 | | -from basic_memory.schemas.search import SearchQuery, SearchItemType |
| 27 | +from basic_memory.schemas.search import SearchItemType |
30 | 28 |
|
31 | 29 | tool_app = typer.Typer() |
32 | 30 | app.add_typer(tool_app, name="tool", help="Access to MCP tools via CLI") |
@@ -198,13 +196,28 @@ def search_notes( |
198 | 196 | raise typer.Abort() |
199 | 197 |
|
200 | 198 | try: |
201 | | - search_query = SearchQuery( |
202 | | - permalink_match=query if permalink else None, |
203 | | - text=query if not (permalink or title) else None, |
204 | | - title=query if title else None, |
205 | | - after_date=after_date, |
| 199 | + if permalink and title: # pragma: no cover |
| 200 | + typer.echo( |
| 201 | + "Use either --permalink or --title, not both. Exiting.", |
| 202 | + err=True, |
| 203 | + ) |
| 204 | + raise typer.Exit(1) |
| 205 | + |
| 206 | + # set search type |
| 207 | + search_type = ("permalink" if permalink else None,) |
| 208 | + search_type = ("permalink_match" if permalink and "*" in query else None,) |
| 209 | + search_type = ("title" if title else None,) |
| 210 | + search_type = "text" if search_type is None else search_type |
| 211 | + |
| 212 | + results = asyncio.run( |
| 213 | + mcp_search( |
| 214 | + query, |
| 215 | + search_type=search_type, |
| 216 | + page=page, |
| 217 | + after_date=after_date, |
| 218 | + page_size=page_size, |
| 219 | + ) |
206 | 220 | ) |
207 | | - results = asyncio.run(mcp_search(query=search_query, page=page, page_size=page_size)) |
208 | 221 | # Use json module for more controlled serialization |
209 | 222 | import json |
210 | 223 |
|
|
0 commit comments