From b11aa046aab9fa175da2a8e42c6ead849141c975 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:53:21 +0000 Subject: [PATCH] rewrite memory_client.py --- memory_client.py | 57 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/memory_client.py b/memory_client.py index 1e5fa57..98b7b38 100644 --- a/memory_client.py +++ b/memory_client.py @@ -1,3 +1,56 @@ """ -Client‑test harness for memory server. -The …..………………………………………………………………………………asyncio?………fast‑..……………………………??…..…??…..…..…..………………………………………??…..…‐ …………………………………………………………‑?……………………‑………..………………………………..………………………………………………??…...……………………..………………………………………?…..……………………..……………………………………‐……..……………………………………………..??…………???……………………‑…..?…..…..…………………………..……..……………………..…………………………………………...…………………………………………??………..?……………………..??……async………..…………………………………………………………………………………………………………..……..…...……………………………??…..……………………?…..………………………………………..……………………………………………..……………………………………………………??…...………………………………………………………memory?……..…………………………………………………………..……..………………………………………..??…..…………………………………a…………..?……………………………………..…………………………………………………………………………………………i…..??………………...…………………………………………………………………………………………………………..………………………………………………………………………………………………………i……………………………………??…………………………………………..………………………………………………………………………………………async?……………………………………………………………………………..…………………………………………………………………………………………………??…...……………………………………………………………………..………………………………………………………………..…………………………………………………………………………………………………………………………………………………………………………..…………………………………………………………………………………………………………………………………… \ No newline at end of file +Memory client example for the MCP memory server. + +The script demonstrates how an external agent or CLI tool can connect to the +``memory_server`` via the stdio transport and invoke its tools. + +It performs three operations: +1. Saves a value under ``default:username`` using ``save_with_namespace``. +2. Retrieves all items in the ``default`` namespace with ``get_by_namespace``. +3. Lists keys that match a glob pattern via ``list_keys``. + +The output is printed to stdout and should look similar to: + +:: + Сохранено: True + Данные namespace 'default': + username: Алексей + Ключи с 'name': ['default:user_name'] +""" + +import asyncio +from fastmcp import Client + +async def main(): + # Launch the server as a subprocess and connect via stdio. + client = Client("python memory_server.py") + await client.connect() + + try: + # 1. Save a value in the default namespace. + result = await client.call_tool( + "save_with_namespace", + {"key": "username", "value": "Алексей", "namespace": "default"}, + ) + print(f"Сохранено: {result}") + + # 2. Retrieve all items in the default namespace. + items = await client.call_tool( + "get_by_namespace", + {"namespace": "default"}, + ) + print("Данные namespace 'default':") + for item in items: + print(f" {item['key']}: {item['value']}") + + # 3. List keys matching a pattern. + keys = await client.call_tool( + "list_keys", + {"pattern": "*name"}, + ) + print("Ключи с 'name':", keys) + finally: + await client.close() + +if __name__ == "__main__": + asyncio.run(main())