From 9578b51324e29e7a46fd7b7dc6021fee03e4d89f Mon Sep 17 00:00:00 2001 From: Larry Singleton <166439969+larrysingleton007@users.noreply.github.com> Date: Wed, 22 Jul 2026 22:43:20 -0500 Subject: [PATCH] fix: Avoid importing feast.feature_store at mcp_server import time mcp_server used a module-level `from feast.feature_store import FeatureStore` solely for a type annotation on add_mcp_support_to_app. Because the feast.infra.mcp_servers package __init__ eagerly imports mcp_server, importing the package pulled in the entire feature_store import graph. Under parallel unit-test collection (pytest -n) this intermittently raced with an in-progress feature_store import and failed collection of test_mcp_server.py with `KeyError: 'feast.infra.mcp_servers.mcp_server'`. Move the import under TYPE_CHECKING and use a forward reference, so importing mcp_server no longer triggers the feature_store graph. Public API and the annotation are unchanged. Signed-off-by: Larry Singleton <166439969+larrysingleton007@users.noreply.github.com> --- sdk/python/feast/infra/mcp_servers/mcp_server.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sdk/python/feast/infra/mcp_servers/mcp_server.py b/sdk/python/feast/infra/mcp_servers/mcp_server.py index 225f721fa34..2be788148cd 100644 --- a/sdk/python/feast/infra/mcp_servers/mcp_server.py +++ b/sdk/python/feast/infra/mcp_servers/mcp_server.py @@ -6,9 +6,10 @@ """ import logging -from typing import Any, Dict, Optional, Set +from typing import TYPE_CHECKING, Any, Dict, Optional, Set -from feast.feature_store import FeatureStore +if TYPE_CHECKING: + from feast.feature_store import FeatureStore logger = logging.getLogger(__name__) @@ -97,7 +98,9 @@ def _patch_fastapi_mcp_schema_resolver() -> None: pass -def add_mcp_support_to_app(app, store: FeatureStore, config) -> Optional["FastApiMCP"]: +def add_mcp_support_to_app( + app, store: "FeatureStore", config +) -> Optional["FastApiMCP"]: """Add MCP support to the FastAPI app if enabled in configuration.""" if not MCP_AVAILABLE: logger.warning("MCP support requested but fastapi_mcp is not available")