34 lines
953 B
Python
34 lines
953 B
Python
import asyncio
|
|
from fastmcp import Client
|
|
|
|
|
|
async def main():
|
|
client = Client("python memory_server.py")
|
|
await client.connect()
|
|
try:
|
|
# Save a value in the default namespace
|
|
saved = await client.call_tool(
|
|
"save_with_namespace",
|
|
{"key": "username", "value": "Алексей", "namespace": "default"}
|
|
)
|
|
print(f"Saved: {saved}")
|
|
|
|
# Retrieve all values from the default namespace
|
|
data = await client.call_tool(
|
|
"get_by_namespace",
|
|
{"namespace": "default"}
|
|
)
|
|
print("Data in namespace 'default':")
|
|
for item in data:
|
|
print(f" {item['key']}: {item['value']}")
|
|
|
|
# List keys matching a pattern
|
|
keys = await client.call_tool("list_keys", {"pattern": "*name"})
|
|
print(f"Keys matching '*name': {keys}")
|
|
|
|
finally:
|
|
await client.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main()) |