langchain-ai/deepagents · error · TypeError
Server '{server_name}' '{field_name}' must be a list of stri
Error message
Server '{server_name}' '{field_name}' must be a list of strings What it means
When a server config defines `allowedTools` or `disabledTools`, the value must be a list containing only strings. `_validate_tool_filter_fields` raises this TypeError when the field is a non-list (e.g. a string or dict) or when any element is not a string. It's a config schema check that runs before any MCP server is contacted.
Source
Thrown at libs/code/deepagents_code/mcp_tools.py:1000
has_disabled = "disabledTools" in server_config
if has_allowed and has_disabled:
error_msg = (
f"Server '{server_name}' cannot set both 'allowedTools' and"
" 'disabledTools' — pick one."
)
raise ValueError(error_msg)
for field_name in ("allowedTools", "disabledTools"):
if field_name not in server_config:
continue
value = server_config[field_name]
if not isinstance(value, list) or not all(
isinstance(item, str) for item in value
):
error_msg = (
f"Server '{server_name}' '{field_name}' must be a list of strings"
)
raise TypeError(error_msg)
if not value:
error_msg = (
f"Server '{server_name}' '{field_name}' must be non-empty;"
" omit the field to disable filtering."
)
raise ValueError(error_msg)
def _looks_like_comment(doc: str, lineno: int) -> bool:
"""Return `True` if the offending line *begins* with `//` or `/*`.
Only the failing line is checked, and only its leading characters (after
stripping indentation). A `url` value such as `"url": "https://..."`
begins with a quote, not `//`, so a URL scheme inside a quoted string
never triggers a false comment hint.
Args:
doc: Full source text that failed to parse.View on GitHub (pinned to a1af029e6e)
Solutions
- Wrap the value in a JSON array of strings: "allowedTools": ["read_file"].
- Remove or stringify non-string elements (numbers, booleans, null) from the list.
- If the field is not needed, delete the key entirely rather than passing an empty or malformed value.
Example fix
// before
{"mcpServers": {"fs": {"command": "mcp-server-fs", "allowedTools": "read_file"}}}
// after
{"mcpServers": {"fs": {"command": "mcp-server-fs", "allowedTools": ["read_file"]}}} Defensive patterns
Strategy: validation
Validate before calling
def check_filter_value(server, field):
value = server.get(field)
if value is not None and not (isinstance(value, list) and all(isinstance(i, str) for i in value)):
raise TypeError(f"{field} must be a list of strings") Type guard
def is_str_list(value: object) -> bool:
return isinstance(value, list) and all(isinstance(i, str) for i in value) Try / catch
try:
load_mcp_config(path)
except TypeError as e:
if "must be a list of strings" in str(e):
repair_filter_field(path, server_name=e, field=...)
else:
raise Prevention
- Always write tool filters as JSON arrays of quoted strings, even for a single tool.
- Generate configs with typed builders instead of hand-editing JSON.
- Keep tool-name lists next to the tool definitions to avoid copy drift.
When it happens
Trigger: Server config with a non-list value like "allowedTools": "read_file" (string instead of list), or a list with non-string entries like "disabledTools": ["write_file", 42] or ["tool", null].
Common situations: Hand-edited JSON where quotes around a single tool name were dropped; YAML-derived configs where a single-item list becomes a scalar; programmatic config generation that inserts tool IDs as integers; copying an object of tool->settings instead of an array of names.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- 'mcpServers' field must be a dictionary
- Invalid MCP config at {mcp_config_path}: {exc}
- {prefix}.{name} must be a dictionary, got {type(values).__na
- Server '{server_name}' cannot set both 'allowedTools' and 'd
- Server '{server_name}' '{field_name}' must be non-empty; omi
AI-assisted analysis of langchain-ai/deepagents@a1af029e6e (2026-08-29).
Data as JSON: /api/errors/b8845e8705af79cd.
Report an issue: GitHub.