Skip to content

Universal SEO skill for Claude Code. 26 sub-skills + 19 sub-agents covering technical SEO, E-E-A-T, schema, GEO/AEO, agent readiness (Lighthouse Agentic Browsing, WebMCP, llms.txt), backlinks, local SEO, e-commerce, international SEO, Google APIs, and PDF/Excel reporting. 9 optional extensions for live SEO data.

fix(extensions): write ~/.claude.json atomically with a larger JSON depth

Agrici Daniel27a7cc627a3a
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c816c57..6bd2d3f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -31,6 +31,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
sequence under PowerShell Core (`pwsh`); a parallel job now runs the same
steps under Windows PowerShell 5.1 (`shell: powershell`), which is what
actually caught #207.
+- The dataforseo, firecrawl, ahrefs, and banana extension installers wrote
+ their MCP server block to `~/.claude/settings.json`, a key Claude Code does
+ not read from that file, so the server never loaded and reinstalling could
+ not fix it. They now write `~/.claude.json` (the file `claude mcp add`
+ writes) across install/uninstall scripts, banana's Python helpers, and the
+ setup docs. `bing-webmaster`, `profound`, and `seranking` were left alone:
+ they write the `env` key, which settings.json does support (#204).
+- `extensions/firecrawl/install.ps1` and `extensions/banana/scripts/
+ setup_mcp.py` now write `~/.claude.json` atomically (temp file in the same
+ directory, then `Move-Item -Force` / `os.replace`), and the PowerShell
+ serialisation depth is raised from 10 to 100 so an existing `~/.claude.json`
+ with deeply nested config round-trips intact instead of being flattened.
## [2.2.6] - 2026-09-10
diff --git a/extensions/banana/scripts/setup_mcp.py b/extensions/banana/scripts/setup_mcp.py
index 07b54bb..e421c33 100755
--- a/extensions/banana/scripts/setup_mcp.py
+++ b/extensions/banana/scripts/setup_mcp.py
@@ -16,6 +16,7 @@ Usage:
import json
import os
import sys
+import tempfile
from pathlib import Path
SETTINGS_PATH = Path.home() / ".claude.json"
@@ -32,10 +33,28 @@ def load_settings() -> dict:
def save_settings(settings: dict) -> None:
- """Save Claude Code ~/.claude.json."""
+ """Save Claude Code ~/.claude.json atomically.
+
+ ~/.claude.json is shared with Claude Code itself and other installers, so
+ a write is staged to a temp file in the same directory and swapped into
+ place with ``os.replace`` (atomic on POSIX and Windows). This avoids a
+ reader ever observing a truncated or partially written file, and avoids
+ corrupting the file if this process is interrupted mid-write.
+ """
SETTINGS_PATH.parent.mkdir(parents=True, exist_ok=True)
- with open(SETTINGS_PATH, "w") as f:
- json.dump(settings, f, indent=2)
+ fd, tmp_path = tempfile.mkstemp(
+ prefix=".claude.json.", suffix=".tmp", dir=str(SETTINGS_PATH.parent)
+ )
+ try:
+ with os.fdopen(fd, "w") as f:
+ json.dump(settings, f, indent=2)
+ os.replace(tmp_path, SETTINGS_PATH)
+ except BaseException:
+ try:
+ os.unlink(tmp_path)
+ except OSError:
+ pass
+ raise
print(f"Settings saved to {SETTINGS_PATH}")
diff --git a/extensions/firecrawl/install.ps1 b/extensions/firecrawl/install.ps1
index 6a443e7..39c1939 100644
--- a/extensions/firecrawl/install.ps1
+++ b/extensions/firecrawl/install.ps1
@@ -76,7 +76,14 @@ $settingsContent.mcpServers | Add-Member -NotePropertyName 'firecrawl-mcp' -Note
args = @('-y', '[email protected]')
env = @{ FIRECRAWL_API_KEY = $apiKeyPlain }
} -Force
-$settingsContent | ConvertTo-Json -Depth 10 | Set-Content $McpConfigFile -Encoding UTF8
+# Write atomically: stage to a temp file in the same directory, then swap
+# it into place, so a crash mid-write never leaves ~/.claude.json truncated
+# or half-written (it is shared with Claude Code and other installers).
+# -Depth 100 (not the ConvertTo-Json default of 2, or the previous 10) so an
+# existing ~/.claude.json with deeply nested config round-trips intact.
+$TempConfigFile = Join-Path (Split-Path -Parent $McpConfigFile) ".claude.json.$([guid]::NewGuid().ToString('N')).tmp"
+$settingsContent | ConvertTo-Json -Depth 100 | Set-Content $TempConfigFile -Encoding UTF8
+Move-Item -Path $TempConfigFile -Destination $McpConfigFile -Force
# Restrict the credential-bearing settings file to the current user only.
try {
icacls $McpConfigFile /inheritance:r /grant:r "${env:USERNAME}:F" | Out-Null
diff --git a/tests/test_banana_setup_mcp_atomic_write.py b/tests/test_banana_setup_mcp_atomic_write.py
new file mode 100644
index 0000000..d6ff453
--- /dev/null
+++ b/tests/test_banana_setup_mcp_atomic_write.py
@@ -0,0 +1,92 @@
+"""Regression tests for setup_mcp.py's atomic ~/.claude.json write.
+
+~/.claude.json is shared with Claude Code and other extension installers, so
+save_settings() must never leave it truncated or half-written. It stages the
+write to a temp file in the same directory and swaps it into place with
+os.replace.
+"""
+
+from __future__ import annotations
+
+import importlib.util
+import json
+from pathlib import Path
+
+import pytest
+
+REPO_ROOT = Path(__file__).resolve().parents[1]
+
+
+def _load_module(monkeypatch, home: Path):
+ """Import setup_mcp.py fresh with HOME pointed at an isolated directory.
+
+ SETTINGS_PATH is computed at module-exec time from Path.home(), so HOME
+ must be patched before exec_module runs.
+ """
+ monkeypatch.setenv("HOME", str(home))
+ spec = importlib.util.spec_from_file_location(
+ "banana_setup_mcp", REPO_ROOT / "extensions/banana/scripts/setup_mcp.py"
+ )
+ assert spec and spec.loader
+ module = importlib.util.module_from_spec(spec)
+ spec.loader.exec_module(module)
+ return module
+
+
+def test_setup_mcp_writes_config_with_no_leftover_temp_file(tmp_path, monkeypatch):
+ module = _load_module(monkeypatch, tmp_path)
+
+ module.setup_mcp("dummy-api-key")
+
+ settings_path = tmp_path / ".claude.json"
+ assert settings_path.exists()
+ data = json.loads(settings_path.read_text())
+ assert data["mcpServers"]["nanobanana-mcp"]["env"]["GOOGLE_AI_API_KEY"] == "dummy-api-key"
+ assert list(tmp_path.glob(".claude.json.*.tmp")) == []
+
+
+def test_save_settings_preserves_unrelated_keys_on_existing_file(tmp_path, monkeypatch):
+ (tmp_path / ".claude.json").write_text(
+ json.dumps({"unrelated": "keep-me", "mcpServers": {"other-mcp": {"command": "x"}}})
+ )
+ module = _load_module(monkeypatch, tmp_path)
+
+ module.setup_mcp("dummy-api-key")
+
+ data = json.loads((tmp_path / ".claude.json").read_text())
+ assert data["unrelated"] == "keep-me"
+ assert "other-mcp" in data["mcpServers"]
+ assert "nanobanana-mcp" in data["mcpServers"]
+
+
+def test_save_settings_stages_temp_file_in_same_directory(tmp_path, monkeypatch):
+ module = _load_module(monkeypatch, tmp_path)
+ tmp_dirs_seen = []
+ real_mkstemp = module.tempfile.mkstemp
+
+ def spy_mkstemp(*args, **kwargs):
+ fd, path = real_mkstemp(*args, **kwargs)
+ tmp_dirs_seen.append(Path(path).parent)
+ return fd, path
+
+ monkeypatch.setattr(module.tempfile, "mkstemp", spy_mkstemp)
+
+ module.save_settings({"mcpServers": {}})
+
+ assert tmp_dirs_seen == [tmp_path]
+ assert (tmp_path / ".claude.json").exists()
+
+
+def test_save_settings_cleans_up_temp_file_and_leaves_original_on_failure(tmp_path, monkeypatch):
+ original = {"mcpServers": {}, "keep": "value"}
+ (tmp_path / ".claude.json").write_text(json.dumps(original))
+ module = _load_module(monkeypatch, tmp_path)
+
+ class Unserializable:
+ pass
+
+ with pytest.raises(TypeError):
+ module.save_settings({"bad": Unserializable()})
+
+ assert json.loads((tmp_path / ".claude.json").read_text()) == original
+ assert list(tmp_path.glob(".claude.json.*.tmp")) == []
diff --git a/tests/test_firecrawl_install_atomic_write.py b/tests/test_firecrawl_install_atomic_write.py
new file mode 100644
index 0000000..2a71283
--- /dev/null
+++ b/tests/test_firecrawl_install_atomic_write.py
@@ -0,0 +1,31 @@
+"""Static contract for firecrawl's install.ps1 ~/.claude.json write.
+
+install.ps1 cannot be executed in CI (no PowerShell on the Linux/macOS
+runners that run the main suite; see docs/WORKFLOW-public-private.md and the
+windows-smoke workflow for the executed coverage). This test asserts the
+source text contains the temp-then-move write pattern and the -Depth 100
+serialisation depth needed to round-trip an existing ~/.claude.json.
+"""
+
+from pathlib import Path
+
+ROOT = Path(__file__).resolve().parents[1]
+
+
+def test_firecrawl_install_ps1_writes_mcp_config_atomically() -> None:
+ text = (ROOT / "extensions/firecrawl/install.ps1").read_text(encoding="utf-8")
+
+ assert "$TempConfigFile" in text
+ assert "Move-Item -Path $TempConfigFile -Destination $McpConfigFile -Force" in text
+ # The final Set-Content must target the temp file, not $McpConfigFile
+ # directly, so a crash mid-write cannot leave it truncated.
+ assert "Set-Content $TempConfigFile -Encoding UTF8" in text
+ assert "Set-Content $McpConfigFile -Encoding UTF8" not in text
+
+
+def test_firecrawl_install_ps1_uses_depth_100() -> None:
+ text = (ROOT / "extensions/firecrawl/install.ps1").read_text(encoding="utf-8")
+
+ assert "ConvertTo-Json -Depth 100" in text
+ assert "ConvertTo-Json -Depth 10 " not in text
+ assert "ConvertTo-Json -Depth 10\n" not in text