DEV Community

Cover image for I tested Context7 on 6 libraries that changed in 2026
GDS K S
GDS K S

Posted on Edited on Originally published at thegdsks.com

I tested Context7 on 6 libraries that changed in 2026

Ten runs out of ten, my coding agent wrote a Vitest test that looked right and failed. The test I wanted was twelve lines long. The bug was a default that Vitest 5 changed in September, and the model had no idea.

Sponsored by Upstash.

Context7 is an MCP server from Upstash that hands a coding agent up to date, version-specific library docs while it works.

To measure how often stale training data breaks agent code, I ran Claude Code headless (model alias sonnet) on six libraries whose APIs changed in 2026, once with plain file tools and once with Context7 added. The code, tasks, checks and all 120 raw runs live in thegdsks/docs-ab-bench.

TL;DR

Told to use Context7, the agent passed 44 of 45 runs on libraries that changed in 2026, against 35 of 45 for the plain agent on the same batches. The catch: with the tool installed and no instruction to use it, the agent barely called it and scored like the plain agent.

Vitest 5 changed the clearMocks default, and the agent missed it

Vitest 5 result: the baseline agent passed 0 of 10 runs, the agent told to use Context7 passed 5 of 5 in one pass.

The task reads like a junior ticket. Create a vi.fn() handler, call notify(handler) once in a beforeAll hook, then assert the handler ran exactly once. Years of Vitest tutorials teach this shape, so the model writes it from memory:

// src/notify.test.js
import { beforeAll, expect, test, vi } from 'vitest'
import { notify } from './notify.js'

const handler = vi.fn()

beforeAll(() => {
  notify(handler)
})

test('handler is called exactly once', () => {
  expect(handler).toHaveBeenCalledTimes(1)
})
Enter fullscreen mode Exit fullscreen mode

On Vitest 4.1.12 that passes. On 5.0.3 it fails. Version 5.0.0 made clearMocks: true the default, so Vitest now clears call history before every test and the assertion never sees the call from beforeAll:

FAIL  src/notify.test.js > handler is called exactly once
AssertionError: expected "vi.fn()" to be called 1 times, but got 0 times
Enter fullscreen mode Exit fullscreen mode

The fix is one line of config, if you know the default moved:

// vitest.config.js
import { defineConfig } from 'vitest/config'

// Vitest 5 clears mock history before every test; keep the beforeAll call visible.
export default defineConfig({
  test: { clearMocks: false },
})
Enter fullscreen mode Exit fullscreen mode

Against the repo's fixture (src/notify.js), the test fails without this config and passes with it.

The plain agent failed this 10 of 10 times in one pass mode. Given Context7 and this one extra line in the prompt, it passed 5 of 5:

"Before you write code, use the Context7 tools to look up the current documentation for the libraries involved."

The harness changes one thing: the MCP config

Both arms get the same task text, system prompt, model and file tools. The baseline arm starts Claude Code with an empty server list and --strict-mcp-config, so it cannot pick up any docs server from my machine. The Context7 arm gets the remote Context7 server and nothing else.

Every run starts in a fresh temp folder with the library version pinned. When the agent stops, the subject's own check.sh runs inside that folder and exits 0 or 1. For Vitest it greps the test file for a mock assertion and a beforeAll, then reads the JSON report from vitest run. Nobody judges the code by vibes, me included.

I ran two modes. One pass mode (oneshot) gives the agent file tools only and no way to run anything. Agentic mode adds a shell for npm, npx and node, so the agent can run the tests and read the error.

Each subject also ships a correct and a stale reference solution. A verify command confirms the untouched fixture fails, the correct answer passes and the stale one fails. If a check could not fail, a pass would mean nothing.

Every result, with and without Context7

Library Mode Baseline Context7, told to use it Context7, not told
Vitest 5 oneshot 0 of 5 5 of 5 2 of 5
Vitest 5 agentic 3 of 5 5 of 5 not run
SvelteKit 3 oneshot 4 of 5 5 of 5 3 of 5
SvelteKit 3 agentic 5 of 5 5 of 5 not run
AI SDK 7 oneshot 5 of 5 5 of 5 5 of 5
AI SDK 7 agentic 5 of 5 5 of 5 not run
React Router 8 oneshot 3 of 5 5 of 5 not run
Astro 7 oneshot 5 of 5 4 of 5 not run
TypeScript 6 oneshot 5 of 5 5 of 5 not run

