Skip to content

fix(mcp): honor workspace filters and shared engine resource controls - #24

Open
Christopher-Schulze wants to merge 1 commit into
codegraph-ai:mainfrom
Christopher-Schulze:fix/mcp-resource-controls
Open

Christopher-Schulze wants to merge 1 commit into
codegraph-ai:mainfrom
Christopher-Schulze:fix/mcp-resource-controls

Conversation

@Christopher-Schulze

Copy link
Copy Markdown

Fixes #23.

Generated source files in an ignored directory currently enter the graph through MCP file events, even when initial indexing excludes them. Each batch then repeats full-graph path queries for individual files. This change gives workspace indexing and the MCP watcher the same filters and makes the existing shared-engine mode preserve the resource settings needed for parallel agent sessions.

Changes

  • Share compiled exclusions and cached root/nested .gitignore matchers between directory indexing and watcher filtering. Preserve .codegraphignore, CLI excludes and built-in exclusions; apply size/depth limits and enforce the file limit for new watcher entries. Reload ignore rules on changes without reacting to read-access notifications.
  • Group graph nodes by path once per watcher batch instead of repeating full-graph property queries. Rebuild search indexes after deletion-only batches, prune orphan vectors after node removal, and cancel the watcher task when its owner is dropped.
  • Skip memory-manager/model initialization in graph-only indexing, including warm daemon snapshots.
  • Forward resource flags during engine auto-start, apply graph-only/profile settings to shared backends, serialize workspace initialization with OnceCell, and hold a per-socket file lock through startup and the engine lifetime.
  • Preserve explicitly supplied workspace arguments in the npm relay wrapper and document repository-local ignores and shared-engine configuration.

The ignore crate supplies Git ignore matching; fs2 was already a workspace dependency. No release/version or default transport changes are included.

Validation

macOS arm64, Rust 1.98.0, isolated homes/workspaces/build output, two build jobs:

  • cargo test --locked -p codegraph-server -- --test-threads=1: 412 passed, 0 failed. One existing model-dependent test remains ignored by upstream; no tests were disabled or weakened.
  • bun mcp-package/test/wrapper-args.test.js: 14 checks passed. The same updated test file against the unchanged upstream wrapper fails the four explicit-workspace cases.
  • Real stdio-MCP reproduction against installed 0.20.1 and the patched debug binary: creating 20 Rust files under a directory excluded by .gitignore, .codegraphignore and --exclude produces searchable unwanted symbols before the patch, and none afterward. The original invokes MemoryManager::initialize under --graph-only; the patched binary does not. Both runs use the local static backend with an absent model path to avoid model downloads.
  • Regression coverage includes real filesystem events, nested ignore/negation rules, deleted paths, size/depth/file limits, graph-only one-shot execution, concurrent cold workspace attaches and two real auto-starting socket relays.
  • cargo clippy --locked -p codegraph-server --all-targets --no-deps completes with existing warnings. -D warnings also fails on unchanged upstream 64f4f30 (unused/dead code and existing Clippy findings); the patch adds no diagnostic at a changed/new source location. A global RUSTFLAGS=-Dwarnings build likewise stops at the pre-existing BODY_PREFIX_MAX_CHARS import in codegraph-c/src/visitor.rs.
  • Scoped rustfmt checks and git diff --check pass. Full-workspace cargo fmt --all -- --check already reports unrelated upstream formatting differences; those files are untouched.

Behavior boundaries

Engine options remain process-wide: the first starter configures a socket; later clients do not reconfigure it. The README documents consistent settings, explicitly managed engines, separate sockets and restarting after configuration changes. Existing indexed entries require a forced reindex after ignore-rule changes. Global Git ignores and .git/info/exclude are outside this change. Direct manual file indexing remains available.

The saved production sample identifies the watcher/query hot path, but does not prove an infinite loop or database corruption. This PR makes no throughput or memory-reduction claim based on the synthetic reproduction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP watcher bypasses workspace ignores; shared engine drops resource controls

1 participant