44from contextlib import asynccontextmanager
55from dataclasses import dataclass
66from mcp .server .fastmcp import FastMCP , Context
7- from mcp .server import Server
87from collections .abc import AsyncIterator
98from nextcloud_mcp_server .client import NextcloudClient
10- import asyncio # Import asyncio
119
1210setup_logging ()
1311
@@ -28,7 +26,7 @@ async def app_lifespan(server: FastMCP) -> AsyncIterator[AppContext]:
2826 yield AppContext (client = client )
2927 finally :
3028 # Cleanup on shutdown
31- client ._client .close ()
29+ await client ._client .aclose ()
3230
3331
3432# Create an MCP server
@@ -38,46 +36,46 @@ async def app_lifespan(server: FastMCP) -> AsyncIterator[AppContext]:
3836
3937
4038@mcp .resource ("nc://capabilities" )
41- def nc_get_capabilities ():
39+ async def nc_get_capabilities ():
4240 """Get the Nextcloud Host capabilities"""
4341 # client = NextcloudClient.from_env()
4442 ctx = (
4543 mcp .get_context ()
4644 ) # https://github.com/modelcontextprotocol/python-sdk/issues/244
4745 client : NextcloudClient = ctx .request_context .lifespan_context .client
48- return client .capabilities ()
46+ return await client .capabilities ()
4947
5048
5149@mcp .resource ("notes://settings" )
52- def notes_get_settings ():
50+ async def notes_get_settings ():
5351 """Get the Notes App settings"""
5452 ctx = (
5553 mcp .get_context ()
5654 ) # https://github.com/modelcontextprotocol/python-sdk/issues/244
5755 client : NextcloudClient = ctx .request_context .lifespan_context .client
58- return client .notes_get_settings ()
56+ return await client .notes_get_settings ()
5957
6058
6159@mcp .tool ()
62- def nc_get_note (note_id : int , ctx : Context ):
60+ async def nc_get_note (note_id : int , ctx : Context ):
6361 """Get user note using note id"""
6462 client : NextcloudClient = ctx .request_context .lifespan_context .client
65- return client .notes_get_note (note_id = note_id )
63+ return await client .notes_get_note (note_id = note_id )
6664
6765
6866@mcp .tool ()
69- def nc_notes_create_note (title : str , content : str , category : str , ctx : Context ):
67+ async def nc_notes_create_note (title : str , content : str , category : str , ctx : Context ):
7068 """Create a new note"""
7169 client : NextcloudClient = ctx .request_context .lifespan_context .client
72- return client .notes_create_note (
70+ return await client .notes_create_note (
7371 title = title ,
7472 content = content ,
7573 category = category ,
7674 )
7775
7876
7977@mcp .tool ()
80- def nc_notes_update_note (
78+ async def nc_notes_update_note (
8179 note_id : int ,
8280 etag : str ,
8381 title : str | None ,
@@ -87,7 +85,7 @@ def nc_notes_update_note(
8785):
8886 logger .info ("Updating note %s" , note_id )
8987 client : NextcloudClient = ctx .request_context .lifespan_context .client
90- return client .notes_update_note (
88+ return await client .notes_update_note (
9189 note_id = note_id ,
9290 etag = etag ,
9391 title = title ,
@@ -97,35 +95,35 @@ def nc_notes_update_note(
9795
9896
9997@mcp .tool ()
100- def nc_notes_append_content (note_id : int , content : str , ctx : Context ):
98+ async def nc_notes_append_content (note_id : int , content : str , ctx : Context ):
10199 """Append content to an existing note with a clear separator"""
102100 logger .info ("Appending content to note %s" , note_id )
103101 client : NextcloudClient = ctx .request_context .lifespan_context .client
104- return client .notes_append_content (note_id = note_id , content = content )
102+ return await client .notes_append_content (note_id = note_id , content = content )
105103
106104
107105@mcp .tool ()
108- def nc_notes_search_notes (query : str , ctx : Context ):
106+ async def nc_notes_search_notes (query : str , ctx : Context ):
109107 """Search notes by title or content, returning only id, title, and category."""
110108 client : NextcloudClient = ctx .request_context .lifespan_context .client
111- return client .notes_search_notes (query = query )
109+ return await client .notes_search_notes (query = query )
112110
113111
114112@mcp .tool ()
115- def nc_notes_delete_note (note_id : int , ctx : Context ):
113+ async def nc_notes_delete_note (note_id : int , ctx : Context ):
116114 logger .info ("Deleting note %s" , note_id )
117115 client : NextcloudClient = ctx .request_context .lifespan_context .client
118- return client .notes_delete_note (note_id = note_id )
116+ return await client .notes_delete_note (note_id = note_id )
119117
120118
121119@mcp .resource ("nc://Notes/{note_id}/attachments/{attachment_filename}" )
122- def nc_notes_get_attachment (note_id : int , attachment_filename : str ):
120+ async def nc_notes_get_attachment (note_id : int , attachment_filename : str ):
123121 """Get a specific attachment from a note"""
124122 ctx = mcp .get_context ()
125123 client : NextcloudClient = ctx .request_context .lifespan_context .client
126124 # Assuming a method get_note_attachment exists in the client
127125 # This method should return the raw content and determine the mime type
128- content , mime_type = client .get_note_attachment (
126+ content , mime_type = await client .get_note_attachment (
129127 note_id = note_id , filename = attachment_filename
130128 )
131129 return {
0 commit comments