Context7

repository·master·Indexed 13 days ago

https://github.com/upstash/context7

A platform and Model Context Protocol (MCP) server that provides up-to-date, version-specific code documentation and examples directly into LLM prompts to prevent hallucinations. It includes a CLI for library resolution and documentation queries, and supports integration with AI coding agents such as Cursor, Claude Code, VS Code, and Devin Desktop.

Tokens
115.8K
Snippets
370
Records
602
Agent score
98%

What's inside Context7

  1. Overview of the Context7 Agent Plugin

    master

    The Context7 Agent Plugin is a portable Agent Plugin (spec 1.0.0) designed to provide AI coding assistants with current, version-specific library documentation.

    Instead of relying on potentially stale training data, the plugin uses the Context7 MCP server to fetch real documentation from source repositories at query time.

    Included Components:

    • MCP Server: A remote server over Streamable HTTP, authorized via OAuth (configured in mcp.json).
    • Skill: A documentation lookup trigger (located in skills/context7-mcp/) that activates when you ask the agent about a specific library.
  2. Overview of Context7 Enterprise

    master

    Context7 Enterprise is designed to convert internal documentation into structured, high-quality context optimized for LLMs. It serves three primary user groups:

    1. Human Developers: Accelerates onboarding and provides immediate API/service references within IDEs, reducing dependency on Slack/Teams.
    2. Coding Agents: Supplies accurate repository and documentation context to reduce hallucinations and enable autonomous generation, refactoring, and analysis within frameworks like LangGraph.
    3. Engineering Management: Provides a single source of truth by enforcing documentation rules, automatically parsing various formats (API, RST/Sphinx, MDX, OpenAPI), and detecting outdated content.

    Enterprise users can customize their setup by disabling query storage, using their own LLM provider for code extraction and private library ranking, or limiting context retrieval to privately indexed documentation only.

  3. Overview of Context7 Agentic Tools

    master
    Context7 provides tools and integrations that allow AI agents to access accurate, up-to-date library documentation during inference. This solves common AI issues such as outdated training data, hallucinated APIs, and version mismatches by enabling agents to fetch real-time documentation instead of relying on static knowledge.
  4. Overview of Context7 Security and Data Privacy

    master

    Context7 implements several security measures to protect user data and ensure privacy during documentation retrieval:

    • Prompt Privacy: Your original prompts remain with your AI assistant. Context7 only receives search queries formulated by the MCP client, which is instructed to strip sensitive data before transmission.
    • Infrastructure: Documentation is indexed within SOC 2 compliant infrastructure operated by Upstash.
    • API Security: API keys are encrypted, rate-limited, and can be rotated via the Upstash dashboard.
    • Enterprise Features: Enterprise customers have access to SSO (SAML, OAuth, OIDC) and dedicated audit trails.

    For full legal and compliance details, refer to the Context7 Addendum and Upstash Terms and Privacy Policy.

  5. Understand Context7 Infrastructure Security

    master
    Context7 is built on SOC 2 compliant infrastructure managed by Upstash. It utilizes industry-standard security controls, including Type II SOC 2 certified infrastructure, continuous monitoring, and regular security audits. The platform is protected by 24/7 infrastructure monitoring, automated security patching, DDoS protection, and redundant backups to ensure enterprise-grade reliability.
  6. Context7 compliance and open source transparency

    master

    Context7 maintains transparency through its open-source model and leverages Upstash's compliance framework:

    Open Source

    The Context7 MCP server is open source. The code is publicly available on GitHub for community auditing and contribution.

    • Repository: github.com/upstash/context7

    Compliance Certifications

    Context7 benefits from Upstash's existing compliance certifications:

    • SOC 2 Type II
    • GDPR compliant
    • ISO 27001 (currently in progress)
  7. Available Context7 Integrations

    master

    Context7 can be integrated into your workflows via several different interfaces:

    • Vercel AI SDK: Use generateText, streamText, or the pre-built Context7Agent for automatic documentation lookup.
    • TypeScript SDK: Call Context7 directly from any TypeScript or Node.js application.
    • MCP Server: Connect the Context7 Model Context Protocol (MCP) server to any compatible agent or editor.
  8. Context7 Plugin for Cursor Overview

    master

    The Context7 Plugin for Cursor addresses the issue of outdated training data and hallucinated APIs in AI coding assistants. It enables Cursor to fetch real-time, up-to-date documentation directly from source repositories instead of relying on stale model knowledge.

    The plugin provides several key components:

    • MCP Server: Connects Cursor to the Context7 documentation service.
    • Rules: An always-on use-context7 rule that prompts the agent to fetch documentation when it is uncertain about library APIs.
    • Skills: A context7-docs-lookup skill containing instructions for resolving libraries and fetching documentation.
    • Agents: A dedicated docs-researcher agent designed for focused documentation lookups.
  9. What is Context7 MCP and how to use it

    master

    Context7 MCP is a Model Context Protocol (MCP) server that provides up-to-date, version-specific documentation and code examples directly to your LLM. It prevents hallucinations and outdated code generation by fetching real-time data from the source.

    To use it, include use context7 in your prompt. This tells the LLM to invoke the MCP tool to fetch the necessary context for your request.

    Example Prompts:

    • Create a Next.js middleware that checks for a valid JWT in cookies and redirects unauthenticated users to /login. use context7
    • Configure a Cloudflare Worker script to cache JSON API responses for five minutes. use context7
    Create a Next.js middleware that checks for a valid JWT in cookies
    and redirects unauthenticated users to `/login`. use context7
  10. How Context7 tools work

    master

    The documentation lookup follows a two-step workflow orchestrated by the AI model:

    1. resolveLibraryId: Searches the Context7 database to find the correct library ID for a query (e.g., converting "react" to /reactjs/react.dev).
    2. queryDocs: Uses the resolved library ID and the user's query to fetch specific, relevant documentation content.

    This allows the model to fetch current documentation on-demand rather than relying on potentially outdated training data.

  11. How Context7 detects prompt injection and malicious content

    master

    Context7 uses a layered malicious content detection system to ensure that documentation retrieved from public or private sources is safe for human developers and AI coding agents to consume. The system includes:

    • Robust Detection: Uses a specialized classifier tailored for Context7 to identify prompt injection attempts and malware-related patterns.
    • Targeted Validation: Suspicious content undergoes additional validation checks.
    • Continuous Monitoring: Flagged content is tracked and reviewed continuously.
    • Regular Updates: Detection logic is updated frequently to defend against evolving attack methods and new injection techniques.
  12. Scale Context7 On-Premise horizontally

    master

    By default, Context7 On-Premise runs as a single container using SQLite and LanceDB. To scale horizontally with multiple replicas behind a load balancer, you must move state to an external PostgreSQL database with the pgvector extension.

    Once DATABASE_URL is configured, every replica becomes stateless and interchangeable. Replicas coordinate via Postgres to pull indexing jobs from a shared queue and use Postgres locks for singleton tasks (like backups or GitOps sync). Adding replicas increases both query capacity and indexing throughput simultaneously.

    # Architecture Overview
    Clients -> Load Balancer -> Multiple Replicas -> PostgreSQL + pgvector