{"record":{"id":"abab8153daf6f4c1","repo":"PrefectHQ/fastmcp","slug":"no-mcp-servers-defined-in-the-config-file-path","errorCode":null,"errorMessage":"No MCP servers defined in the config: {file_path}","messagePattern":"No MCP servers defined in the config: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"fastmcp_slim/fastmcp/mcp_config.py","lineNumber":358,"sourceCode":"\n    def to_dict(self) -> dict[str, Any]:\n        \"\"\"Convert MCPConfig to dictionary format, preserving all fields.\"\"\"\n        return self.model_dump(exclude_none=True)\n\n    def write_to_file(self, file_path: Path) -> None:\n        \"\"\"Write configuration to JSON file.\"\"\"\n        file_path.parent.mkdir(parents=True, exist_ok=True)\n        file_path.write_text(self.model_dump_json(indent=2), encoding=\"utf-8\")\n\n    @classmethod\n    def from_file(cls, file_path: Path) -> Self:\n        \"\"\"Load configuration from JSON file.\"\"\"\n        if file_path.exists() and (\n            content := file_path.read_text(encoding=\"utf-8\").strip()\n        ):\n            return cls.model_validate_json(content)\n\n        raise ValueError(f\"No MCP servers defined in the config: {file_path}\")\n\n\nclass CanonicalMCPConfig(MCPConfig):\n    \"\"\"Canonical MCP configuration format.\n\n    This defines the standard configuration format for Model Context Protocol servers.\n    The format is designed to be client-agnostic and extensible for future use cases.\n    \"\"\"\n\n    mcpServers: dict[str, CanonicalMCPServerTypes] = Field(default_factory=dict)\n\n    @override\n    def add_server(self, name: str, server: CanonicalMCPServerTypes) -> None:\n        \"\"\"Add or update a server in the configuration.\"\"\"\n        self.mcpServers[name] = server\n\n\ndef update_config_file(","sourceCodeStart":340,"sourceCodeEnd":376,"githubUrl":"https://github.com/PrefectHQ/fastmcp/blob/1f021142978e0861cd910c8df4e8074bc7cf3978/fastmcp_slim/fastmcp/mcp_config.py#L340-L376","documentation":"MCPConfig.from_file loads a JSON config file and validates it; if the file is missing, empty, or contains only whitespace, it raises ValueError('No MCP servers defined in the config: <path>'). It treats a non-existent or blank file as an invalid config rather than silently returning an empty model.","triggerScenarios":"from_file(path) where path does not exist, or the file exists but read_text().strip() is empty (0-byte file or whitespace only). Also reached via update_config_file flows.","commonSituations":"Pointing at a .mcp.json path that was never created; a failed write left an empty file; wrong working directory so the relative path resolves to a nonexistent file.","solutions":["Check the file exists at the given path (os.path.exists) and fix the path","Populate the JSON with an mcpServers object, e.g. {\"mcpServers\": {\"myserver\": {...}}}","If the file should be created on demand, create and write valid JSON before calling from_file"],"exampleFix":"// before\nconfig = MCPConfig.from_file(Path(\"~/.mcp.json\"))\n// after\npath = Path(\"~/.mcp.json\").expanduser()\nassert path.exists(), f\"missing config: {path}\"\nconfig = MCPConfig.from_file(path)","handlingStrategy":"validation","validationCode":"from pathlib import Path\nimport json\ndef config_file_ready(p: Path) -> bool:\n    if not p.exists():\n        return False\n    text = p.read_text(encoding=\"utf-8\").strip()\n    if not text:\n        return False\n    return bool(json.loads(text).get(\"mcpServers\"))","typeGuard":null,"tryCatchPattern":"try:\n    cfg = MCPConfig.from_file(path)\nexcept ValueError as e:\n    print(f\"bad or empty config: {e}\"); sys.exit(1)","preventionTips":["Verify the config path exists and is non-empty before loading","Use absolute paths (Path.expanduser()/resolve())","Never leave zero-byte config files behind on failed writes"],"tags":["config","file-io","validation","mcp"],"backgroundTag":"empty-config-file","analyzedSha":"1f021142978e0861cd910c8df4e8074bc7cf3978","analyzedAt":"2026-08-29T14:31:16.082Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}