langchain-ai/deepagents · error · MCPConfigError

str(exc)

Error message

str(exc)

What it means

MCPConfigError wrapping any OSError, JSONDecodeError, TypeError, or ValueError raised while discovering and loading MCP tools (env parsing, config file reading, JSON decoding). The original message is preserved verbatim via str(exc) and the cause is chained.

Source

Thrown at libs/talon/deepagents_talon/mcp.py:85

    Args:
        config: Talon runtime configuration.

    Returns:
        Loaded tools and status for each configured server.

    Raises:
        MCPConfigError: If a selected config source is malformed.
    """
    try:
        tools, manager, infos = await resolve_and_load_mcp_tools(
            explicit_config_path=_first_env_value(config.env),
            trust_project_mcp=None,
            project_context=_project_context(config),
        )
    except (OSError, json.JSONDecodeError, TypeError, ValueError) as exc:
        msg = str(exc)
        raise MCPConfigError(msg) from exc
    if manager is not None:
        logger.debug("Loaded MCP tools with a persistent session manager: %r", manager)
    return MCPTools(tools=tuple(tools), servers=tuple(infos))


def print_mcp_config_paths(config: TalonConfig) -> None:
    """Print Deep Agents Code MCP config discovery paths.

    Args:
        config: Talon runtime configuration.
    """
    project_context = _project_context(config)
    found = {str(path.resolve()) for path in discover_mcp_config_paths(config)}
    project_root = (
        project_context.project_root
        if project_context is not None and project_context.project_root is not None
        else (project_context.user_cwd if project_context is not None else Path.cwd())
    )

View on GitHub (pinned to a1af029e6e)

Solutions

  1. Read the chained 'Caused by' exception for the root cause and fix that underlying issue
  2. Validate the MCP config JSON parses (python -m json.tool <file>)
  3. Check the config path env vars point to an existing readable file
Defensive patterns

Strategy: try-catch

Validate before calling

cfg_path = os.environ.get("MCP_CONFIG_PATH")
if cfg_path and not Path(cfg_path).is_file():
    raise FileNotFoundError(cfg_path)
json.loads(Path(cfg_path).read_text())  # syntax check

Try / catch

try:
    mcp_tools = load_mcp_tools(config)
except MCPConfigError as exc:
    logger.error("MCP config failed to load: %s (cause: %r)", exc, exc.__cause__)
    mcp_tools = MCPTools(tools=(), servers=())

Prevention

When it happens

Trigger: Calling load_mcp_tools when the MCP config file is unreadable (OSError), contains invalid JSON (JSONDecodeError), or has a structurally wrong type/value (TypeError/ValueError) during discovery.

Common situations: Bad MCP_CONFIG path env var; malformed .mcp.json with a JSON typo; unexpected value types in config fields; permissions issues on the config file.

Related errors


AI-assisted analysis of langchain-ai/deepagents@a1af029e6e (2026-08-29). Data as JSON: /api/errors/4d036eea5d427d72. Report an issue: GitHub.