---
title: "Server-Indexed Code Search in Sparse-Checkout Monorepos"
term: "Server-Indexed Code Search"
description: "Give coding agents a server-side code-search and SCIP navigation index over MCP to find callers outside a sparse monorepo checkout."
tags:
  - context-engineering
  - agent-design
  - mcp
  - tool-agnostic
aliases:
  - server-side code navigation for coding agents
  - sparse-checkout monorepo code search
  - MCP code intelligence for monorepos
last_reviewed: 2026-11-28
maturity: emerging
---

# 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](https://sourcegraph.com/blog/monorepo-code-search-ai-coding-agents); [Sourcegraph MCP Server docs](https://sourcegraph.com/docs/api/mcp)). The agent queries committed, indexed code across the full repository instead of seeing only its local slice ([Sourcegraph, 2026](https://sourcegraph.com/blog/monorepo-code-search-ai-coding-agents)). 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](https://sourcegraph.com/blog/monorepo-code-search-ai-coding-agents)).

## 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](https://cursor.com/blog/fast-regex-search)). Sourcegraph cites Canva's 2022 report of around half a million files and a fresh-clone `git status` taking about 10 seconds ([Sourcegraph, 2026](https://sourcegraph.com/blog/monorepo-code-search-ai-coding-agents)).
- 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](https://github.blog/open-source/git/bring-your-monorepo-down-to-size-with-sparse-checkout/)).
- Tasks modify shared libraries, types, or APIs with callers outside the local slice ([Sourcegraph, 2026](https://sourcegraph.com/blog/monorepo-code-search-ai-coding-agents)).
- CI can build and upload per-project compiler indexes for your main languages ([Sourcegraph Precise Code Navigation docs](https://sourcegraph.com/docs/code-navigation/precise-code-navigation)).

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](https://cursor.com/blog/fast-regex-search)).

## How the two-surface architecture works

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

```mermaid
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](https://github.blog/open-source/git/bring-your-monorepo-down-to-size-with-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](https://sourcegraph.com/docs/api/mcp)).
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](https://sourcegraph.com/blog/monorepo-code-search-ai-coding-agents)).

## 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](https://github.blog/open-source/git/bring-your-monorepo-down-to-size-with-sparse-checkout/)). Local `grep` and IDE lookups inspect only checked-out files, so an empty search proves absence inside the slice alone ([Sourcegraph, 2026](https://sourcegraph.com/blog/monorepo-code-search-ai-coding-agents)). 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](https://sourcegraph.com/blog/monorepo-code-search-ai-coding-agents)).

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](https://sourcegraph.com/blog/monorepo-code-search-ai-coding-agents)). 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](https://github.blog/ai-and-ml/github-copilot/give-github-copilot-cli-real-code-intelligence-with-language-servers/)). Precomputed [SCIP](https://github.com/sourcegraph/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](https://sourcegraph.com/docs/code-navigation/precise-code-navigation)).

## 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](https://cursor.com/blog/fast-regex-search)). 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](https://sourcegraph.com/docs/code-search/configuration)).
- 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](https://sourcegraph.com/docs/api/mcp)). 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](https://sourcegraph.com/docs/code-navigation/precise-code-navigation)). 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](https://sourcegraph.com/docs/code-navigation/precise-code-navigation)).
- Operational and licensing overhead. Both Sourcegraph's MCP Server and Precise Code Navigation require Enterprise plans ([Sourcegraph MCP Server docs](https://sourcegraph.com/docs/api/mcp); [Sourcegraph Precise Code Navigation docs](https://sourcegraph.com/docs/code-navigation/precise-code-navigation)), and self-hosting adds ongoing work to keep indexes fresh and services upgraded ([Sourcegraph, 2026](https://sourcegraph.com/blog/monorepo-code-search-ai-coding-agents)).
- Unmeasured vendor framing. The sparse-checkout MCP argument rests on one vendor blog post with no controlled sparse-checkout benchmark ([Sourcegraph, 2026](https://sourcegraph.com/blog/monorepo-code-search-ai-coding-agents)). 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](https://github.blog/open-source/git/bring-your-monorepo-down-to-size-with-sparse-checkout/)):

```bash
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](https://sourcegraph.com/docs/api/mcp)). 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](https://sourcegraph.com/blog/monorepo-code-search-ai-coding-agents); [Sourcegraph MCP Server docs](https://sourcegraph.com/docs/api/mcp)).

## 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.

## Related

- [Semantic Context Loading: Language Server Plugins for Agents](semantic-context-loading.md) — local LSP symbol lookup over checked-out files, the client-side counterpart when a full checkout fits on disk
- [Agent-Tuned Code Search: Retrieval Built for the Loop](agent-tuned-code-search.md) — higher-level delegated search contracts layered above a hosted index
- [Sparse-Checkout Worktrees for Monorepo Agent Isolation](../tools/claude/sparse-paths-monorepo-isolation.md) — restricting a Claude Code worktree to a sparse cone, the local isolation setup that creates the visibility gap this pattern closes
- [Indexed Regex Search for Agent Tools](../tool-engineering/indexed-regex-search-agent-tools.md) — local trigram and sparse n-gram indexes anchored to a Git commit, the main alternative when full checkouts remain viable
- [Whole-Codebase Visibility as a Migration Prerequisite](../workflows/whole-codebase-visibility-migration-prerequisite.md) — the up-front scoping check for deciding when large migrations require whole-codebase visibility before agent dispatch
