diff --git a/mcp/client.py b/mcp/client.py new file mode 100644 index 0000000..2d7d2d3 --- /dev/null +++ b/mcp/client.py @@ -0,0 +1,26 @@ +from mcp import ClientSession +from mcp.client.streamable_http import streamable_http_client + + +class MCPClient: + def __init__(self, url: str): + self.url = url + self.session = None + self._client = None + + async def connect(self): + self._client = streamable_http_client(self.url) + read, write = await self._client.__aenter__() + + self.session = ClientSession(read, write) + await self.session.initialize() + + async def list_tools(self): + return await self.session.list_tools() + + async def call_tool(self, name, args): + return await self.session.call_tool(name, args) + + async def close(self): + if self._client: + await self._client.__aexit__(None, None, None) \ No newline at end of file