Agent_week_6 / backend /test_client.py
Mohanp76's picture
Deploy project
5545e4d
Raw
History Blame Contribute Delete
1.14 kB
import asyncio
import subprocess
from pathlib import Path
from mcp.client.stdio import stdio_client
from mcp import StdioServerParameters, ClientSession
params = StdioServerParameters(
command="uv",
args=["run", "-m", "backend.accounts_server"],
cwd=str(Path(__file__).resolve().parent.parent),
env=None,
)
async def read_accounts_resource(name):
async with stdio_client(params, errlog=subprocess.DEVNULL) as streams:
async with ClientSession(*streams) as session:
await session.initialize()
result = await session.read_resource(f"accounts://accounts_server/{name}")
return result.contents[0].text
async def read_strategy_resource(name):
async with stdio_client(params, errlog=subprocess.DEVNULL) as streams:
async with ClientSession(*streams) as session:
await session.initialize()
result = await session.read_resource(f"accounts://strategy/{name}")
return result.contents[0].text
async def main():
result = await read_accounts_resource("warren")
print(result)
if __name__ == "__main__":
asyncio.run(main())