@@ -74,6 +74,7 @@ def error(request: Request) -> None:
7474class AppContext :
7575 open_note_results : Queue [Future [QueryParams ]]
7676 create_results : Queue [Future [QueryParams ]]
77+ add_text_results : Queue [Future [QueryParams ]]
7778 tags_results : Queue [Future [QueryParams ]]
7879 open_tag_results : Queue [Future [QueryParams ]]
7980 todo_results : Queue [Future [QueryParams ]]
@@ -103,6 +104,7 @@ async def app_lifespan(_server: FastMCP, uds: Path) -> AsyncIterator[AppContext]
103104 yield AppContext (
104105 open_note_results = register_callback (callback , "open-note" ),
105106 create_results = register_callback (callback , "create" ),
107+ add_text_results = register_callback (callback , "add-text" ),
106108 tags_results = register_callback (callback , "tags" ),
107109 open_tag_results = register_callback (callback , "open-tag" ),
108110 todo_results = register_callback (callback , "todo" ),
@@ -186,6 +188,47 @@ async def create(
186188
187189 return res .get ("identifier" ) or ""
188190
191+ @mcp .tool ()
192+ async def replace_note (
193+ ctx : Context ,
194+ id : str | None = Field (description = "note unique identifier" , default = None ),
195+ title : str | None = Field (description = "new title for the note" , default = None ),
196+ text : str | None = Field (description = "new text to replace note content" , default = None ),
197+ tags : list [str ] | None = Field (description = "list of tags to add to the note" , default = None ),
198+ timestamp : bool = Field (description = "prepend the current date and time to the text" , default = False ),
199+ ) -> str :
200+ """Replace the content of an existing note identified by its id."""
201+ app_ctx : AppContext = ctx .request_context .lifespan_context # type: ignore
202+ future = Future [QueryParams ]()
203+ await app_ctx .add_text_results .put (future )
204+
205+ mode = "replace_all" if title is not None else "replace"
206+
207+ params = {
208+ "mode" : mode ,
209+ "open_note" : "no" ,
210+ "new_window" : "no" ,
211+ "show_window" : "no" ,
212+ "edit" : "no" ,
213+ "x-success" : f"xfwder://{ uds .stem } /add-text/success" ,
214+ "x-error" : f"xfwder://{ uds .stem } /add-text/error" ,
215+ }
216+ if id is not None :
217+ params ["id" ] = id
218+ if text is not None :
219+ params ["text" ] = text
220+ if title is not None :
221+ params ["title" ] = title
222+ if tags is not None :
223+ params ["tags" ] = "," .join (tags )
224+ if timestamp :
225+ params ["timestamp" ] = "yes"
226+
227+ webbrowser .open (f"{ BASE_URL } /add-text?{ urlencode (params , quote_via = quote )} " )
228+ res = await future
229+
230+ return unquote_plus (res .get ("note" ) or "" )
231+
189232 @mcp .tool ()
190233 async def tags (
191234 ctx : Context ,
0 commit comments