FoundationAgents/OpenManus · error · ValueError

Failed to load MCP server config: {e}

Error message

Failed to load MCP server config: {e}

What it means

Raised by the MCP server config loader in config.py when parsing mcp_servers.json fails for any reason — the outer `except Exception` wraps JSON syntax errors, missing required keys, wrong types, and file read failures into one ValueError with the original exception interpolated. The underlying cause is always in the `{e}` part of the message.

Source

Thrown at app/config.py:171

        try:
            config_file = config_path if config_path.exists() else None
            if not config_file:
                return {}

            with config_file.open() as f:
                data = json.load(f)
                servers = {}

                for server_id, server_config in data.get("mcpServers", {}).items():
                    servers[server_id] = MCPServerConfig(
                        type=server_config["type"],
                        url=server_config.get("url"),
                        command=server_config.get("command"),
                        args=server_config.get("args", []),
                    )
                return servers
        except Exception as e:
            raise ValueError(f"Failed to load MCP server config: {e}")


class AppConfig(BaseModel):
    llm: Dict[str, LLMSettings]
    sandbox: Optional[SandboxSettings] = Field(
        None, description="Sandbox configuration"
    )
    browser_config: Optional[BrowserSettings] = Field(
        None, description="Browser configuration"
    )
    search_config: Optional[SearchSettings] = Field(
        None, description="Search configuration"
    )
    mcp_config: Optional[MCPSettings] = Field(None, description="MCP configuration")
    run_flow_config: Optional[RunflowSettings] = Field(
        None, description="Run flow configuration"
    )
    daytona_config: Optional[DaytonaSettings] = Field(

View on GitHub (pinned to 52a13f2a57)

Solutions

  1. Read the {e} suffix to identify the root cause: JSONDecodeError means syntax, KeyError 'type' means a missing field
  2. Validate the file with a JSON linter (python -m json.tool mcp_servers.json) and fix syntax
  3. Ensure every mcpServers entry has "type" ("sse" or "stdio") plus the matching fields: url for sse, command for stdio

Example fix

// before (mcp_servers.json)
{ "mcpServers": { "fs": { "command": "npx" } } }  // KeyError: 'type'

// after
{ "mcpServers": { "fs": { "type": "stdio", "command": "npx", "args": ["-y", "@modelcontextprotocol/server-filesystem"] } } }
Defensive patterns

Strategy: try-catch

Validate before calling

import json

def validate_mcp_config(path: str) -> dict:
    with open(path) as f:
        data = json.load(f)  # raises JSONDecodeError early
    for sid, sc in data.get("mcpServers", {}).items():
        assert sc.get("type") in ("sse", "stdio"), f"{sid}: bad type"
        if sc["type"] == "sse":
            assert sc.get("url"), f"{sid}: url required"
        else:
            assert sc.get("command"), f"{sid}: command required"
    return data

Try / catch

try:
    servers = load_mcp_servers()
except ValueError as e:
    # the original cause is embedded after the colon
    logger.error("MCP config invalid: %s", e)
    raise SystemExit(1) from e

Prevention

When it happens

Trigger: Loading mcp_servers.json with invalid JSON (trailing comma, comments), a server entry missing the required "type" key (server_config["type"] raises KeyError), or non-dict values under mcpServers. File permission errors also surface here.

Common situations: Hand-editing mcp_servers.json and leaving a trailing comma; entry with url/command/args but no "type" field; comments in JSON; running with read permissions missing on the config file.

Related errors


AI-assisted analysis of FoundationAgents/OpenManus@52a13f2a57 (2026-08-15). Data as JSON: /api/errors/c9b05a79cc3a1df5. Report an issue: GitHub.