mirror of
https://github.com/basicmachines-co/basic-memory
synced 2026-06-21 13:47:35 +00:00
fix: Update view_note and ChatGPT tools for Claude Desktop compatibility (#355)
Signed-off-by: phernandez <paul@basicmachines.co> Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -14,6 +14,7 @@ from basic_memory.mcp.server import mcp
|
||||
from basic_memory.mcp.tools.search import search_notes
|
||||
from basic_memory.mcp.tools.read_note import read_note
|
||||
from basic_memory.schemas.search import SearchResponse
|
||||
from basic_memory.config import ConfigManager
|
||||
|
||||
|
||||
def _format_search_results_for_chatgpt(results: SearchResponse) -> List[Dict[str, Any]]:
|
||||
@@ -90,10 +91,14 @@ async def search(
|
||||
logger.info(f"ChatGPT search request: query='{query}'")
|
||||
|
||||
try:
|
||||
# ChatGPT tools don't expose project parameter, so use default project
|
||||
config = ConfigManager().config
|
||||
default_project = config.default_project
|
||||
|
||||
# Call underlying search_notes with sensible defaults for ChatGPT
|
||||
results = await search_notes.fn(
|
||||
query=query,
|
||||
project=None, # Let project resolution happen automatically
|
||||
project=default_project, # Use default project for ChatGPT
|
||||
page=1,
|
||||
page_size=10, # Reasonable default for ChatGPT consumption
|
||||
search_type="text", # Default to full-text search
|
||||
@@ -149,10 +154,14 @@ async def fetch(
|
||||
logger.info(f"ChatGPT fetch request: id='{id}'")
|
||||
|
||||
try:
|
||||
# ChatGPT tools don't expose project parameter, so use default project
|
||||
config = ConfigManager().config
|
||||
default_project = config.default_project
|
||||
|
||||
# Call underlying read_note function
|
||||
content = await read_note.fn(
|
||||
identifier=id,
|
||||
project=None, # Let project resolution happen automatically
|
||||
project=default_project, # Use default project for ChatGPT
|
||||
page=1,
|
||||
page_size=10, # Default pagination
|
||||
context=context,
|
||||
|
||||
@@ -22,14 +22,10 @@ async def view_note(
|
||||
) -> str:
|
||||
"""View a markdown note as a formatted artifact.
|
||||
|
||||
This tool reads a note using the same logic as read_note but displays the content
|
||||
as a markdown artifact for better viewing experience in Claude Desktop.
|
||||
This tool reads a note using the same logic as read_note but instructs Claude
|
||||
to display the content as a markdown artifact in the Claude Desktop app.
|
||||
Project parameter optional with server resolution.
|
||||
|
||||
After calling this tool, create an artifact using the returned content to display
|
||||
the note in a readable format. The tool returns the note content that should be
|
||||
used to create a markdown artifact.
|
||||
|
||||
Args:
|
||||
identifier: The title or permalink of the note to view
|
||||
project: Project name to read from. Optional - server will resolve using hierarchy.
|
||||
@@ -39,7 +35,7 @@ async def view_note(
|
||||
context: Optional FastMCP context for performance caching.
|
||||
|
||||
Returns:
|
||||
The note content as a markdown artifact with a confirmation message.
|
||||
Instructions for Claude to create a markdown artifact with the note content.
|
||||
|
||||
Examples:
|
||||
# View a note by title
|
||||
@@ -66,26 +62,16 @@ async def view_note(
|
||||
|
||||
# Check if this is an error message (note not found)
|
||||
if "# Note Not Found" in content:
|
||||
return content # Return error message directly instead of creating artifact
|
||||
|
||||
# Extract title from content if possible
|
||||
title = identifier
|
||||
lines = content.split("\n")
|
||||
for line in lines:
|
||||
if line.startswith("title:"):
|
||||
# Extract title from frontmatter
|
||||
title = line.split("title:", 1)[1].strip().strip('"').strip("'")
|
||||
break
|
||||
elif line.startswith("# "):
|
||||
# Extract title from first heading
|
||||
title = line[2:].strip()
|
||||
break
|
||||
|
||||
# Return the artifact XML as part of the response
|
||||
artifact = f'<artifact identifier="note-{hash(identifier) & 0x7FFFFFFF}" type="text/markdown" title="{title}">\n{content}\n</artifact>'
|
||||
return content # Return error message directly
|
||||
|
||||
# Return instructions for Claude to create an artifact
|
||||
return dedent(f"""
|
||||
<instructions>
|
||||
Create an artifact using the returned content to display the note in a readable format.
|
||||
</instructions>
|
||||
{artifact}\n\n✅ Note displayed as artifact: **{title}**""")
|
||||
Note retrieved: "{identifier}"
|
||||
|
||||
Display this note as a markdown artifact for the user.
|
||||
|
||||
Content:
|
||||
---
|
||||
{content}
|
||||
---
|
||||
""").strip()
|
||||
|
||||
Reference in New Issue
Block a user