{"record":{"id":"3ce0cefbdd12a10d","repo":"Panniantong/Agent-Reach","slug":"mcporter-imports","errorCode":null,"errorMessage":"mcporter imports 必须是字符串列表","messagePattern":"mcporter imports 必须是字符串列表","errorType":"exception","errorClass":"McporterConfigError","httpStatus":null,"severity":"error","filePath":"agent_reach/channels/mcporter.py","lineNumber":73,"sourceCode":"        if not isinstance(servers, dict):\n            raise McporterConfigError(\"mcporter 配置缺少 mcpServers 对象\")\n\n        for name, definition in servers.items():\n            if not isinstance(name, str) or not name.strip():\n                raise McporterConfigError(\"mcporter 配置包含无效的 server name\")\n            if not isinstance(definition, dict):\n                raise McporterConfigError(\"mcporter server 定义必须是对象\")\n            names.add(name.casefold())\n\n        imports = payload.get(\"imports\", _MISSING)\n        if imports is _MISSING:\n            # mcporter defaults to importing supported editor configs when the\n            # key is omitted. Doctor intentionally does not open those files.\n            imports_unchecked = True\n        elif not isinstance(imports, list) or not all(\n            isinstance(item, str) for item in imports\n        ):\n            raise McporterConfigError(\"mcporter imports 必须是字符串列表\")\n        elif imports:\n            imports_unchecked = True\n        sources.append(source)\n\n    return McporterConfigInspection(\n        frozenset(names),\n        \"+\".join(sources),\n        imports_unchecked=imports_unchecked,\n    )\n\n\ndef _select_config_layers(\n    root_dir: str | Path | None,\n) -> list[tuple[Path, str]]:\n    root = Path(os.path.abspath(os.fspath(root_dir or Path.cwd())))\n    explicit = os.environ.get(\"MCPORTER_CONFIG\", \"\").strip()\n    if explicit:\n        expanded = Path(os.path.expanduser(explicit))","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/Panniantong/Agent-Reach/blob/93ae1d18c37b707dec053c7c4f9d91cd8ef8943d/agent_reach/channels/mcporter.py#L55-L91","documentation":"Raised when a config layer's 'imports' key exists but is not a list of strings. Doctor treats imports as an honesty flag: when imports are present (or omitted, since mcporter then auto-imports editor configs), it marks the inspection imports_unchecked because imported files may add servers it did not open. Malformed imports abort instead of producing a misleading result.","triggerScenarios":"Any selected layer has '\"imports\": \"../shared.json\"' (string), '\"imports\": {\"a\": 1}' (object), or a list containing non-strings like '\"imports\": [1]'. Note: 'imports': [] (empty list) is accepted and NOT flagged unchecked.","commonSituations":"Confusion with YAML anchors or glob strings written as a single string; older/newer mcporter schema drift where imports was an object map; hand-merging several config files.","solutions":["Write imports as an array of path strings: '\"imports\": [\"../shared/mcp.json\"]'","Remove the imports key if you do not import anything (but know the doctor will then flag imports_unchecked due to mcporter's auto-import default)","Check every layer — user config and project .mcporter/mcporter.json both"],"exampleFix":"// before\n { \"mcpServers\": {}, \"imports\": \"./extra.json\" }\n// after\n { \"mcpServers\": {}, \"imports\": [\"./extra.json\"] }","handlingStrategy":"validation","validationCode":"import json\n\ndef imports_ok(path) -> bool:\n    try:\n        payload = json.load(open(path, encoding=\"utf-8\"))\n    except Exception:\n        return False\n    if \"imports\" not in payload:\n        return True\n    imports = payload[\"imports\"]\n    return isinstance(imports, list) and all(isinstance(i, str) for i in imports)","typeGuard":"def valid_imports(payload: dict) -> bool:\n    imports = payload.get(\"imports\")\n    return imports is None or (isinstance(imports, list) and all(isinstance(x, str) for x in imports))","tryCatchPattern":"except McporterConfigError as exc:\n    if \"imports\" in str(exc):\n        show_fix(\"change imports to an array of path strings\")","preventionTips":["imports is an array of string paths, never a bare string or object","An empty array is valid and silences the unchecked-imports caveat deliberately only when you truly import nothing","Keep layer schemas in sync when merging configs"],"tags":["mcporter","mcp","json","config"],"backgroundTag":null,"analyzedSha":"93ae1d18c37b707dec053c7c4f9d91cd8ef8943d","analyzedAt":"2026-08-14T22:54:06.735Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}