Add solution for 69f8e929da860fb4533faa2a
This commit is contained in:
+12
-19
@@ -1,33 +1,26 @@
|
|||||||
from __future__ import annotations
|
from fastmcp import Client
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
from fastmcp import Client
|
|
||||||
|
|
||||||
|
|
||||||
def unwrap(result):
|
|
||||||
return getattr(result, "data", result)
|
|
||||||
|
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
async with Client("memory_server.py") as client:
|
client = Client("python memory_server.py")
|
||||||
|
await client.connect()
|
||||||
|
try:
|
||||||
result = await client.call_tool(
|
result = await client.call_tool(
|
||||||
"save_with_namespace",
|
"save_with_namespace",
|
||||||
{"key": "username", "value": "\u0410\u043b\u0435\u043a\u0441\u0435\u0439", "namespace": "default"},
|
{"key": "username", "value": "Алексей", "namespace": "default"}
|
||||||
)
|
)
|
||||||
print(f"Сохранено: {unwrap(result)}")
|
print(f"Сохранено: {result}")
|
||||||
|
|
||||||
result = await client.call_tool(
|
result = await client.call_tool(
|
||||||
"get_by_namespace",
|
"get_by_namespace",
|
||||||
{"namespace": "default"},
|
{"namespace": "default"}
|
||||||
)
|
)
|
||||||
print("Данные namespace 'default':")
|
print("Данные namespace 'default':")
|
||||||
for item in unwrap(result):
|
for item in result:
|
||||||
print(f" {item['key']}: {item['value']}")
|
print(f" {item['key']}: {item['value']}")
|
||||||
|
|
||||||
keys = await client.call_tool("list_keys", {"pattern": "*name"})
|
keys = await client.call_tool("list_keys", {"pattern": "*name"})
|
||||||
print(f"Ключи с 'name': {unwrap(keys)}")
|
print(f"Ключи с 'name': {keys}")
|
||||||
|
finally:
|
||||||
|
await client.close()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
asyncio.run(main())
|
asyncio.run(main())
|
||||||
Reference in New Issue
Block a user