{"record":{"id":"6e4bfdcea5450f49","repo":"langchain-ai/deepagents","slug":"serverselection-server-name-must-not-be-empty","errorCode":null,"errorMessage":"ServerSelection.server_name must not be empty","messagePattern":"ServerSelection\\.server_name must not be empty","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/code/deepagents_code/mcp_login_service.py","lineNumber":188,"sourceCode":"\n    server_name: str\n    \"\"\"Selected MCP server name (matches an `mcpServers` key).\"\"\"\n\n    server_config: McpServerSpec\n    \"\"\"Validated server config payload for `mcp_auth.login`.\"\"\"\n\n    search_label: str = \"\"\n    \"\"\"Where the config came from — used in not-found errors.\"\"\"\n\n    def __post_init__(self) -> None:\n        \"\"\"Enforce the non-empty `server_name` invariant.\n\n        Raises:\n            ValueError: If `server_name` is empty.\n        \"\"\"\n        if not self.server_name:\n            msg = \"ServerSelection.server_name must not be empty\"\n            raise ValueError(msg)\n\n\ndef resolve_mcp_config(\n    config_path: str | None,\n    *,\n    trust_project_mcp: bool | None = None,\n) -> ConfigResolution | ConfigResolutionError:\n    \"\"\"Resolve an MCP config dict for login without printing anything.\n\n    Args:\n        config_path: Explicit `--mcp-config` path, or `None` for auto-discovery.\n        trust_project_mcp: Whether project configs have whole-config trust for\n            the current session. Persisted approvals and denials still apply.\n\n    Returns:\n        A `ConfigResolution` on success, or a `ConfigResolutionError`\n            describing why no usable config could be assembled.\n    \"\"\"","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/code/deepagents_code/mcp_login_service.py#L170-L206","documentation":"ServerSelection's __post_init__ requires a non-empty server_name because every MCP login/selection operation needs to identify which named server to act on. An empty string name cannot match any configured server, so construction fails immediately with a ValueError.","triggerScenarios":"Constructing `ServerSelection(server_name=\"\", ...)` directly, or passing an empty server argument into `dcode mcp login` / resolve_mcp_config-driven flows that build a ServerSelection.","commonSituations":"Shell variables expanding to empty (`dcode mcp login \"$SERVER\"` with unset SERVER); scripts splitting CLI args incorrectly; UI code defaulting the name to empty string before user picks a server.","solutions":["Provide the server name explicitly, matching a name defined under `mcp.servers` in your config.","Guard the CLI/script input: fail early with a usage message if the argument is empty.","Run `dcode mcp login list` to see valid server names and pick one."],"exampleFix":"// before\nServerSelection(server_name=os.environ.get(\"MCP_SERVER\", \"\"), ...)\n// after\nname = os.environ.get(\"MCP_SERVER\")\nif not name:\n    raise SystemExit(\"usage: MCP_SERVER=<name> dcode mcp login\")\nServerSelection(server_name=name, ...)","handlingStrategy":"validation","validationCode":"server_name = (args.server or os.environ.get(\"MCP_SERVER\") or \"\").strip()\nif not server_name:\n    raise SystemExit(\"server name required: dcode mcp login <server>\")","typeGuard":"def non_empty_str(value: object) -> TypeGuard[str]:\n    return isinstance(value, str) and bool(value.strip())","tryCatchPattern":"try:\n    selection = ServerSelection(server_name=name)\nexcept ValueError as exc:\n    print(f\"invalid selection: {exc}\"); raise SystemExit(2)","preventionTips":["Quote shell variables and check they are set before invoking dcode","List valid names with `dcode mcp login list` first","Validate CLI args in wrapper scripts before calling the library"],"tags":["mcp","oauth","validation","value-error"],"backgroundTag":"required-argument-missing","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}