{"record":{"id":"6e4117bab7b60e00","repo":"langchain-ai/deepagents","slug":"mcp-token-file-path-has-unsupported-version-ty","errorCode":null,"errorMessage":"MCP token file {path} has unsupported version ({type(data.get('version')).__name__}; expected {_STORAGE_VERSION!r}). Delete it and run `/mcp login {self._server_name}` in the TUI (or `dcode mcp login {self._server_name}`).","messagePattern":"MCP token file (.+?) has unsupported version \\((.+?); expected (.+?)\\)\\. Delete it and run `/mcp login (.+?)` in the TUI \\(or `dcode mcp login (.+?)`\\)\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"libs/code/deepagents_code/mcp_auth.py","lineNumber":736,"sourceCode":"                f\"`dcode mcp login {self._server_name}`).\"\n            )\n            # Not `TypeError` (TRY004): this is a corrupt-file report, not a\n            # caller type error, and callers catch the same `RuntimeError` the\n            # other corruption modes raise. `TypeError` would escape them.\n            raise RuntimeError(msg)  # noqa: TRY004\n        if data.get(\"version\") != _STORAGE_VERSION:\n            # Render only the value's type, never the value itself: callers\n            # print this message verbatim (e.g. `mcp login` list on stderr),\n            # and the version field is attacker-controlled file content that\n            # could carry credential material planted by a malformed write.\n            msg = (\n                f\"MCP token file {path} has unsupported version \"\n                f\"({type(data.get('version')).__name__}; expected \"\n                f\"{_STORAGE_VERSION!r}). Delete it and run \"\n                f\"`/mcp login {self._server_name}` in the \"\n                f\"TUI (or `dcode mcp login {self._server_name}`).\"\n            )\n            raise RuntimeError(msg)\n        return data\n\n    def _write(self, data: dict) -> None:\n        path = self.path\n        path.parent.mkdir(parents=True, exist_ok=True)\n        if hasattr(os, \"chmod\"):\n            try:\n                path.parent.chmod(stat.S_IRWXU)\n            except OSError as exc:\n                # A failing chmod on the parent dir leaves the tokens\n                # directory at the default umask. Warn so operators on\n                # shared hosts notice.\n                logger.warning(\n                    \"Could not lock down MCP tokens dir %s (mode 0700): %s. \"\n                    \"Tokens may be readable by other local users.\",\n                    path.parent,\n                    exc,\n                )","sourceCodeStart":718,"sourceCodeEnd":754,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/code/deepagents_code/mcp_auth.py#L718-L754","documentation":"_read enforces a storage schema version (`version` must equal _STORAGE_VERSION). A token file written by a different version of the library (or with a missing/mistyped version field) is rejected as a RuntimeError, because migrating or interpreting unknown versions is unsafe. Only the value's type is shown to avoid leaking attacker-controlled file content into verbatim-printed messages.","triggerScenarios":"Reading tokens via any of the _read-backed accessors when the file's `version` key is absent, a non-string, or a string from an older/newer library release.","commonSituations":"Upgrading or downgrading deepagents-code across a token-storage format change, hand-editing the token file and dropping/changing the version field, or copying a token file from another tool with a different schema.","solutions":["Delete the token file at the reported path and run `/mcp login <server>` (or `dcode mcp login <server>`) to rewrite it in the current format.","Upgrade or downgrade deepagents-code to match the tool version that wrote the file.","Restore the correct `version` field only if you know the exact schema for the installed _STORAGE_VERSION."],"exampleFix":"// before\ndowngrade to deepagents-code 0.3.x -> token file version mismatch\n// after\npip install -U deepagents-code && rm ~/.local/share/deepagents-code/mcp-tokens/github.json && dcode mcp login github","handlingStrategy":"fallback","validationCode":"import json\nfrom pathlib import Path\np = Path(token_store_dir()) / f\"{server_name}.json\"\nif p.exists():\n    data = json.loads(p.read_text(encoding=\"utf-8\"))\n    if isinstance(data, dict) and data.get(\"version\") != \"1\":  # match _STORAGE_VERSION\n        p.unlink()  # stale schema: force fresh login","typeGuard":null,"tryCatchPattern":"try:\n    tokens = store.get_tokens_sync()\nexcept RuntimeError as e:\n    if \"unsupported version\" in str(e):\n        store.path.unlink(missing_ok=True)\n        reauthenticate(server_name)  # re-login rewrites file in current format\n    else:\n        raise","preventionTips":["After upgrading/downgrading deepagents-code, re-run `dcode mcp login` for each MCP server.","Keep all environments (dev, CI, server) on the same package version so token formats match.","Never copy token files between machines running different tool versions."],"tags":["mcp","versioning","schema-validation","migration"],"backgroundTag":"unsupported-schema-version","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}