diff --git a/litellm/proxy/hooks/mcp_semantic_filter/hook.py b/litellm/proxy/hooks/mcp_semantic_filter/hook.py index 53a83c59049..9b109c3f908 100644 --- a/litellm/proxy/hooks/mcp_semantic_filter/hook.py +++ b/litellm/proxy/hooks/mcp_semantic_filter/hook.py @@ -237,7 +237,7 @@ class SemanticToolFilterHook(CustomLogger): return None @staticmethod - def initialize_from_config( + async def initialize_from_config( config: Optional[Dict[str, Any]], llm_router: Optional["Router"], ) -> Optional["SemanticToolFilterHook"]: @@ -282,6 +282,9 @@ class SemanticToolFilterHook(CustomLogger): enabled=True, ) + # Build router from MCP registry on startup + await semantic_filter.build_router_from_mcp_registry() + hook = SemanticToolFilterHook(semantic_filter) verbose_proxy_logger.info( diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index d724b88d41c..07598eaff15 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -800,7 +800,7 @@ async def proxy_startup_event(app: FastAPI): # noqa: PLR0915 _config = proxy_config.get_config_state() _litellm_settings = _config.get("litellm_settings", {}) verbose_proxy_logger.debug(f"litellm_settings keys = {list(_litellm_settings.keys())}") - ProxyStartupEvent._initialize_semantic_tool_filter( + await ProxyStartupEvent._initialize_semantic_tool_filter( llm_router=llm_router, litellm_settings=_litellm_settings, ) @@ -4757,7 +4757,7 @@ class ProxyStartupEvent: ) @classmethod - def _initialize_semantic_tool_filter( + async def _initialize_semantic_tool_filter( cls, llm_router: Optional[Router], litellm_settings: Dict[str, Any], @@ -4773,7 +4773,7 @@ class ProxyStartupEvent: mcp_semantic_filter_config = litellm_settings.get("mcp_semantic_tool_filter", None) verbose_proxy_logger.debug(f"Semantic filter config: {mcp_semantic_filter_config}") - hook = SemanticToolFilterHook.initialize_from_config( + hook = await SemanticToolFilterHook.initialize_from_config( config=mcp_semantic_filter_config, llm_router=llm_router, )