Skip to content

JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.

Python

Revert "fix(mcp): review 追加——opt-in 指纹根声明(JIUWENSWARM_MCP_BUNDLE_FINGERPRINT_ROOTS)"

huxiaokai496b219dddeb
diff --git a/jiuwenswarm/common/mcp_config.py b/jiuwenswarm/common/mcp_config.py
index b727fc1842..89ceccaf98 100644
--- a/jiuwenswarm/common/mcp_config.py
+++ b/jiuwenswarm/common/mcp_config.py
@@ -814,12 +814,6 @@ def _office_claw_mcp_schema_cache_enabled() -> bool:
_OFFICE_CLAW_MCP_BUNDLE_MAX_FILES = 256
-# Opt-in extra directories folded into the bundle fingerprint for layouts
-# that keep schema-defining code outside the entry script's directory tree.
-# Comma-separated; relative paths resolve against params["cwd"].
-_OFFICE_CLAW_MCP_BUNDLE_FINGERPRINT_ROOTS_ENV = (
- "JIUWENSWARM_MCP_BUNDLE_FINGERPRINT_ROOTS"
-)
def _fingerprint_bundle_tree(root: Path) -> list[dict[str, Any]] | None:
@@ -861,47 +855,6 @@ def _fingerprint_bundle_tree(root: Path) -> list[dict[str, Any]] | None:
return sorted(entries, key=lambda entry: entry["path"])
-def _declared_fingerprint_roots(params: Mapping[str, Any]) -> list[Path]:
- """Resolve JIUWENSWARM_MCP_BUNDLE_FINGERPRINT_ROOTS into directories.
-
- Declared roots join the bundle fingerprint with the same walker rules
- (node_modules and *.map skipped, per-root file cap). Unset or empty
- entries are ignored; a declared root that does not resolve to an
- existing directory is skipped rather than failing discovery.
- """
- raw = str(
- os.environ.get(_OFFICE_CLAW_MCP_BUNDLE_FINGERPRINT_ROOTS_ENV, "") or ""
- ).strip()
- if not raw:
- return []
- cwd_raw = str(params.get("cwd") or "").strip()
- bases = [Path(cwd_raw).expanduser()] if cwd_raw else []
- bases.append(Path.cwd())
- roots: list[Path] = []
- for item in raw.split(","):
- candidate = item.strip()
- if not candidate:
- continue
- probe = Path(candidate).expanduser()
- resolved: Path | None = None
- if probe.is_absolute():
- resolved = probe
- else:
- for base in bases:
- joined = base / probe
- if joined.is_dir():
- resolved = joined
- break
- if resolved is None:
- try:
- resolved = probe.resolve(strict=False)
- except OSError:
- continue
- if resolved.is_dir():
- roots.append(resolved)
- return roots
-
-
def _office_claw_mcp_build_fingerprint(
params: Mapping[str, Any],
) -> list[dict[str, Any]] | None:
@@ -920,12 +873,6 @@ def _office_claw_mcp_build_fingerprint(
modules next to it, so a rebuild that only touches those imports must
still rotate the key. ``node_modules`` and ``*.map`` files are skipped.
- ``JIUWENSWARM_MCP_BUNDLE_FINGERPRINT_ROOTS`` (comma-separated directories,
- relative to ``params['cwd']``) opts additional trees into the fingerprint
- for layouts that keep schema-defining code outside the entry's owning
- directory — the fingerprint then covers the declared roots with the same
- walker rules.
-
Returns ``None`` when a bundle tree exceeds ``_OFFICE_CLAW_MCP_BUNDLE_MAX_FILES``
files — the caller then bypasses the cache instead of trusting a
fingerprint it could not fully compute.
@@ -994,20 +941,6 @@ def _office_claw_mcp_build_fingerprint(
continue
seen_paths.add(entry["path"])
fingerprints.append(entry)
-
- for root in _declared_fingerprint_roots(params):
- root_key = _normalized_path(str(root))
- if root_key in expanded_dirs:
- continue
- expanded_dirs.add(root_key)
- tree = _fingerprint_bundle_tree(root)
- if tree is None:
- return None
- for entry in tree:
- if entry["path"] in seen_paths:
- continue
- seen_paths.add(entry["path"])
- fingerprints.append(entry)
return sorted(fingerprints, key=lambda entry: entry["path"])
diff --git a/tests/unit_tests/agentserver/test_mcp_schema_cache.py b/tests/unit_tests/agentserver/test_mcp_schema_cache.py
index d858cb2739..805123df57 100644
--- a/tests/unit_tests/agentserver/test_mcp_schema_cache.py
+++ b/tests/unit_tests/agentserver/test_mcp_schema_cache.py
@@ -362,49 +362,3 @@ async def test_capacity_bound_clears_orphaned_entries(
# the cleared entries are gone: a repeat of the first variant re-discovers
await mcp_config.list_office_claw_mcp_tools(variants[0])
assert calls == 4, "evicted entry must re-discover"
-
-
-def test_declared_fingerprint_roots_extend_coverage(
- tmp_path,
- monkeypatch: pytest.MonkeyPatch,
-) -> None:
- """JIUWENSWARM_MCP_BUNDLE_FINGERPRINT_ROOTS folds extra directories into the key.
-
- For layouts that keep schema-defining code outside the entry's owning
- directory (see the review on !9045): files under a declared root rotate
- the cache key even though the entry tree itself is unchanged; without
- the declaration they stay invisible to the fingerprint.
- """
- dist = tmp_path / "dist"
- dist.mkdir()
- entry = dist / "index.js"
- entry.write_text("shell v1")
-
- shared = tmp_path / "shared"
- shared.mkdir()
- (shared / "toolsets.js").write_text("toolset v1")
-
- params = {
- "command": "node",
- "args": [str(entry)],
- "cwd": str(tmp_path),
- "env": {},
- }
-
- # undeclared: changes under shared/ do not affect the key
- key1 = mcp_config._office_claw_mcp_schema_cache_key(params)
- (shared / "toolsets.js").write_text("toolset v2-with-more-bytes")
- key2 = mcp_config._office_claw_mcp_schema_cache_key(params)
- assert key1 == key2, "undeclared external tree must not affect the key"
-
- # declared: the root joins the fingerprint and its changes rotate the key
- monkeypatch.setenv("JIUWENSWARM_MCP_BUNDLE_FINGERPRINT_ROOTS", "shared")
- key3 = mcp_config._office_claw_mcp_schema_cache_key(params)
- assert key3 is not None and key3 != key2, (
- "declared root must join the fingerprint"
- )
- (shared / "toolsets.js").write_text("toolset v3-with-even-more-bytes")
- key4 = mcp_config._office_claw_mcp_schema_cache_key(params)
- assert key4 is not None and key4 != key3, (
- "file change under a declared root must rotate the cache key"
- )