{"record":{"id":"7a14455d61b91785","repo":"langchain-ai/deepagents","slug":"mcpserverinfo-self-name-r-status-ok-cannot-ca","errorCode":null,"errorMessage":"MCPServerInfo {self.name!r}: status='ok' cannot carry an error (got {self.error!r})","messagePattern":"MCPServerInfo (.+?): status='ok' cannot carry an error \\(got (.+?)\\)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/code/deepagents_code/mcp_tools.py","lineNumber":178,"sourceCode":"    already covered by `needs_attention()`.\n    \"\"\"\n\n    def __post_init__(self) -> None:\n        \"\"\"Enforce the status/error/tools consistency invariant.\n\n        Raises:\n            ValueError: If any of: `status='ok'` with a non-`None` error;\n                non-`ok` status without an error message; non-`ok` status\n                carrying tools; or `pending_reconnect` set without\n                `status='disabled'`.\n        \"\"\"\n        if self.status == \"ok\":\n            if self.error is not None:\n                msg = (\n                    f\"MCPServerInfo {self.name!r}: status='ok' cannot carry \"\n                    f\"an error (got {self.error!r})\"\n                )\n                raise ValueError(msg)\n        else:\n            if self.error is None:\n                msg = (\n                    f\"MCPServerInfo {self.name!r}: status={self.status!r} \"\n                    \"requires an error message\"\n                )\n                raise ValueError(msg)\n            if self.tools:\n                msg = (\n                    f\"MCPServerInfo {self.name!r}: status={self.status!r} \"\n                    \"cannot carry tools\"\n                )\n                raise ValueError(msg)\n        if self.pending_reconnect and self.status != \"disabled\":\n            msg = (\n                f\"MCPServerInfo {self.name!r}: pending_reconnect requires \"\n                f\"status='disabled' (got {self.status!r})\"\n            )","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/code/deepagents_code/mcp_tools.py#L160-L196","documentation":"MCPServerInfo's __post_init__ enforces a consistent status/error pairing: a server reporting status='ok' succeeded and must not also carry an error message. Constructing an MCPServerInfo with status='ok' and a non-None error fails this invariant with a ValueError.","triggerScenarios":"Programmatically constructing `MCPServerInfo(name=..., status='ok', error=<message>)` in code that aggregates MCP server health (e.g. custom tooling or tests around mcp_tools listing).","commonSituations":"Adapters wrapping third-party results that set both a success status and a residual error string; refactors that populate error unconditionally; test fixtures copying fields from a failed server info and only changing status.","solutions":["Set error=None when status is 'ok'; keep the message only for failure statuses.","If you want to surface a non-fatal warning, encode it in a dedicated field or in tools metadata, not in `error`.","Fix fixture/adapter code that copies `error` across status transitions."],"exampleFix":"// before\nMCPServerInfo(name=\"github\", status=\"ok\", error=\"timeout earlier\")\n// after\nMCPServerInfo(name=\"github\", status=\"ok\", error=None)","handlingStrategy":"type-guard","validationCode":"def make_server_info(name: str, status: str, error: str | None = None, tools: list | None = None) -> MCPServerInfo:\n    if status == \"ok\" and error is not None:\n        raise ValueError(\"status='ok' cannot carry an error\")\n    return MCPServerInfo(name=name, status=status, error=error, tools=tools or [])","typeGuard":"def is_consistent(info: MCPServerInfo) -> bool:\n    return (info.error is None) if info.status == \"ok\" else (info.error is not None)","tryCatchPattern":"try:\n    info = MCPServerInfo(name=name, status=\"ok\", error=err)\nexcept ValueError as exc:\n    print(f\"dropping inconsistent server info: {exc}\")\n    info = MCPServerInfo(name=name, status=\"ok\", error=None)","preventionTips":["Set error=None on success paths — don't carry stale errors across retries","Build MCPServerInfo through one helper/factory, not ad hoc literals","When reusing a failed info as a template, explicitly clear error/tools"],"tags":["mcp","invariant","value-error","dataclass"],"backgroundTag":"invariant-violation","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}