Fix search_source: pass env vars via mcp.json interpolation, search Plugins/, cap at 40 total lines

- .mcp.json: pass UE_ENGINE_ROOT and UE_DOCS_PATH via ${VAR} interpolation so the
  MCP server subprocess inherits them without hardcoding paths
- search_source: search both Engine/Source/ and Engine/Plugins/ (path_hint applied
  under both); switch from -m 40 (per-file cap) to streaming Popen with a true
  40-line total cap; fix UE_ENGINE_ROOT to point at Engine/ not the repo root
- Update README and CLAUDE.md to reflect the above

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-01 18:11:46 -05:00
parent a51102c1eb
commit 77c972977a
4 changed files with 30 additions and 13 deletions

View File

@@ -207,15 +207,26 @@ def get_file(relative_path: str) -> str:
def search_source(pattern: str, path_hint: str = "") -> str:
"""Grep UE source .h files for pattern. Requires $UE_ENGINE_ROOT.
path_hint: optional subdirectory under Engine/Source/ (e.g. 'Runtime/Engine').
Searches both Engine/Source/ and Engine/Plugins/.
Returns up to 40 matching lines with file:line context."""
root = _engine_root() / "Engine" / "Source"
if path_hint:
root = root / path_hint
result = subprocess.run(
["grep", "-rn", "--include=*.h", "-m", "40", pattern, str(root)],
capture_output=True, text=True, timeout=15
engine = _engine_root()
candidates = [engine / "Source", engine / "Plugins"]
search_dirs = [d / path_hint if path_hint else d for d in candidates]
search_dirs = [d for d in search_dirs if d.exists()]
if not search_dirs:
return "(no matches)"
grep = subprocess.Popen(
["grep", "-rn", "--include=*.h", pattern, *map(str, search_dirs)],
stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, text=True
)
return result.stdout or "(no matches)"
lines = []
for line in grep.stdout:
lines.append(line)
if len(lines) == 40:
grep.kill()
break
grep.wait()
return "".join(lines) or "(no matches)"
if __name__ == "__main__":