From 990142432007e0cd58067277e7bed5e5db94210d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B8=D1=80=D0=B8=D0=BB=D0=BB=20=D0=9A=D1=83=D1=82?= =?UTF-8?q?=D0=BB=D0=B0=D1=85=D0=BC=D0=B5=D1=82=D0=BE=D0=B2?= Date: Tue, 26 May 2026 14:47:05 +0000 Subject: [PATCH] add memory_client.py --- memory_client.py | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/memory_client.py b/memory_client.py index f2dac7d..c54e8ea 100644 --- a/memory_client.py +++ b/memory_client.py @@ -1,3 +1,43 @@ import asyncio from fastmcp import Client -async def main():c? \ No newline at end of file + +async def main(): + """Demonstrates client usage against the MemoryServer. + + The client launches the server as a subprocess using ``python -u memory_server.py``. + It then performs a series of tool calls to showcase the available API. + """ + # Launch the server process. ``-u`` forces unbuffered stdout which is required by FastMCP stdio transport. + client = Client("python -u memory_server.py") + await client.connect() + + try: + # 1. Save a value in the default namespace + saved = await client.call_tool( + "save_with_namespace", + {"key": "username", "value": "Alexey", "namespace": "default"}, + ) + print(f"Saved: {saved}") + + # 2. Retrieve all entries from the default namespace + data = await client.call_tool( + "get_by_namespace", + {"namespace": "default"}, + ) + print("Namespace 'default' contents:") + for k, v in data.items(): + print(f" {k}: {v['value']} (saved at {v['timestamp']})") + + # 3. List keys matching a pattern + keys = await client.call_tool( + "list_keys_in_namespace", + {"namespace": "default", "pattern": "*name"}, + ) + print("Keys matching '*name':", keys) + + finally: + # Gracefully close the client and terminate the server process. + await client.close() + +if __name__ == "__main__": + asyncio.run(main())