Repository navigation
fix: explicit mcp --host/--port flags take precedence over .env - #46
Merged
OkiriGabriel merged 7 commits intoAug 17, 2026
Merged
OkiriGabriel merged 7 commits into
OkiriGabriel merged 7 commits into
Conversation
run_mcp set the FastMCP bind address with os.environ.setdefault, so a FASTMCP_HOST/FASTMCP_PORT value loaded from .env at import silently discarded explicitly passed --host/--port flags. An operator restricting the bind with --host 127.0.0.1 could stay listening on 0.0.0.0 with no warning. Precedence is now: explicit flag > environment (.env) > built-in default. The mcp CLI flags default to None so an explicit pass is detectable, and run_mcp assigns the env vars when a value is given, falling back to setdefault with the defaults 127.0.0.1/8090 only when it is not. Fixes open-devops-agent#40 Co-Authored-By: Kimi K3 <[email protected]>
Co-Authored-By: Kimi K3 <[email protected]>
Brings in upstream's .env.example entries for PAGERDUTY_URGENCY_*, fixing tests/test_env_example_coverage.py. Co-Authored-By: Kimi K3 <[email protected]>
Construct the real FastMCP server and capture self.settings.host/port via a monkeypatched FastMCP.run instead of stubbing create_mcp_server. Both tests fail pre-fix: FastMCP 1.x freezes settings at construction from explicit constructor params, so the env assignments in run_mcp never reach the settings and the server always binds 127.0.0.1:8000. Co-Authored-By: Kimi K3 <[email protected]>
FastMCP 1.x freezes settings at construction from explicit constructor params, so the FASTMCP_HOST/FASTMCP_PORT assignments in run_mcp happened too late to matter and the server always bound 127.0.0.1:8000. Resolve precedence before create_mcp_server — explicit args over FASTMCP_HOST/FASTMCP_PORT from the environment (e.g. loaded from .env) over application defaults 127.0.0.1/8090 — keeping the existing environment assignments, and pass the resolved host and integer port explicitly to FastMCP(..., host=..., port=...). Co-Authored-By: Kimi K3 <[email protected]>
stdio never binds TCP, so FASTMCP_PORT is irrelevant on that path; the current branch resolves int(FASTMCP_PORT) anyway and raises ValueError. Regression test fails until the stdio branch stops parsing the env. Co-Authored-By: Kimi K3 <[email protected]>
stdio does not bind TCP, so the bind address is irrelevant there; the branch now constructs the server with the explicit args or fixed defaults without reading, validating, or mutating FASTMCP_HOST/FASTMCP_PORT. FASTMCP_PORT=not-an-integer no longer raises before run(transport=stdio). HTTP (sse/streamable-http) resolution is unchanged. Co-Authored-By: Kimi K3 <[email protected]>
Collaborator
|
Reviewed — CI is green across all checks. Explicit mcp --host/--port taking precedence over .env is correct. Merging to |
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.
Summary
FASTMCP_HOST/FASTMCP_PORTin.envsilently overrode themcp --host/--portflags. Explicit flags now win; the env file supplies the value only when the flag is absent; built-in defaults remain the last resort.Related Issues and Pull Requests
Fixes #40
Changes
devops_agent/cli.py: themcpsubcommand's--host/--portargparse defaults changed toNone(mirroringserve), so an explicitly passed flag is detectable; help text notes the env fallbackdevops_mcp/server.py:run_mcp(host=None, port=None)assigns explicitly passed values andsetdefaults the rest, so the rule holds for direct callers too; stdio path untouchedTesting
Precedence proven end-to-end in all three directions with a real
.envand real argv (flag beats .env; .env beats default; default otherwise), adversarially re-run independently. Full suite: only the pre-existingtest_mcp.pypin failure (fixed upstream by #38 since). Known, documented non-blocking residual: an explicit value from one in-processrun_mcpcall persists for a second no-flag call in the same process — unreachable via the CLI (one blocking call per process); noted in the issue's thread for the embedding case.Footer
Generated by Kimi K3 (brief, implementation, review, verification)