Enable notes_search_results and get_note tools
This commit is contained in:
@@ -136,8 +136,25 @@ class NextcloudClient:
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
|
||||
def notes_search_notes(self, *, query: str):
|
||||
all_notes = self.notes_get_all()
|
||||
search_results = []
|
||||
query_lower = query.lower()
|
||||
for note in all_notes:
|
||||
title_lower = note.get("title", "").lower()
|
||||
content_lower = note.get("content", "").lower()
|
||||
if query_lower in title_lower or query_lower in content_lower:
|
||||
search_results.append(
|
||||
{
|
||||
"id": note.get("id"),
|
||||
"title": note.get("title"),
|
||||
"category": note.get("category"),
|
||||
"modified": note.get("modified"),
|
||||
}
|
||||
)
|
||||
return search_results
|
||||
|
||||
def notes_delete_note(self, *, note_id: int):
|
||||
response = self._client.delete(f"index.php/apps/notes/api/v1/notes/{note_id}")
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ def nc_get_capabilities():
|
||||
ctx = (
|
||||
mcp.get_context()
|
||||
) # https://github.com/modelcontextprotocol/python-sdk/issues/244
|
||||
client = ctx.request_context.lifespan_context.client
|
||||
client: NextcloudClient = ctx.request_context.lifespan_context.client
|
||||
return client.capabilities()
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ def notes_get_settings():
|
||||
ctx = (
|
||||
mcp.get_context()
|
||||
) # https://github.com/modelcontextprotocol/python-sdk/issues/244
|
||||
client = ctx.request_context.lifespan_context.client
|
||||
client: NextcloudClient = ctx.request_context.lifespan_context.client
|
||||
return client.notes_get_settings()
|
||||
|
||||
|
||||
@@ -62,24 +62,24 @@ def nc_notes_get_all():
|
||||
ctx = (
|
||||
mcp.get_context()
|
||||
) # https://github.com/modelcontextprotocol/python-sdk/issues/244
|
||||
client = ctx.request_context.lifespan_context.client
|
||||
client: NextcloudClient = ctx.request_context.lifespan_context.client
|
||||
return client.notes_get_all()
|
||||
|
||||
|
||||
@mcp.resource("notes://{note_id}")
|
||||
def nc_notes_get_note(note_id: int):
|
||||
# Removed nc_notes_get_note resource
|
||||
|
||||
|
||||
@mcp.tool()
|
||||
def get_note(note_id: int, ctx: Context):
|
||||
"""Get user note using note id"""
|
||||
ctx = (
|
||||
mcp.get_context()
|
||||
) # https://github.com/modelcontextprotocol/python-sdk/issues/244
|
||||
client = ctx.request_context.lifespan_context.client
|
||||
client: NextcloudClient = ctx.request_context.lifespan_context.client
|
||||
return client.notes_get_note(note_id=note_id)
|
||||
|
||||
|
||||
@mcp.tool()
|
||||
def nc_notes_create_note(title: str, content: str, category: str, ctx: Context):
|
||||
"""Create a new note"""
|
||||
client = ctx.request_context.lifespan_context.client
|
||||
client: NextcloudClient = ctx.request_context.lifespan_context.client
|
||||
return client.notes_create_note(
|
||||
title=title,
|
||||
content=content,
|
||||
@@ -97,7 +97,7 @@ def nc_notes_update_note(
|
||||
ctx: Context,
|
||||
):
|
||||
logger.info("Updating note %s", note_id)
|
||||
client = ctx.request_context.lifespan_context.client
|
||||
client: NextcloudClient = ctx.request_context.lifespan_context.client
|
||||
return client.notes_update_note(
|
||||
note_id=note_id,
|
||||
etag=etag,
|
||||
@@ -107,10 +107,17 @@ def nc_notes_update_note(
|
||||
)
|
||||
|
||||
|
||||
@mcp.tool()
|
||||
def nc_notes_search_notes(query: str, ctx: Context):
|
||||
"""Search notes by title or content, returning only id, title, and category."""
|
||||
client: NextcloudClient = ctx.request_context.lifespan_context.client
|
||||
return client.notes_search_notes(query=query)
|
||||
|
||||
|
||||
@mcp.tool()
|
||||
def nc_notes_delete_note(note_id: int, ctx: Context):
|
||||
logger.info("Deleting note %s", note_id)
|
||||
client = ctx.request_context.lifespan_context.client
|
||||
client: NextcloudClient = ctx.request_context.lifespan_context.client
|
||||
return client.notes_delete_note(note_id=note_id)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user