youtube-summarizer/backend/core/mcp_client.py

52 lines
1.6 KiB
Python

"""
MCP client helper for video downloader integration
"""
import logging
from typing import Optional, Dict, Any
logger = logging.getLogger(__name__)
class MockMCPClient:
"""Mock MCP client when MCP servers are not available"""
async def call_tool(self, tool_name: str, params: Dict[str, Any]) -> Any:
"""Mock tool call that raises an exception"""
raise Exception(f"MCP server not available for tool: {tool_name}")
class MCPClientManager:
"""Manager for MCP client connections"""
def __init__(self):
self.clients = {}
self._initialize_clients()
def _initialize_clients(self):
"""Initialize MCP clients"""
# For now, we'll use mock clients since MCP integration is complex
# In a real implementation, you would connect to actual MCP servers
self.clients = {
'playwright': MockMCPClient(),
'browser-tools': MockMCPClient(),
'yt-dlp': MockMCPClient()
}
logger.info("Initialized MCP client manager with mock clients")
def get_client(self, service_name: str) -> Optional[MockMCPClient]:
"""Get MCP client for a service"""
return self.clients.get(service_name)
# Global instance
_mcp_manager = MCPClientManager()
def get_mcp_client(service_name: str) -> MockMCPClient:
"""Get MCP client for a service"""
client = _mcp_manager.get_client(service_name)
if not client:
logger.warning(f"No MCP client available for service: {service_name}")
return MockMCPClient()
return client