UI-agnostic helpers for resolving an MCP login target.
The MCP login flow historically inlined config discovery, trust gating,
shape validation, and print()-based error reporting. The TUI cannot
consume those print statements, so this module extracts the same logic
into pure functions that return structured results (ConfigResolution,
ServerSelection) plus a typed ConfigResolutionError. Callers decide
how to render those results.
No print() calls live in this module. No imports happen at module
top level beyond dataclasses/typing/pathlib so the CLI fast path
stays cheap; the actual config loaders are imported inside the
functions that need them.
Resolve an MCP config dict for login without printing anything.
Pull server out of a resolved config and validate its shape.
Build the CLI-style hint for an unreadable user trust policy.
Surfaced by dcode mcp login so a config.toml read failure is never
swallowed just because a user-level config or an env-enabled server still
loaded — and so the reason is not misattributed to an "untrusted project"
when the real fix is repairing config.toml.
Build the CLI-style hint string for skipped project server entries.
Build the CLI-style hint for servers dropped by the legacy-key removal.
Mirrors the resolve_and_load_mcp_tools migration message so
non-interactive dcode mcp login explains why a previously allowlisted
server stopped loading instead of leaving it to vanish silently.
Build the CLI-style hint for the renamed, now-ignored env var.
Mirrors format_legacy_ignored_notice for the env surface so a user who
still exports DEEPAGENTS_CODE_ENABLED_PROJECT_MCP_SERVERS learns it was
renamed instead of its servers silently ceasing to pre-approve.
Build the CLI-style hint for dropped malformed saved approvals.
Mirrors format_legacy_ignored_notice so non-interactive dcode mcp login
explains why a previously-approved server stopped loading (a corrupt saved
approval) instead of leaving it to vanish silently.
Build the CLI-style hint for discovered configs that failed to load.
Surfaced by dcode mcp login on a partially successful resolution so a
broken .mcp.json is reported instead of silently dropped while another
config still loads — matching the runtime loader
(resolve_and_load_mcp_tools), which emits the same failures as error rows.
Parsed MCP server config entry.
All keys are optional at the type level because mcpServers entries
are validated shape-first by _validate_server_config rather than by
the type system. This TypedDict documents the accepted shape for
readers and static checkers — validate the fields at use sites before
relying on them.
Discriminator for ConfigResolutionError reasons.
Only NO_CONFIG_FOUND maps to exit code 2 in run_mcp_login; all
other kinds map to exit code 1. The TUI surface translates them into
in-app status messages.
Structured error returned when a login target cannot be resolved.
Successful resolution of a merged MCP config for login.
Resolved server config plus enough context for error messages.