Skip to content

Server-Indexed Code Search in Sparse-Checkout Monorepos

Connect coding agents to server-indexed code search and symbol navigation over MCP when sparse-checkout monorepos hide callers from local tools.

Server-indexed code search links an agent in a sparse monorepo checkout to a centralized search and symbol index over Model Context Protocol (MCP) (Sourcegraph, 2026; Sourcegraph MCP Server docs). The agent queries committed, indexed code across the full repository instead of seeing only its local slice (Sourcegraph, 2026). Adopt it only once a monorepo outgrows full local checkouts; on modest monorepos, local search or an IDE avoids indexing and hosting overhead (Sourcegraph, 2026).

When the pattern pays off

Adopt server-indexed code search when four conditions hold:

  • Full local checkouts stall everyday tools. Cursor reports ripgrep scans routinely taking more than 15 seconds on very large enterprise monorepos (Cursor, 2026). Sourcegraph cites Canva's 2022 report of around half a million files and a fresh-clone git status taking about 10 seconds (Sourcegraph, 2026).
  • Engineers and agents run inside sparse checkouts. Cone-mode git sparse-checkout, often paired with --filter=blob:none partial clones, restores local speed by keeping unselected directories off disk (GitHub Blog on sparse-checkout).
  • Tasks modify shared libraries, types, or APIs with callers outside the local slice (Sourcegraph, 2026).
  • CI can build and upload per-project compiler indexes for your main languages (Sourcegraph Precise Code Navigation docs).

When a full checkout stays fast on disk, a local index and local language server avoid network roundtrips, remote storage exposure, and server index lag (Cursor, 2026).

How the two-surface architecture works

The architecture applies separation of concerns between a narrow local write surface and a full-repository read index:

graph TD
    A[Coding agent] -->|Uncommitted reads and edits| L[Local sparse checkout]
    A -->|MCP search and SCIP queries| S[Server code index]
    S -->|Exact definitions and callers| A
    L -->|Slice tests| V[Local verification]
    A -->|Split by CODEOWNERS| P[Per-owner PRs]

Each surface has a distinct boundary:

  1. The local sparse checkout owns active edits, slice tests, and reads of uncommitted files on disk (GitHub Blog on sparse-checkout).
  2. The server index owns committed, repo-wide search and symbol navigation. Sourcegraph exposes keyword_search, nls_search, go_to_definition, find_references, read_file, and list_files at /.api/mcp, gated by repository permissions and MCP#ACCESS (Sourcegraph MCP Server docs).
  3. Ownership-based PR splitting handles cross-team rollout. Break multi-team edits into per-owner PRs using CODEOWNERS, OWNERS, or build files so each team reviews its own slice and CI can batch checks (Sourcegraph, 2026).

Why it works

Local exploration in a sparse monorepo hits two walls, and server-side indexing addresses both.

First, sparse checkouts keep unselected directories off disk (GitHub Blog on sparse-checkout). Local grep and IDE lookups inspect only checked-out files, so an empty search proves absence inside the slice alone (Sourcegraph, 2026). An agent "can rename a function, run the tests in its slice, see them pass, and still break callers in a part of the repo it never looked at" (Sourcegraph, 2026).

Second, raw text search matches strings instead of symbol identity. Searching a common name returns definitions, call sites, comments, log lines, and unrelated functions; that output consumes context tokens (Sourcegraph, 2026). The GitHub Blog reports the same structural limit for CLI agents: raw text matching misses generics, overloads, and transitive types (GitHub Blog on Copilot CLI LSP). Precomputed SCIP indexes link definitions and references by symbol identity across indexed projects. The server returns exact call sites across the repository regardless of what sits on local disk (Sourcegraph Precise Code Navigation docs).

When this backfires

  • Uncommitted writes during active edits. A remote index reflects committed revisions, never uncommitted edits on disk. Cursor notes that regex indexes must stay fresh for "the model reading its own writes" and warns that missing newly written text makes an agent "go into a wild goose chase, waste tokens" (Cursor, 2026). Keep local grep for files inside the working slice.
  • Default-branch lag, skipped files, and branch caps. Sourcegraph indexes the default branch by default and can trail the newest commits. Multi-branch indexing is experimental and caps at 64 branches per repository. By default, indexed search skips files over 1 MB and files with more than 20,000 unique trigrams. The search.largeFiles setting can exempt listed files from both limits after reindexing; binary files remain excluded (Sourcegraph Code Search configuration docs).
  • Silent MCP truncation. Sourcegraph MCP tools enforce payload limits: find_references defaults limit to 10, list_files caps at 1,000 entries, and read_file truncates files over 128KB to the first 200 lines (Sourcegraph MCP Server docs). Treating a capped reply as exhaustive hides callers.
  • Partial SCIP coverage and revision drift. Each SCIP upload covers one project at one revision and requires installed toolchains, resolved dependencies, and generated sources. Changed lines between commits may fail translation and fall back to search-based results, and references exclude unindexed or inaccessible code (Sourcegraph Precise Code Navigation docs). Indexer limits also apply by language: scip-ruby targets Sorbet with best-effort untyped support, and scip-go with GOPACKAGESDRIVER lacks cross-repository navigation (Sourcegraph Precise Code Navigation docs).
  • Operational and licensing overhead. Both Sourcegraph's MCP Server and Precise Code Navigation require Enterprise plans (Sourcegraph MCP Server docs; Sourcegraph Precise Code Navigation docs), and self-hosting adds ongoing work to keep indexes fresh and services upgraded (Sourcegraph, 2026).
  • Unmeasured vendor framing. The sparse-checkout MCP argument rests on one vendor blog post with no controlled sparse-checkout benchmark (Sourcegraph, 2026). Measure local search latency and missed-caller breakages on your own monorepo first.

Example

The GitHub Blog's sample monorepo supports a blobless partial clone and cone-mode sparse-checkout. The commands below select service/common and service/identity; cone mode also includes root files and files directly inside their parent directories (GitHub Blog on sparse-checkout):

git clone --filter=blob:none --no-checkout https://github.com/derrickstolee/sparse-checkout-example
cd sparse-checkout-example
git sparse-checkout set --cone
git checkout main
git sparse-checkout set service/common service/identity

Before modifying a shared symbol inside service/common, the coding agent queries Sourcegraph MCP find_references with repo, path, and symbol. It can also specify revision and limit; limit sets the maximum references returned and defaults to 10 (Sourcegraph MCP Server docs). The agent reads out-of-cone callers through read_file (using startLine and endLine for files over 128KB), uses local search for its own uncommitted edits inside service/common and service/identity, and splits cross-team caller updates into per-owner PRs via CODEOWNERS (Sourcegraph, 2026; Sourcegraph MCP Server docs).

Key Takeaways

  • Treat server-indexed code search as a scale-triggered architecture for sparse-checkout monorepos; keep local search and local LSP on repos that fit on disk.
  • Enforce the read/write boundary in tool instructions: use the server MCP index for committed repo-wide definitions and callers, and local disk search for uncommitted edits.
  • Set explicit limits or paginate MCP calls such as find_references (default limit 10), and confirm per-project SCIP upload coverage before treating a caller list as complete.
  • Split repo-wide edits surfaced by the index into per-owner PRs via CODEOWNERS, OWNERS, or build files so reviews and CI checks stay unblocked.
  • Verify that a client-side commit-plus-overlay index cannot solve your latency problem before taking on Enterprise licensing or self-hosted index operations.