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:
Paul Hernandez
2025-10-13 10:44:35 -05:00
committed by GitHub
parent c0538ad2dd
commit 2b7008d997
6 changed files with 2028 additions and 74 deletions
+11 -2
View File
@@ -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,
+14 -28
View File
@@ -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()