37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
"""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())
|