Announcing CIMD support for MCP Client registration
Learn more

Context7 MCP or Context7 API? A Decision Framework for AI Agents

Saif Ali Shaik
Founding Developer Advocate

TL;DR

  • Context7 MCP and the Context7 API cover the same retrieval core, resolve-library-id and query-docs, but only the API adds index management: submitting GitHub, GitLab, Bitbucket, OpenAPI, website, Confluence, and Notion sources, refreshing them, and reading usage metrics.
  • Both paths authenticate with the same Context7 API key (the ctx7sk- prefix). The remote MCP server adds OAuth 2.0 as an option for interactive clients; the API is key-only. Auth barely diverges here, which is unusual for this series.
  • The MCP server ships two LLM-ready tools so your agent binds them without writing schemas. The API gives you response controls, version pinning, and library management, at the cost of writing and maintaining the schemas yourself.
  • Context7 is a shared documentation service, not a per-user SaaS. The credential risk is key custody, per-caller attribution, and one shared rate-limit budget, not the usual N-per-user OAuth token sprawl, unless tenants bring their own Context7 keys.
  • Scalekit vaults the ctx7sk- key, resolves it per identifier at call time, and logs every tool call, so the key never enters your agent runtime and the MCP-vs-API choice does not change your auth infrastructure.

Your agent needs up-to-date library documentation, and you have picked Context7 to supply it. Context7 ships two ways in: an official hosted MCP server at a single endpoint, and a REST API your pipeline can call directly. They read from the same documentation index, but they are not the same object. They expose different surfaces, put you on slightly different auth paths, and hand you different work to own in production. Here is how to pick.

What Context7 MCP and Context7 API actually are

Context7 is Upstash's documentation-retrieval platform: it fetches version-specific docs and code snippets straight from the source and injects them into an LLM's context. The MCP server code is open source under the MIT license; the backend, parsing, and crawling engines are proprietary. Two access paths sit on top of that index.

Context7 MCP

The official Context7 MCP server is hosted at https://mcp.context7.com/mcp over Streamable HTTP, with an SSE variant and a local npx @upstash/context7-mcp option. It exposes exactly two tools: resolve-library-id, which maps a library name to a Context7 ID, and query-docs, which returns version-specific documentation for that ID. Authentication is an API key passed as an Authorization: Bearer header, and the remote server also supports OAuth 2.0 for MCP clients. See the official Context7 repository for the tool contract and client setup.

The Context7 API

The Context7 API is a REST interface rooted at https://context7.com/api/v2/. GET /libs/search mirrors library resolution and GET /context mirrors document retrieval, so the read core matches the MCP server. Beyond that, the API exposes what the MCP server does not: POST /add/* endpoints for GitHub, GitLab, Bitbucket, OpenAPI specs, websites, llms.txt, Confluence, and Notion, plus refresh, usage metrics, and teamspace policy endpoints. Auth is the same ctx7sk- key as a Bearer token. The full surface is in the Context7 API guide.

Comparing them where it matters for agents

The two paths overlap on retrieval and diverge on everything operational. For a coding agent that only needs current docs, they are close to interchangeable. For a pipeline that curates its own documentation index, they are not.

What your agent can actually do

The MCP server is the retrieval slice; the API is retrieval plus library management. The table below maps the actions that matter for agent use cases.