I ran the one pass baseline twice with an identical prompt, so pooled it comes to 0 of 10 for Vitest 5, 8 of 10 for SvelteKit 3 and 10 of 10 for AI SDK 7. React Router 8 swapped data for loaderData in meta args, and Astro 7 now needs @astrojs/markdown-remark for remark plugins. The Wilson intervals for the hinted cells run from 88 to 100 percent for Context7 and 64 to 87 percent for the baseline. They do not overlap, barely.

With a shell, SvelteKit 3 needs no docs tool

SvelteKit 3 result with a shell: both the baseline agent and the Context7 agent passed 5 of 5 runs.

SvelteKit 3 stopped reading svelte.config.js and moved config into the sveltekit() Vite plugin. It also removed $app/stores in favor of $app/state. In one pass mode the plain agent got 8 of 10.

Give it a shell and both arms pass 5 of 5. The plain agent can run the build and read the error. A loud break documents itself.

Vitest shows the opposite case. A cleared mock produces no import error and no deprecation warning, only an assertion that says zero calls. With a shell the plain agent climbed to 3 of 5, and the Context7 arm held at 5 of 5. Silent behavior changes are where looking up the docs first pays off.

When the model already knows the library, docs cost tokens

AI SDK 7 result: the baseline agent and the Context7 agent both passed 5 of 5 runs.

AI SDK 7 and TypeScript 6 changed too, yet the model handled both alone. Both arms passed 5 of 5 everywhere. On Astro 7 the result flipped by one run, 4 of 5 for Context7 against 5 of 5 for the baseline. I count that as noise, and it stays in the table.

Context7 does little until you tell the agent to use it

My first Context7 batch had no hint. The agent had the tool and barely touched it, at 0.6 calls per run on Vitest 5 and SvelteKit 3 and zero on AI SDK 7. The results looked like the baseline: 2 of 5 on Vitest, 3 of 5 on SvelteKit.

With the one line hint the agent made about 2 calls per run, one to each of the server's two tools (resolve-library-id and query-docs), and Vitest went to 5 of 5. The official npx ctx7 setup also installs a skill meant to trigger Context7 on library questions. My harness used the bare server without it, so the no-hint column covers a bare install only.

What up to date docs cost in tokens

Mean tokens per run, rounded down to the thousand. Claude Code counts cache reads and writes as input, so these are totals, not fresh tokens.

Library and mode Baseline Context7, told to use it
Vitest 5, one pass 35k 64k
Vitest 5, with a shell 105k 98k
SvelteKit 3, one pass 83k 67k
SvelteKit 3, with a shell 49k 74k
AI SDK 7, with a shell 95k 105k
TypeScript 6, one pass 37k 52k
Astro 7, one pass 160k 148k

The cheapest Vitest run is the baseline at 35k tokens, and it fails every time. Docs cost extra where the model already knew the API. Upstash's own benchmark against web search reports about 37 percent fewer tokens and about 35 percent lower cost per query. Upstash wrote it and it skips answer quality, so I keep it apart from mine.

My first harness was unfair to the plain agent

The first shell mode allowed a short list of commands, and a refused command ended the run. The plain agent wrote a stale config file, saw the build error, then tried to delete the file. Delete was not on the list, so the run stopped. The Context7 arm never wrote the stale file.

The giveaway: the plain agent scored worse with a shell than without one. I threw that batch away and rebuilt the shell inside a sandbox, where writes stay in the project folder and network only reaches the package registry. No number here comes from the discarded batch.

Set up Context7 MCP in one command

npx ctx7 setup
Enter fullscreen mode Exit fullscreen mode

It runs OAuth, creates an API key and installs a skill for your agent. It needs Node 22.13 or newer. The free plan gives you 1,000 calls per month, and Pro costs $10 per seat per month with 2,000 calls per seat. At about 2 calls per task, that stretches far.

If you run the MCP server locally instead, pin it. CVE-2026-75130, a prompt injection through the Custom AI Instructions feature, got its fix in context7-mcp 2.1.3, so anything older should go. For Claude Code, save this as .mcp.json in your project root. Create a free key in the Context7 dashboard and export it as CONTEXT7_API_KEY:

