add memory_client.py
This commit is contained in:
@@ -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())
|
||||||
Reference in New Issue
Block a user