Capability
Context7 MCP
Context7 API
Resolve a library name to a Context7 ID
Yes (resolve-library-id)
Yes (GET /libs/search)
Retrieve version-specific docs and snippets
Yes (query-docs)
Yes (GET /context)
Pin a specific library version
Yes
Yes
Control response type, reranking, token budget
Limited
Yes (query params)
Add a GitHub, GitLab, or Bitbucket repo
No
Yes (POST /add/repo/*)
Add an OpenAPI spec, website, or llms.txt
No
Yes (POST /add/*)
Add Confluence or Notion sources
No
Yes (POST /add/*)
Refresh a library's documentation
No
Yes (refresh endpoint)
Read library usage metrics
No
Yes (GET /libs/metrics)
Read or update teamspace policies
No
Yes (GET/PATCH /policies)
LLM-ready tool schemas to bind directly
Yes
No, you write them

Where the gap actually bites

The gap is not about retrieval quality; both paths hit the same index. It is about ownership of the index. Anything that curates documentation, adding a private repo, submitting an OpenAPI spec, refreshing a stale library, or reading usage metrics, lives only in the API. An agent built on the MCP server can read the world's docs but cannot add your own. That is a design boundary, not a tool that ships next month.

The auth path each one puts you on

Here Context7 breaks the usual pattern. Both the MCP server and the API authenticate with the same key: a ctx7sk- secret from the Context7 dashboard, sent as Authorization: Bearer. There is no bot-versus-user token split to reason about.

The one divergence is OAuth. The remote MCP server supports OAuth 2.0 following the MCP OAuth specification, which lets an interactive client have the end user sign in rather than paste a key. The API is key-only. Without any key, requests fall into a low, shared anonymous rate-limit pool; a key grants dedicated quota by plan. For agents, the practical takeaway is simple: whichever path you choose, a ctx7sk- key is the credential you have to protect.

What you own in production

On the MCP path, Upstash hosts the server, maintains the two tool schemas, and owns the crawl and index. You own key custody, rate-limit handling, and caching. On the API path, you own the resolve-then-context two-step, request construction, error handling, and the LLM tool schemas if an agent calls it.

Both paths return 429 with Retry-After and RateLimit-* headers, so exponential backoff is your job either way, and the docs recommend caching responses for hours since documentation changes infrequently. Watch the maintenance trajectory too: the MCP tool set has already been renamed across versions, so pin the package and re-discover tools; the API is versioned at v2 and the old api.context7.com host has been retired. Agent tool observability and rate-limit backoff patterns go hand in hand when running tools reliably in production.

When to use MCP, when to use the API

Both lists below are specific to Context7, not generic MCP advice. Match the path to what your agent is actually doing.

Use Context7 MCP when:

  • Your agent is an interactive coding assistant, Cursor, Claude Code, or a VS Code agent, where in-prompt "use context7" retrieval is the whole point.
  • You want the two tools in LLM-ready form without writing or maintaining schemas.
  • Read-only documentation retrieval is all the agent needs.
  • You want end users to sign in via OAuth instead of distributing a shared key.

Use the Context7 API when:

  • You curate the index: adding private repos, OpenAPI specs, websites, or Confluence and Notion sources, then refreshing them.
  • You need response controls, reranking, type, and version pinning, inside a deterministic pipeline.
  • You run headless retrieval and already own your tool schemas.
  • You need usage metrics or teamspace policy management the MCP tools do not expose.

Connecting Context7 through Scalekit

Scalekit ships a single Context7 connector, and it resolves the part both direct paths leave to you: where the ctx7sk- key lives and who is allowed to call which tool. The Context7 MCP connector docs cover the full setup; the shape is below.

One connector, API-key auth, two scoped tools

The connector is named context7mcp, authenticates with the Context7 API key, and exposes the two retrieval tools as context7mcp_resolve_library_id and context7mcp_query_docs. Because Context7 uses an API key rather than OAuth, you register the key once per identifier instead of running a browser consent flow. The credential is held in Scalekit's token vault and injected server side; it never reaches your agent runtime or the model context.

Set up the connected account in Python

A connected account links a user identifier in your system to a Context7 key. Create it once, from your own authenticated backend, using the Scalekit Python SDK.

import os from scalekit import ScalekitClient scalekit = ScalekitClient( env_url=os.environ["SCALEKIT_ENVIRONMENT_URL"], client_id=os.environ["SCALEKIT_CLIENT_ID"], client_secret=os.environ["SCALEKIT_CLIENT_SECRET"], ) actions = scalekit.actions # Context7 authenticates with an API key, not OAuth, so you store the key # once per identifier. It lives in Scalekit's vault, never in agent code. scalekit.connect.upsert_connected_account( connection_name="context7mcp", identifier="user_123", credentials={"api_key": "ctx7sk-..."}, )

Give a LangChain agent the scoped Context7 tools

Before the code, be precise about what happens. The agent does not load a Context7 catalog. actions.langchain.get_tools calls list_scoped_tools under the hood for one identifier and returns only the tools that identifier's connected account is authorized to call, each already bound to that identifier. You choose the surface; for a pure documentation agent, the two retrieval tools are the whole set.

from langchain.agents import create_agent CONTEXT7_CONNECTION = "context7mcp" # Discovery and scope: authorized tools for this identifier, bound to it. tools = actions.langchain.get_tools( identifier="user_123", connection_names=[CONTEXT7_CONNECTION], tool_names=["context7mcp_resolve_library_id", "context7mcp_query_docs"], page_size=50, ) agent = create_agent( model="anthropic:claude-sonnet-4-5", tools=tools, system_prompt=( "You answer coding questions using current library docs. " "Call context7mcp_resolve_library_id to turn a library name into a " "Context7 ID, then context7mcp_query_docs for version-specific docs. " "Do not answer from memory when a tool can confirm the API." ), ) result = agent.invoke({ "messages": [ {"role": "user", "content": "How do I set up middleware in Next.js 15?"} ] }) print(result["messages"][-1].content)

Execution runs inside the agent loop: the model decides which tool to call, the adapter executes it with the bound identifier through Scalekit, and the Context7 key never enters the exchange. The same connected-account pattern works with the Claude SDK, CrewAI, Google ADK, and Mastra.

What the scoping buys you

Context7 alone is only two tools, so this is not a tool-bloat story on its own. It becomes one the moment Context7 sits inside a multi-tool agent, next to GitHub, Slack, or Jira surfaces, where the aggregate tool count climbs. A pure retrieval agent can be scoped to context7mcp_query_docs alone, cutting the decision space to one tool. Surface reduction is the lever for tool-calling accuracy here; model upgrades help, but they are not the lever. For index management endpoints the connector does not wrap, you still call the Context7 API directly, with the same vaulted key.

The credential problem that exists on both paths

Both direct paths hand you a ctx7sk- key and stop there. Neither gives you a vault, per-caller attribution, or a revocation flow. Context7 is a shared service, so the failure mode is not the usual per-user OAuth sprawl; it is quieter and easier to ship by accident.

The shared-key failure mode

Drop one key into the agent runtime and it works in a demo. In production, that key ends up in environment dumps and logs, every caller draws down one shared rate-limit budget so a single runaway agent can 429 the whole product, and there is no way to attribute a call back to the user who triggered it. Rotating the key to cut off one bad actor rotates it for everyone.

When tenants bring their own Context7 keys

The picture changes for teams on Context7 plans that index private repositories or set teamspace policies. Now each tenant has its own ctx7sk- key, and you are back to the N-credential problem: N keys to store, attribute, and revoke independently. The token type never changed; the number of them did. This is the same multi-tenant credential problem explored in depth in how tool calling auth changes when you move from single-tenant to multi-tenant.

Where Scalekit fits

Scalekit's Context7 connector holds each key in the token vault, resolves the right one per identifier at call time, and never exposes it to agent code. Every execute_tool call is recorded with the identifier, the connected account, and an execution ID, so agent tool observability and downstream auth logs answer "what did this agent do for this user" as one query. For multi-tool and multi-tenant agents, Virtual MCP Servers expose only the Context7 tools you allow and mint a short-lived, per-user session token before each run, with no MCP server to deploy, host, or maintain.

Which one to build against

If your agent is an interactive coding assistant that just needs current docs, the MCP server is the faster route: two tools, hosted, LLM-ready, with OAuth available for end users. If your agent curates a documentation index, adding private sources, refreshing them, reading metrics, build against the API, because those actions live nowhere else.

The credential question is the same regardless of which you pick. One ctx7sk- key protects the whole path, and whether you run one shared key or one per tenant, custody, attribution, and revocation are infrastructure you own. That is the part worth solving once, so the MCP-vs-API decision never touches your auth layer again. Understanding credential ownership across agent tool-calling patterns is the first step to getting this right.

Keep building

Read the Context7 MCP connector docs or the Scalekit Context7 connector page to wire it up, and browse the full connector catalog to bundle Context7 with the rest of your agent's tools. If you are building a developer-facing agent, the DevOps assistant agent template is a working starting point, and pricing is usage-based with a free tier to start.

Building a Context7 agent and want a second pair of eyes on the auth model? Join the Scalekit Slack community, or use the talk to us page for immediate help.

No items found.
Agent
Auth Quickstart
On this page
Share this article
Agent
Auth Quickstart

Acquire enterprise customers with
zero upfront cost.

Every feature unlocked. No hidden fees.