{"record":{"id":"be2c6bdc1d23adb9","repo":"langchain-ai/deepagents","slug":"prefix-name-must-be-a-dictionary-got-type-va","errorCode":null,"errorMessage":"{prefix}.{name} must be a dictionary, got {type(values).__name__}","messagePattern":"(.+?)\\.(.+?) must be a dictionary, got (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"libs/code/deepagents_code/mcp_config.py","lineNumber":173,"sourceCode":"            resolved[name] = _resolve_string(resolved[name], field=f\"{prefix}.{name}\")\n\n    if \"args\" in resolved:\n        args = resolved[\"args\"]\n        if not isinstance(args, list):\n            msg = f\"{prefix}.args must be a list, got {type(args).__name__}\"\n            raise TypeError(msg)\n        resolved[\"args\"] = [\n            _resolve_string(value, field=f\"{prefix}.args[{index}]\")\n            for index, value in enumerate(args)\n        ]\n\n    for name in (\"env\", \"headers\"):\n        if name not in resolved:\n            continue\n        values = resolved[name]\n        if not isinstance(values, dict):\n            msg = f\"{prefix}.{name} must be a dictionary, got {type(values).__name__}\"\n            raise TypeError(msg)\n        resolved[name] = _resolve_mapping_values(values, field=f\"{prefix}.{name}\")\n\n    return resolved\n","sourceCodeStart":155,"sourceCodeEnd":177,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/code/deepagents_code/mcp_config.py#L155-L177","documentation":"resolve_mcp_server_env validates the resolved `env` and `headers` fields of an MCP server config before resolving templated values. If either field resolves to anything other than a dictionary (e.g. a list, string, or null), this TypeError is thrown. The library enforces the MCP config schema: env/headers must be string-keyed mappings.","triggerScenarios":"Calling resolve_mcp_server_env (directly or via run_mcp_login_list, resolve_headers, login, or _preflight_and_connect) with an MCP server config where `env` or `headers` is a list, string, or other non-dict value after config resolution.","commonSituations":"A typo'd YAML/TOML config that defines `env` as a list of `KEY=VALUE` strings instead of a mapping; a project-level mcp.json with `headers: []`; merging configs that replace the dict with null; hand-editing config files with wrong indentation.","solutions":["Fix the server config so `env` and `headers` are mappings of string keys to string values (e.g. `env: {API_KEY: 'x'}` not `env: ['API_KEY=x']`).","Check for null: a key with no value (`headers:` with nothing after it) resolves to None; give it at least `{}`.","If configs are merged from multiple sources, verify the winning layer defines these fields as dictionaries.","Run `dcode mcp login list` / the test entrypoint to validate the config before reconnecting."],"exampleFix":"# before (config)\nenv:\n  - API_KEY=secret\n# after\nenv:\n  API_KEY: secret","handlingStrategy":"type-guard","validationCode":"for field in (\"env\", \"headers\"):\n    value = server_config.get(field, {})\n    if not isinstance(value, dict):\n        raise TypeError(f\"{server_name}.{field} must be a dictionary, got {type(value).__name__}\")","typeGuard":"def is_str_mapping(value: object) -> TypeGuard[dict[str, str]]:\n    return isinstance(value, dict) and all(isinstance(k, str) and isinstance(v, str) for k, v in value.items())","tryCatchPattern":"try:\n    env = resolve_mcp_server_env(server)\nexcept TypeError as exc:\n    print(f\"Bad MCP config for {server_name}: {exc}; fix env/headers to be mappings\")","preventionTips":["Define env/headers as key: value mappings, never lists of KEY=VALUE strings","Avoid bare keys with no value; use explicit empty mappings {}","Lint mcp config files (TOML/YAML) before committing"],"tags":["mcp","config","type-error","schema"],"backgroundTag":"config-schema-validation-failed","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}