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.
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.