File size: 1,137 Bytes
5545e4d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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())