from tool_search import TAVILY_TOOL from connector_browser import ALL_BROWSER_MCP_TOOLS from connector_gmail import ALL_GMAIL_MCP_TOOLS from connector_calendar import ALL_CALENDAR_MCP_TOOLS from connector_drive import ALL_DRIVE_MCP_TOOLS from connector_sheets import ALL_SHEETS_MCP_TOOLS from connector_docs import ALL_DOCS_MCP_TOOLS from connector_slides import ALL_SLIDES_MCP_TOOLS from connector_youtube import ALL_YOUTUBE_MCP_TOOLS from connector_notion import ALL_NOTION_MCP_TOOLS from connector_github import ALL_GITHUB_MCP_TOOLS from connector_telegram import ALL_TELEGRAM_MCP_TOOLS from connector_vercel import ALL_VERCEL_MCP_TOOLS def build_dynamic_discover_tool(active_services: list) -> dict: return { "type": "function", "function": { "name": "discover_connector_capabilities", "description": f"Discover available API operations, endpoints, and schema guidelines for connected services: {', '.join(active_services)}.", "parameters": { "type": "object", "properties": { "service": { "type": "string", "enum": active_services, "description": "The connected service name to query capabilities and endpoint patterns for." }, "query": { "type": "string", "description": "Optional search term for specific capabilities, e.g., 'send email', 'create issue', 'query database', 'send telegram message', 'browse webpage'." } }, "required": ["service"] } } } def get_filtered_tools(connectors: list = None, web_search: bool = False) -> list: active_tools = [] if web_search: active_tools.append(TAVILY_TOOL) if not connectors or not isinstance(connectors, list): return active_tools connector_keys = {str(c).lower().strip() for c in connectors} active_services = [] if "browser" in connector_keys or "web" in connector_keys: active_tools.extend(ALL_BROWSER_MCP_TOOLS) active_services.append("browser") if "gmail" in connector_keys or "google" in connector_keys: active_tools.extend(ALL_GMAIL_MCP_TOOLS) active_services.append("gmail") if "calendar" in connector_keys or "google" in connector_keys: active_tools.extend(ALL_CALENDAR_MCP_TOOLS) active_services.append("calendar") if "drive" in connector_keys or "google" in connector_keys: active_tools.extend(ALL_DRIVE_MCP_TOOLS) active_services.append("drive") if "sheets" in connector_keys or "google" in connector_keys: active_tools.extend(ALL_SHEETS_MCP_TOOLS) active_services.append("sheets") if "docs" in connector_keys or "google" in connector_keys: active_tools.extend(ALL_DOCS_MCP_TOOLS) active_services.append("docs") if "slides" in connector_keys or "google" in connector_keys: active_tools.extend(ALL_SLIDES_MCP_TOOLS) active_services.append("slides") if "youtube" in connector_keys or "google" in connector_keys: active_tools.extend(ALL_YOUTUBE_MCP_TOOLS) active_services.append("youtube") if "notion" in connector_keys: active_tools.extend(ALL_NOTION_MCP_TOOLS) active_services.append("notion") if "github" in connector_keys: active_tools.extend(ALL_GITHUB_MCP_TOOLS) active_services.append("github") if "telegram" in connector_keys: active_tools.extend(ALL_TELEGRAM_MCP_TOOLS) active_services.append("telegram") if "vercel" in connector_keys: active_tools.extend(ALL_VERCEL_MCP_TOOLS) active_services.append("vercel") if active_services: active_tools.append(build_dynamic_discover_tool(active_services)) return active_tools