{
  "mcpServers": {
    "context7": {
      "command": "npx",
      "args": ["-y", "@upstash/context7-mcp@4.7.3"],
      "env": { "CONTEXT7_API_KEY": "${CONTEXT7_API_KEY}" }
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

The API guide covers keys and rate limits. Then add the hint to your agent's instructions file, such as CLAUDE.md, unless the setup skill covers it.

Reproduce the benchmark on your machine

You need the Node version listed in the repo README and the Claude Code CLI, installed and logged in.

git clone https://github.com/thegdsks/docs-ab-bench
cd docs-ab-bench
npm install
cp .env.example .env
npx tsx src/cli.ts verify --subject vitest-5
npx tsx src/cli.ts report --batch headline-oneshot-hint
BENCH_DOCS_HINT=1 npx tsx src/cli.ts run --subject vitest-5 --arm both --n 5 --mode oneshot --driver claude-code --model sonnet --batch mine
npx tsx src/cli.ts report --batch mine
Enter fullscreen mode Exit fullscreen mode

The first verify installs the pinned dependencies once and caches them. The first report reads my shipped runs for free (ls runs lists every batch), while run spends your own Claude Code usage. Put CONTEXT7_API_KEY in .env if you have one. Drop BENCH_DOCS_HINT=1 and pick a new batch name to see the unprompted behavior, or add --mode agentic for the sandboxed shell.

Where these numbers stop

Five runs per cell is small. One 5 of 5 cell leaves a wide interval, so I lean on the pooled 44 of 45 and the 0 of 10. I used one model through one agent driver. I also wrote the tasks myself, and I picked libraries known to have changed, so the setup favors a docs tool by design. On a library your model already knows, my own data says you will usually pay extra tokens for nothing.

What Context7 changes in the code your agent writes

Context7 serves the agent current docs for a library, for a specific version if you name it, at the moment it needs them. In my runs that came down to four effects.

Current syntax instead of remembered syntax

The Vitest 5 failures were a stale default, not a made-up function. With the docs in context the agent wrote against the new clearMocks default and passed 5 of 5.

Fewer bugs from changes after the model's training

SvelteKit 3 moved config out of svelte.config.js. In one pass the plain agent got 8 of 10 and the Context7 agent got 5 of 5.

Docs that match your version

A Context7 library id can carry a version, in the form /owner/repo/<version>, so you can point the agent at the release in your lockfile and not only the latest one.

A lookup to check against

A model's wrong answer and its right answer sound the same. Reading the docs gives it something to verify instead of recall.

Upstash describes the aim as fewer outdated or hallucinated APIs. I measured the outdated kind and did not test for invented ones.

Context7 FAQ

Does Context7 reduce hallucinations in generated code?

It cut the outdated-API failures in my runs, for example 0 of 10 to 5 of 5 on Vitest 5. I did not test for invented functions, so I cannot say it removes those.

Does Context7 work if you do not tell the agent to use it?

Barely, as a bare MCP server. Without the hint the agent averaged 0.6 calls per run on Vitest 5 and scored 2 of 5. I did not test the setup skill.

Does Context7 cost more tokens?

Sometimes. On TypeScript 6 the mean rose from 37k to 52k tokens with no change in passes, while on Vitest 5 with a shell it fell from 105k to 98k.

Is Context7 safe to install?

Pin a local server to context7-mcp 2.1.3 or later, which fixes CVE-2026-75130. The hosted server needs no pin.

Bottom line

Install Context7, then make sure something tells the agent to use it. That one line took my agent from 0 of 10 to 5 of 5 on a Vitest default that throws no error. If a library you depend on is missing, you can add it to Context7. What silent default in your stack would your agent still get wrong today?


Originally published at thegdsks.com.

Context7 and Upstash names and logos are trademarks of Upstash, Inc., shown because this is a sponsored post about their product.


GDS K S · thegdsks.com · building GLINR Studios · follow on X @thegdsks

The model's training data has a release date, and your dependencies keep shipping after it.

Top comments (1)

Collapse
 
robertpaschal profile image
Odinaka Robert Nnamani •

0 of 10 on Vitest 5, then 5 of 5 once the agent actually looked at the docs. The silent default did all the damage.