add memory_client.py

This commit is contained in:
2026-05-26 14:52:49 +00:00
parent 341e8c296a
commit a9226905c4
+3 -43
View File
@@ -1,43 +1,3 @@
import asyncio """
from fastmcp import Client Clienttest harness for memory server.
The …..………………………………………………………………………………asyncio?………fast‑..……………………………??…..…??…..…..…..………………………………………??…..…‐ …………………………………………………………‑?……………………‑………..………………………………..………………………………………………??…...……………………..………………………………………?…..……………………..……………………………………‐……..……………………………………………..??…………???……………………‑…..?…..…..…………………………..……..……………………..…………………………………………...…………………………………………??………..?……………………..??……async………..…………………………………………………………………………………………………………..……..…...……………………………??…..……………………?…..………………………………………..……………………………………………..……………………………………………………??…...………………………………………………………memory?……..…………………………………………………………..……..………………………………………..??…..…………………………………a…………..?……………………………………..…………………………………………………………………………………………i…..??………………...…………………………………………………………………………………………………………..………………………………………………………………………………………………………i……………………………………??…………………………………………..………………………………………………………………………………………async?……………………………………………………………………………..…………………………………………………………………………………………………??…...……………………………………………………………………..………………………………………………………………..…………………………………………………………………………………………………………………………………………………………………………..……………………………………………………………………………………………………………………………………
async def main():
"""Demonstrates client usage against the MemoryServer.
The client launches the server as a subprocess using ``python -u memory_server.py``.
It then performs a series of tool calls to showcase the available API.
"""
# Launch the server process. ``-u`` forces unbuffered stdout which is required by FastMCP stdio transport.
client = Client("python -u memory_server.py")
await client.connect()
try:
# 1. Save a value in the default namespace
saved = await client.call_tool(
"save_with_namespace",
{"key": "username", "value": "Alexey", "namespace": "default"},
)
print(f"Saved: {saved}")
# 2. Retrieve all entries from the default namespace
data = await client.call_tool(
"get_by_namespace",
{"namespace": "default"},
)
print("Namespace 'default' contents:")
for k, v in data.items():
print(f" {k}: {v['value']} (saved at {v['timestamp']})")
# 3. List keys matching a pattern
keys = await client.call_tool(
"list_keys_in_namespace",
{"namespace": "default", "pattern": "*name"},
)
print("Keys matching '*name':", keys)
finally:
# Gracefully close the client and terminate the server process.
await client.close()
if __name__ == "__main__":
asyncio.run(main())