Skip to content

fix: Avoid importing feast.feature_store at mcp_server import time#6634

Open
larrysingleton007 wants to merge 1 commit into
feast-dev:masterfrom
larrysingleton007:fix/mcp-server-import-flake
Open

fix: Avoid importing feast.feature_store at mcp_server import time#6634
larrysingleton007 wants to merge 1 commit into
feast-dev:masterfrom
larrysingleton007:fix/mcp-server-import-flake

Conversation

@larrysingleton007

Copy link
Copy Markdown
Contributor

What this PR does / why we need it:

feast/infra/mcp_servers/mcp_server.py imported feast.feature_store.FeatureStore at module load, but used it only 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 the entire feature_store import graph in as a side effect.

Under parallel unit-test collection (pytest -n), that heavy import intermittently raced with an in-progress feature_store import and failed collection of tests/unit/infra/feature_servers/test_mcp_server.py with KeyError: 'feast.infra.mcp_servers.mcp_server'. The tests pass in isolation, so it shows up as a flaky unit-test-python failure.

Moving the import under TYPE_CHECKING with a forward-reference annotation removes feature_store from mcp_server's module-load path, so importing mcp_server no longer triggers that graph. Public API and the annotation are unchanged.

Which issue(s) this PR fixes:

Fixes #6633

Checks

  • I've made sure the tests are passing.
  • My commits are signed off (git commit -s)
  • My PR title follows conventional commits format

Testing Strategy

  • Unit tests
  • Integration tests
  • Manual tests
  • Testing is not required for this change

test_mcp_server.py passes (23), and feast.infra.mcp_servers still exposes add_mcp_support_to_app and McpFeatureServerConfig. ruff and mypy clean.

Misc

Release note: NONE.

As an outside contributor I can't apply labels, so a maintainer will need to add kind/bug and run ok-to-test.

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>
@codecov-commenter

codecov-commenter commented Jul 23, 2026

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 45.74%. Comparing base (54da19a) to head (9578b51).
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #6634      +/-   ##
==========================================
- Coverage   45.74%   45.74%   -0.01%     
==========================================
  Files         414      414              
  Lines       49668    49667       -1     
  Branches     7078     7078              
==========================================
- Hits        22723    22722       -1     
  Misses      25366    25366              
  Partials     1579     1579              
Flag Coverage Δ
go-feature-server 30.58% <ø> (ø)
python-unit 47.00% <100.00%> (-0.01%) ⬇️
Files with missing lines Coverage Δ
sdk/python/feast/infra/mcp_servers/mcp_server.py 85.29% <100.00%> (-0.22%) ⬇️

Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 54da19a...9578b51. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flaky unit-test collection: KeyError importing feast.infra.mcp_servers.mcp_server under pytest -n

3 participants