# What Is Source Graph **Context Source Graph lets people, scripts and AI Agents search and read code at an exact Git commit without cloning the repository.** Answers come back in milliseconds from a prepared index, and every result names the commit it was read from, so the same question gets the same evidence. It is open source and self-hosted. A public, read-only [live demo](https://context4ai.org/sourcegraph/) serves this site's own Context knowledge workspace, `context4ai/portal`, together with the source code of `context4ai/context`, `context4ai/sourcegraph` and `context4ai/agent-graph`, so you can try both code search and knowledge-first questions right away. The guides in this section cover connecting to an instance, using it with Context, and — for administrators — registering repositories, self-hosting, securing and operating it. ## The problem it solves An Agent answering a question about code usually needs a handful of exact lines, not a whole repository. Its work is many small, precise rounds of *search, then read* against code it does not have checked out. Cloning every repository into every Agent sandbox at the right revision is slow, and running `rg` or `git grep` over a checkout repeats the same full scan on every call. Source Graph moves that work ahead of the question: it keeps each registered repository mirrored and indexed in the background, so a query reads a prepared index instead of scanning a working tree. The gap widens as repositories grow. ## What you get - **Fast search.** Indexed search typically completes in under 5 ms on the server; in the same region as its callers, a full request including the network stays well under 100 ms. On the demo, a literal search that takes `rg` about 61 ms over a local checkout returns in about 1 ms. [Pinned Search and Reads]() explains where the speed comes from. - **Reproducible reads.** Any branch or tag of a registered repository resolves to one full commit before anything is read, so a search hit, the file it points to and a later diff describe the same snapshot. Branches and tags can be listed and searched by name, author, title or date, newest first, so an Agent can find the version a question is about. - **Ready for Agents.** The same operations — list repositories, find branches and tags, resolve a version, search, read one range or several, list a directory, diff two commits — are available on a website, an HTTP API, an MCP server and a command-line client. Any MCP client that speaks Streamable HTTP can connect, and anonymous access is read-only and limited to public repositories. Repositories can also be private, visible only to their creator, managers and administrators. - **Snapshot retention.** Shallow synchronization of branch heads, snapshots of any commit prepared on demand and a storage budget per repository keep disk use predictable. When a repository reaches its capacity, its oldest snapshots are released first, while current branch heads and versions pinned in its settings are kept. - **Small footprint.** One process manages the Git mirrors, the search engine and background indexing. SQLite is the default database; PostgreSQL and MongoDB are supported. ## A faster option for Context By default, Context reads the code behind an answer from a local repository or from a sparse partial clone of the cited commit, which takes time. When Source Graph is available, it reads the same code at the same commit much faster. Source Graph is a progressive enhancement for performance only: answering without it does not change answer quality. How to connect it and choose the reading mode is in [Connecting Agents, Scripts and the CLI to Source Graph](). Source Graph also works without Context. When an instance holds a team's knowledge repository as well as its code, any MCP client can answer from both with nothing but a retrieval prompt; see [Querying Through MCP in Your Agent](). ## When it is worth connecting Connect Source Graph when Agents or scripts regularly need code from repositories they do not have locally, when answers must cite an exact commit, or when the same repositories are queried many times a day. A local checkout remains simpler for code you are editing right now. Source Graph is a text search and reading service at fixed revisions. Each instance owns its mirrors and indexes on local disk; it scales by giving instances disjoint sets of repositories, not by running replicas over the same data. ## Start in three steps 1. **Try the live demo.** Open [https://context4ai.org/sourcegraph/](https://context4ai.org/sourcegraph/) and search or read code in the browser; no account is needed. 2. **Connect your Agent.** Open the site's **Connect** page and copy the configuration for your Agent host. [Connecting Agents, Scripts and the CLI to Source Graph]() covers MCP, HTTP, the CLI and credentials. To ask questions of this site's knowledge straight away, follow [Querying Through MCP in Your Agent](). 3. **Run your own instance for your repositories.** Start it with Docker, add Google or GitHub sign-in, and the first verified user becomes the administrator who registers repositories. [Ops: Self-Hosting Source Graph]() and [Registering and Managing Repositories]() walk through both. ## Where to go next | To… | Read | | --- | --- | | Connect your Agent, a script or the CLI | [Connecting Agents, Scripts and the CLI to Source Graph]() | | Let Context read cited code without cloning | [Choose how Context reads code]() | | Answer from a team's knowledge and code in any MCP client | [Querying Through MCP in Your Agent]() | | Add repositories and monorepo path groups | [Registering and Managing Repositories]() | | Deploy and configure your own instance | [Ops: Self-Hosting Source Graph]() | | Set up sign-in and decide who can read | [Ops: Sign-in and Permissions]() | | Watch health and jobs, and fix common errors | [Ops: Day-to-Day Operations]() | | Understand how the service is built | [Architecture Overview]() and [Pinned Search and Reads]() | | Look up routes, tools, flags and settings | [HTTP and MCP](), [CLI](), [Query Syntax]() and [Configuration]() | --- ## Sources - [sourcegraph/README.md L1–L15 · e670b1c]() - [sourcegraph/README.md L41–L43 · e670b1c]() - note:20261021/mcp-query.md · mcp-query.md L30–L37 - [sourcegraph/README.md L13–L17 · e670b1c]() - [sourcegraph/README.md L38–L40 · e670b1c]() - [sourcegraph/README.md L18–L26 · e670b1c]() - [sourcegraph/docs/interfaces.md L5–L10 · e670b1c]() - [sourcegraph/docs/interfaces.md L34–L62 · e670b1c]() - [sourcegraph/docs/interfaces.md L86–L88 · e670b1c]() - [sourcegraph/docs/snapshots.md L7–L13 · e670b1c]() - [context/plugins/context/skills/context-inspect-search/SKILL.md L49–L57 · b319dd2]() - [context/plugins/context/skills/context-inspect-search/SKILL.md L160–L200 · b319dd2]() - note:20261021/mcp-query.md · mcp-query.md L5–L9 - [sourcegraph/README.md L81–L92 · e670b1c]() - [sourcegraph/README.md L41–L64 · e670b1c]() - [sourcegraph/README.md L66–L79 · e670b1c]() - [sourcegraph/docs/authentication.md L1–L3 · e670b1c]() - [sourcegraph/README.md L96–L114 · e670b1c]()