fix(mcp): make the [mcp] extra installable and the server constructible - #388
Open
phaestos2501 wants to merge 1 commit into
Open
fix(mcp): make the [mcp] extra installable and the server constructible#388phaestos2501 wants to merge 1 commit into
phaestos2501 wants to merge 1 commit into
Conversation
Three problems prevented the MCP server from ever starting from a fresh install of .[mcp]: - fastmcp is imported by fle/env/protocols/_mcp and fle/mcp_dataloader but was not declared anywhere; declare it in the mcp extra. - Unpinned, pip resolves mcp 2.0, which removed McpError and broke fastmcp (fastmcp 2.14 only requires mcp>=1.24 with no upper bound); pin mcp[cli]>=1.24,<2. - FastMCP removed the 'dependencies' constructor kwarg, so creating the server raised TypeError; and the previous fallback crashed on 'mcp.lifespan = fle_lifespan' with mcp=None when fastmcp was missing. Worse, fastmcp only honours a lifespan passed to the constructor (it stores it in _lifespan at init), so the attribute assignment was silently ignored even when it did not crash. Define fle_lifespan before the server is created and pass it as the lifespan kwarg; late-bound module globals resolve by the time the session starts. Note: importing the package still requires running Factorio containers because _mcp/init.py builds FactorioMCPState eagerly at import time, and a fresh install additionally hits the a2a-sdk 1.x API break addressed by PR JackHopkins#372.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Three issues prevent the MCP server from starting from a fresh
pip install .[mcp]:fastmcpis undeclared.fle/env/protocols/_mcp/__init__.pyandfle/mcp_dataloader.pyimport it, but themcpextra only listsmcp[cli]anddulwich, so the package falls into the (broken, see 3) fallback path.mcpresolves to 2.0, which removedMcpErrorfrommcp.shared.exceptionsand breaks fastmcp at import (fastmcp 2.14 only requiresmcp>=1.24with no upper bound).dependenciesconstructor kwarg, soFastMCP(..., dependencies=[...])raisesTypeError— which theexcept ImportErrorguard doesn't catch. And when fastmcp is genuinely missing, the module still crashes onmcp.lifespan = fle_lifespanwithmcp = None. Additionally, fastmcp only honours a lifespan passed to the constructor (stored in_lifespanat init), so the post-hoc attribute assignment was silently ignored even when it didn't crash — sessions would run without the Factorio lifecycle manager.Fix
fastmcp>=2.14.0and pinmcp[cli]>=1.24.0,<2in themcpextra.fle_lifespanbefore the server is created and pass it as thelifespanconstructor kwarg (its late-bound module globals resolve by the time a session starts). The no-fastmcp fallback now imports cleanly withmcp = None.Verification
uv pip install -e '.[mcp]'resolves and installs (previously missing fastmcp entirely).FastMCP('probe', lifespan=fle_lifespan)constructs and_lifespanis wired.mcp = None.FactorioMCPStateat import time, which requires live Factorio containers — arguably its own issue. A fresh install additionally hits the a2a-sdk 1.x API break addressed by Fixes related to dependencies #372.🤖 Generated with Claude Code