Files
2026-05-25 22:03:22 +00:00

44 lines
1.3 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Клиент для тестирования 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())