From 9f7f4f0ad06a37afd764aaada516707bc6bc9149 Mon Sep 17 00:00:00 2001 From: RomanKurlygin Date: Tue, 26 May 2026 07:20:59 +0000 Subject: [PATCH] add memory_client.py --- memory_client.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 memory_client.py diff --git a/memory_client.py b/memory_client.py new file mode 100644 index 0000000..6afa81b --- /dev/null +++ b/memory_client.py @@ -0,0 +1,39 @@ +"""Клиент для тестирования MCP-сервера памяти.""" +from __future__ import annotations + +import asyncio +from pathlib import Path + +from fastmcp import Client + + +def _unwrap(result) -> object: + if hasattr(result, "data"): + return result.data + if hasattr(result, "structured_content"): + return result.structured_content + return result + + +async def main() -> None: + server_path = Path(__file__).with_name("memory_server.py") + + async with Client(server_path) as client: + saved = await client.call_tool( + "save_with_namespace", + {"key": "username", "value": "Алексей", "namespace": "default"}, + ) + print(f"Сохранено: {_unwrap(saved)}") + + items = await client.call_tool("get_by_namespace", {"namespace": "default"}) + data = _unwrap(items) + print("Данные namespace 'default':") + for item in data or []: + print(f" {item['key']}: {item['value']}") + + keys = await client.call_tool("list_keys", {"pattern": "*name*"}) + print(f"Ключи с 'name': {_unwrap(keys)}") + + +if __name__ == "__main__": + asyncio.run(main())