add memory_client.py
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
"""Клиент для тестирования MCP-сервера памяти."""
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from pathlib import Path
|
||||
|
||||
from fastmcp import Client
|
||||
|
||||
|
||||
def _unwrap(result) -> object:
|
||||
if hasattr(result, "data") and result.data is not None:
|
||||
return result.data
|
||||
if getattr(result, "structured_content", None):
|
||||
return result.structured_content
|
||||
return result
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
# Эквивалент Client("python memory_server.py") при запуске из этой папки
|
||||
server_path = Path(__file__).resolve().parent / "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:
|
||||
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