Skip to content

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

Merged
ntkathole merged 1 commit into
feast-dev:masterfrom
larrysingleton007:fix/mcp-server-import-flake
Jul 23, 2026
Merged

fix: Avoid importing feast.feature_store at mcp_server import time#6634
ntkathole merged 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.

@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 (7ae64ec) to head (47c89b6).
⚠️ Report is 1 commits behind head on master.
❗ 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.75%   45.74%   -0.01%     
==========================================
  Files         414      414              
  Lines       49701    49698       -3     
  Branches     7087     7087              
==========================================
- Hits        22739    22736       -3     
  Misses      25377    25377              
  Partials     1585     1585              
Flag Coverage Δ *Carryforward flag
go-feature-server 30.58% <ø> (ø)
python-unit 47.00% <ø> (-0.01%) ⬇️ Carriedforward from 7ae64ec

*This pull request uses carry forward flags. Click here to find out more.

Files with missing lines Coverage Δ
sdk/python/feast/infra/mcp_servers/mcp_server.py 84.84% <ø> (-0.66%) ⬇️

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 7ae64ec...47c89b6. 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.

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>
@ntkathole
ntkathole force-pushed the fix/mcp-server-import-flake branch from 9578b51 to 47c89b6 Compare July 23, 2026 10:11
@ntkathole
ntkathole merged commit ddb2e9a into feast-dev:master Jul 23, 2026
13 of 22 checks passed
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