Skip to content

fix(mcp): make keyring a true optional dependency in _resolve_keyring_refs#1028

Open
kovtcharov wants to merge 1 commit intomainfrom
kalin/fix-keyring-optional-import
Open

fix(mcp): make keyring a true optional dependency in _resolve_keyring_refs#1028
kovtcharov wants to merge 1 commit intomainfrom
kalin/fix-keyring-optional-import

Conversation

@kovtcharov
Copy link
Copy Markdown
Collaborator

Why this matters

Before: `tests/unit/mcp/client/test_mcp_client.py::test_from_config_accepts_env` fails at import on any dev environment without the optional `keyring` package, even though that test only passes plain string env vars and never exercises the `$keyring` path. The unconditional `import keyring` at the top of `_resolve_keyring_refs` made keyring a hard dependency in practice for every config-driven MCP server load.

After: imports for `keyring`, `ConnectorsError`, and `SERVICE_NAME` are deferred to the branch that actually needs them. Plain-env callers stay zero-dep on keyring; the security invariants and error handling for real `$keyring` references are unchanged.

Caught while reviewing #1026 — pre-existing issue, not introduced by that PR.

Test plan

  • `pytest tests/unit/mcp/client/ -v` — 25/25 pass (previously 24 pass + 1 fail)
  • `python util/lint.py --black --isort` — clean

_resolve_keyring_refs imported keyring (an optional dependency) at the
top of the function regardless of whether the env actually contained
any $keyring references. On dev environments without keyring installed
this caused tests/unit/mcp/client/test_mcp_client.py::TestMCPClient::
test_from_config_accepts_env to fail at collection with
ModuleNotFoundError, even though the test only passes plain string
env vars and never triggers the keyring path.

Move the keyring + connectors imports inside the loop branch that
actually needs them, so plain-env callers stay zero-dep on keyring
while $keyring callers get the same behaviour as before.
@github-actions github-actions Bot added the mcp MCP integration changes label May 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mcp MCP integration changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant