{"record":{"id":"2c7a266ea9164067","repo":"langchain-ai/deepagents","slug":"field-must-be-a-string-got-type-value-name","errorCode":null,"errorMessage":"{field} must be a string, got {type(value).__name__}","messagePattern":"(.+?) must be a string, got (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"libs/code/deepagents_code/mcp_config.py","lineNumber":103,"sourceCode":"    return _ENV_REF_RE.sub(replace, value)\n\n\ndef _resolve_string(value: object, *, field: str) -> str:\n    \"\"\"Validate and interpolate one string field.\n\n    Args:\n        value: Raw field value.\n        field: Fully qualified field path for error messages.\n\n    Returns:\n        The validated and interpolated string.\n\n    Raises:\n        TypeError: If the field value is not a string.\n    \"\"\"\n    if not isinstance(value, str):\n        msg = f\"{field} must be a string, got {type(value).__name__}\"\n        raise TypeError(msg)\n    return _interpolate_env(value, field=field)\n\n\ndef _resolve_mapping_values(\n    values: Mapping[str, object],\n    *,\n    field: str,\n) -> dict[str, str]:\n    \"\"\"Validate and interpolate string values in a mapping field.\n\n    Args:\n        values: Raw mapping values.\n        field: Fully qualified field path for error messages.\n\n    Returns:\n        A new mapping with validated and interpolated values.\n    \"\"\"\n    return {","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/code/deepagents_code/mcp_config.py#L85-L121","documentation":"`_resolve_string` validates that a supported MCP config field (`command`, `url`, an `args` element, or an `env`/`headers` value) is a string before interpolating env references. A non-string value raises `TypeError` naming the fully qualified field path and the actual type.","triggerScenarios":"Calling `resolve_mcp_server_env(server_name, server_config)` where a supported field holds a non-string: e.g. `url: 123`, an `args` element that is a number/bool/dict, or an `env` value that is `true`/`null`.","commonSituations":"JSON/YAML configs where numbers or booleans are unquoted (`port: 8080`, `verbose: true`); programmatic config construction passing ints or `None`; schema drift after the server entry was edited by hand or generated by a tool.","solutions":["Quote the field value as a string in the config (`port: \"8080\"`).","Fix the code path building the config to stringify values (`str(value)`).","Check the field named in the message — it identifies the exact path, e.g. `mcpServers.myserver.args[2]`."],"exampleFix":"// before\n{\"env\": {\"PORT\": 8080}}\n// after\n{\"env\": {\"PORT\": \"8080\"}}","handlingStrategy":"type-guard","validationCode":"SUPPORTED_FIELDS = (\"command\", \"url\")\ndef check_string_fields(cfg: dict) -> list[str]:\n    errs = []\n    for f in SUPPORTED_FIELDS:\n        if f in cfg and not isinstance(cfg[f], str):\n            errs.append(f\"{f} must be a string, got {type(cfg[f]).__name__}\")\n    for f in (\"env\", \"headers\"):\n        for k, v in cfg.get(f, {}).items():\n            if not isinstance(v, str):\n                errs.append(f\"{f}.{k} must be a string, got {type(v).__name__}\")\n    return errs","typeGuard":"def is_str_field(v: object) -> TypeGuard[str]:\n    return isinstance(v, str)","tryCatchPattern":"try:\n    resolved = resolve_mcp_server_env(server_name, server_config)\nexcept TypeError as exc:\n    raise SystemExit(f\"Config type error: {exc} — quote the field as a string\") from exc","preventionTips":["Quote all values in mcpServers entries in JSON/YAML so numbers and booleans stay strings","Never pass None/int/bool into programmatically built configs; coerce with str() first","Read the field path in the error message — it pinpoints the exact offending key"],"tags":["mcp","type-error","config-validation"],"backgroundTag":"schema-validation-failed","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}