Add memory_client.py

This commit is contained in:
2026-06-02 07:05:34 +00:00
parent 4bbb7112ec
commit 6a65d9f9e4
+36
View File
@@ -0,0 +1,36 @@
"""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())