Files
task-69f8e929da860fb4533faa2a/memory_client.py
T
2026-06-02 07:05:34 +00:00

37 lines
1.1 KiB
Python
Raw 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.
"""Client demo for MemoryServer.
Run with:
python memory_client.py
"""
import asyncio
from fastmcp import Client
async def main():
# Connect to the server via stdio. The server must be running in another terminal.
client = Client("python memory_server.py")
await client.connect()
try:
# Save a value in default namespace
res = await client.call_tool("save_with_namespace", {
"key": "username",
"value": "Алексей",
"namespace": "default",
})
print(f"Сохранено: {res}")
# Retrieve all items in default namespace
res = await client.call_tool("get_by_namespace", {"namespace": "default"})
print("Данные namespace 'default':")
for item in res:
print(f" {item['key']}: {item['value']}")
# List keys matching pattern
keys = await client.call_tool("list_keys", {"pattern": "*name"})
print("Ключи с 'name':", keys)
finally:
await client.close()
if __name__ == "__main__":
asyncio.run(main())