import contextlib from mcp import ClientSession from mcp.client.streamable_http import streamable_http_client from config import MCP_URL class MCPClient: def __init__(self): self.session = None self.exit_stack = contextlib.AsyncExitStack() async def connect(self): """ Verbindung zum OpenHAB MCP Server """ transport = await self.exit_stack.enter_async_context( streamable_http_client(MCP_URL) ) read, write, _ = transport self.session = await self.exit_stack.enter_async_context( ClientSession(read, write) ) await self.session.initialize() return self.session 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): await self.exit_stack.aclose()