# Context7 Now Gives Agents the Source Code, Not Just the Docs

> **Source:** https://upstash.com/blog/context7-source-code
> **Date:** 2026-12-02
> **Author(s):** Enes Akar
> **Reading time:** 8 min read
> **Tags:** context7, mcp, agents, dev-tools
> **Format:** text/markdown — machine-readable content for agents and LLMs

Four new Context7 tools let coding agents search and read a library's source code at any version, without downloading the package.

---

Until now, Context7 had two tools: one to find a library, one to fetch its docs. That was enough for most questions. But docs don't cover everything.

Today we're adding four new tools that let your agent search and read a library's source code. This is the biggest change to Context7 since we launched. The tools are experimental for now: turn them on under **Tools** in your [Context7 dashboard](https://context7.com/dashboard?tab=tools).

## Why source code

Docs tell you how a library should be used. The code tells you how it actually works. Default values, undocumented options, the exact place an error is thrown: these usually live only in the code.

Coding agents already know this. When the docs aren't enough, they open the package in `node_modules`. If the package isn't installed, they download it or clone the repo. That costs time and tokens, and often the agent ends up reading the wrong version.

With Context7, the agent skips all of that. It asks for the code it needs, at the version it needs, and gets it back in one call.

## The four tools

- **grep-code**: Search a library's source for a string or regex. Good for finding where an error message comes from, or every place an option is read.
- **glob-code**: List files by path pattern. Lets the agent see how a library is laid out before reading anything.
- **read-code**: Read a file, or just the lines it needs. No need to pull whole files into context.
- **find-symbol**: Jump to the definition of a function, class or type. The fastest way to get a real signature instead of guessing one.

All four work on the same version as the docs the agent is reading, so docs and code always match.

## How it works

Code search works for any open-source library on GitHub, at any version.

More than 170,000 libraries are already in Context7. If you ask for one that isn't, we index it on demand. This usually takes less than a minute. After that, it's instant.

You don't need to change your prompts. Each tool has a clear MCP description, so the agent decides on its own when to read docs and when to go to the code.

## Why not just grep locally?

Agents like Claude Code can already grep a package on disk. Here's what Context7 adds:

1. **No downloads.** If the package isn't installed, the agent doesn't need to clone a repo or run `npm install`.
2. **Any version.** The agent can read a version other than the one installed, older or newer.
3. **Packages you don't have.** It can read a library before you even add it to the project.
4. **Less noise.** A grep over `node_modules` returns hits from hundreds of packages. Ours searches only the library you asked about.
5. **Source, not bundles.** Many npm packages ship compiled or minified code. We serve the original source, which is far easier for an agent to read.
6. **Docs and code in one place.** Same MCP server, same versions, no mismatch.
7. **Works in sandboxes.** No file system or network access needed beyond the MCP call.

## When it helps

- **Gaps in the docs.** Undocumented options, default values, edge cases.
- **Debugging.** Find exactly where an error message is thrown and why.
- **Upgrades.** Compare two versions of the code and spot breaking changes before you upgrade.
- **Choosing a library.** See how a package works before you install it.
- **Real signatures.** Read types and function signatures with find-symbol instead of guessing them.
- **Real examples.** Pull usage examples from a library's own tests.

## Benchmark

We compared Context7 with what an agent does without it: download the package from npm and search it on disk. The short version: with Context7, the agent reads far less, and it finishes faster and for less money.

### One search

We looked for one fact in three libraries, once with a local grep and once with one grep-code call.

| Question | Package size | Local grep returns | Context7 grep-code returns |
| --- | --- | --- | --- |
| AI SDK: default `maxRetries` | 1.8 MB, 743 files | 328 hits in 68 files, \~9k tokens | 10 lines, \~250 tokens |
| Next.js: where is "Dynamic server usage" thrown? | 44 MB, 9,220 files | 28 files, \~2k tokens | 1 line, \~130 tokens |
| esbuild: where is "Could not resolve" thrown? | 10 MB, 11 files | nothing | 5 lines, \~270 tokens |

Tokens are how much text each result adds to the agent's context.

What the numbers show:

- **15 to 36 times fewer tokens.** A local grep matches every copy of the string: bundles, source maps, type files. Context7 searches one copy of the source. And we were generous to the local side: we cut each local line at 300 characters. Uncut, the AI SDK search returns \~500k tokens and Next.js \~13M.
- **Source, not bundles.** The local hits point to compiled files in `dist/`. Context7 points to the original source, like `packages/ai/src/util/retry-with-exponential-backoff.ts:66`.
- **Some packages ship no source at all.** esbuild's npm package is a compiled Go binary, so a local grep finds nothing. Context7 points to `internal/bundler/bundler.go:823`.
- **Any version, no extra download.** Asking for Next.js `v13.4.0` returned the file as it was in May 2023. Locally, that's another 12 MB download.

### A full agent run

We gave Claude Code the question from the example below: does the AI SDK wait two minutes when a provider replies `Retry-After: 120`? It ran three times with Context7 and three times without. Both setups had the same local tools (npm, tar, grep and file reading) and no web access.

All six runs found the right answer. But in every run, Claude Code with Context7 was faster, needed fewer turns and cost less. A turn is one model call, and the agent spends one on each step, like a search or a file read.

The difference comes from where the agent looks. With Context7, it read the original source and cited `retry-with-exponential-backoff.ts`. Without it, it downloaded the packages from npm and searched them on disk, and two of the three runs ended up citing a compiled bundle, `default-stop-condition-BrpA-6RQ.js`.

| Run | Claude Code with Context7 | Claude Code without Context7 |
| --- | --- | --- |
| 1 | 12 turns, 79 s, $0.85 | 19 turns, 126 s, $0.94 |
| 2 | 13 turns, 71 s, $0.94 | 40 turns, 246 s, $1.70 |
| 3 | 9 turns, 67 s, $0.78 | 21 turns, 124 s, $0.96 |

Before these runs, each setup answered one short throwaway prompt to warm the prompt cache, so neither side paid extra for going first. That run isn't counted.

## A real example

**The question.** Your app calls a model through the AI SDK's `generateText`, and you hit the provider's rate limit. The provider answers `429 Too Many Requests` and asks you to try again in two minutes, with the header `Retry-After: 120`. Does the SDK wait two minutes and retry?

**What the docs say.** The SDK retries twice by default (`maxRetries: 2`), and one reference page says it respects `Retry-After`. Nothing says how long it waits, or whether there's a limit.

**What the code says.** The agent needed two calls: `grep-code` to find the retry logic, and `read-code` to read it in `packages/ai/src/util/retry-with-exponential-backoff.ts`. This is the part that picks the wait (comments ours):

```ts
// Use Retry-After only if it is under 60 seconds
// (or under the SDK's own delay)
if (ms != null && !Number.isNaN(ms) && 0 <= ms &&
    (ms < 60 * 1000 || ms < exponentialBackoffDelay)) {
  return ms;
}
// Otherwise use the SDK's own delay: 2 seconds, then 4 seconds
return exponentialBackoffDelay;
```

**The answer: no.** With the default settings, the SDK ignores a `Retry-After` of 60 seconds or more. It would only use a longer one if its own delay were even longer, and with the defaults it never is. With `Retry-After: 120`:

1. The first call fails with `429`.
2. The SDK waits 2 seconds and retries. Still `429`.
3. It waits 4 seconds and retries. Still `429`.
4. It gives up and throws a `RetryError`.

The provider asked for two minutes. The SDK gave up after about six seconds.

**The fix.** Set `maxRetries: 0` and handle `429` yourself, waiting as long as `Retry-After` asks.

## Try it

Open the **Tools** tab in your [Context7 dashboard](https://context7.com/dashboard?tab=tools) and turn on **Source search tools**. Within a few minutes, every MCP client that connects with your account or one of your API keys gets grep-code, glob-code, read-code and find-symbol. They're free while they're experimental.

![The Tools tab in the Context7 dashboard, with the Source search tools switch under Experimental tools](/blog/context7-source-code/source-search-tools.png)

We'll watch how they're used. If they prove useful and efficient, we'll turn them on for everyone.

Follow [@context7ai](https://x.com/context7ai) on X and tell us what works and what doesn't.

---

This site has a search endpoint: https://context7.com/api/v2/ask?siteKey=ask_4cf2adc7846aa874f833b068&query=<URL-encoded question>. It returns documentation that answers the question, with a source link for each part. No API key is needed. If nothing matches, it says so.