Up-to-date technical documentation for your agents

Hi everyone, how many times do we write code with our agents only to end up with methods that don’t exist, syntax from two versions back, or configurations that have long since been deprecated? The problem is well known: models reason over their training data, which ages fast compared to the pace of framework and library releases.

In today’s article I want to tell you about Context7, a project that solves this problem in a simple way: it pulls in the up-to-date, version-specific documentation of libraries and injects it straight into the model’s context.

I’ve been trying to add this tool to my agents’ harness for a while now, and I can say that in some contexts the quality of the code produced has improved a lot. The main advantage is that Context7 hands agents documentation that is already clean and optimized, something you don’t get with an agent that looks things up on the web.

Let’s dig into the details now and see how it works.

What Context7 is for

Context7 is a platform that indexes the documentation of languages, libraries and more, and then exposes it to AI agents through the MCP protocol or a skill. When we ask our agent something about a library, instead of answering “from memory” the agent queries Context7 and gets back documentation excerpts and code snippets taken from the official sources.

The project is open source (GitHub repository) and can work in two modes:

  1. MCP: we register the Context7 MCP server and the agent calls the documentation tools natively
  2. CLI + skill: we install a skill that guides the agent to use the ctx7 CLI commands, with no MCP needed

In this article we’ll see how to install it both ways. Personally I’m very happy with the MCP approach.

Connecting Context7 via MCP

Let’s start with the approach I prefer: the MCP server. The fastest way to set everything up is the setup command (it needs Node.js 18+):

ShellScript
npx ctx7 setup

The command authenticates via OAuth (with the device flow: it shows us a link and a code to open on any device, so it works on remote machines over SSH too), generates an API key and installs the configuration. During setup we pick the MCP mode, and with the --claude flag (or whichever provider you prefer) we install it straight into the directory of the agent we care about.

If you prefer to configure things by hand, the remote server is available at https://mcp.context7.com/mcp and takes the API key in the Authorization: Bearer <API_KEY> header. Every client has its own configuration format: the official guide covers more than 30 clients. There’s also the @upstash/context7-mcp package if you want to run the server locally through npx.

Once connected, the server exposes two tools:

ToolWhat it does
resolve-library-idturns a library name (e.g., “next.js”) into a Context7-compatible ID (e.g., /vercel/next.js)
query-docsfetches a library’s documentation starting from the ID and the question

Note: for those on Claude Code there’s also a dedicated plugin that installs skills, agents and commands on top of the MCP server:

Bash
/plugin marketplace add upstash/context7
/plugin install context7@context7-marketplace

The plugin reads the API key from the CONTEXT7_API_KEY environment variable; if we don’t set it, it still works, but it goes through the anonymous tier, which has lower limits. If you haven’t installed Claude Code yet, I covered it in this article.

Using it with the CLI and a skill

The CLI + skill mode is the most interesting new option: no MCP server has to be running. The setup installs a skill that tells the agent when and how to use the ctx7 CLI, which offers two commands mirroring the MCP tools:

Bash
# searches for a library in the index and returns the IDs
ctx7 library next.js "middleware"

# fetches the documentation starting from the ID
ctx7 docs /vercel/next.js "app router setup"

The handy part is that the skill fires on its own: when we ask a question about a language, a framework or a library, the agent notices that documentation can help and calls Context7 without us having to ask.

The Claude Code plugin brings two extra tools:

  • the /context7:docs <library> [question] command to query the documentation by hand (e.g., /context7:docs prisma relations)
  • the docs-researcher agent: a subagent that runs the documentation search in a separate context and returns only the answer. Handy when we’re in the middle of a long task and don’t want to pollute the main context with tool calls

How to get the most out of it

Even though it’s already useful simply because we produce code aligned with the latest version, there are a few tricks that can help us get more out of Context7:

  • Version in the prompt: by naming the version (“How do I configure middleware in Next.js 14?”) Context7 matches the documentation of the corresponding version and avoids having to work it out from the project.
  • A rule in the project: after installing it I always add a rule in the AGENT.md or CLAUDE.md file saying “Always use Context7 when you need library or API documentation”, so the agent does it on its own without us having to spell it out.

Something I really appreciate on the privacy side (and it’s not a given at all) is that only the search query and the library name travel to the Context7 servers, not our code and not the conversation.

Is it free or not?

Yes, for individual use on public libraries it’s free, though with limits tied to the number of calls per month. For more details I’ll point you to the page with the pricing details.

We can use Context7 without an API key too, anonymously, but with lower rate limits: the key is free (you generate it from the dashboard) and it’s always worth having

The limit of 1,000 calls a month (the limit in place when I wrote this article) is more than enough for personal use and I’ve never gone over it myself: every question from the agent usually burns one or two calls (resolution + query). Once you hit the limit you get blocked, but you’re given 20 bonus calls a day until the month resets

Private repositories are limited to paid plans (and this gets very interesting in enterprise settings): if you want to index the documentation of your internal libraries you’ll need the Pro plan. All the details are on the plans page.

I usually set up two accounts (API keys): a personal one and one I use in work contexts.

Conclusions

It’s more and more clear that the quality of the output an agent generates doesn’t depend on the model alone, but also on the harness and the tools it has at hand: Context7 is a really useful tool that improves the code produced, feeding it documentation that’s always up to date.

My advice is to start from the free plan with whichever mode you prefer (MCP if you already have other servers configured, CLI + skill if you want the lighter option) and add a rule in the project: from there on you forget it exists and it keeps improving the quality of the output.

Personally I’ve noticed a huge difference on open source or less “capable” models, while with models like Sonnet 5, Opus, Fable, GPT Sole/Terra the generated code is most of the time aligned with the latest versions: these highly capable models probably already have a similar mechanism behind the scenes.

Thanks for reading, and stay tuned for more!

Share this article
Shareable URL
Prev Post

Documenting a legacy project with Claude skills

Next Post

Agentic migration of my homelab

Read next

ChatGPT-5 is coming!

Back in February, Sam Altman hinted that the new model might drop this summer… and here we are!…