How to Add Your Library to Context7 for AI-Powered Documentation
To add your library to Context7, submit your repository URL via the web form at context7.com/add-library or add a context7.json configuration file to your repository root, then optionally claim ownership to manage settings through a web admin panel.
Context7 indexes library source trees and serves up-to-date documentation to AI agents via the MCP (Model Context Protocol) server. Adding your library enables AI coding assistants like Cursor and Claude Code to retrieve accurate, current API references using simple slash syntax. This guide walks through the submission process using the upstash/context7 repository configuration options and underlying SDK architecture.
Submitting Your Library via the Web Interface
The fastest way to add your library is through the public submission form. According to the documentation in docs/adding-libraries.mdx, this process clones your repository, parses the documentation, and generates a Context7-compatible library ID.
- Navigate to https://context7.com/add-library?tab=github.
- Paste your GitHub repository URL (e.g.,
https://github.com/your-org/your-lib). - Optionally specify folders to include or exclude from indexing.
- Submit the form.
Context7 will create a library ID formatted as /your-org/your-lib that AI agents can reference immediately.
Advanced Configuration with context7.json
For granular control over indexing behavior, add a context7.json file to the root of your repository. This file functions like a "robots.txt" for Context7, defining include patterns, exclusions, and AI-specific guidance rules.
Example context7.json Configuration
{
"$schema": "https://context7.com/schema/context7.json",
"projectTitle": "My Awesome Library",
"description": "A tiny utility for handling dates",
"folders": [],
"excludeFolders": ["test"],
"excludeFiles": ["CHANGELOG.md"],
"rules": [
"Prefer the `formatDate` helper over legacy functions",
"Do not use the internal `devOnly` flag in production"
],
"previousVersions": [
{ "tag": "v1.0.0" },
{ "tag": "v1.1.0" }
]
}
Key Configuration Fields
The schema defined in docs/adding-libraries.mdx supports the following fields:
projectTitle: Display name shown in the Context7 library catalog.description: Short description used when the LLM cannot infer one.folders: Array of specific paths to include; empty array scans the entire repository.excludeFolders/excludeFiles: Glob patterns to skip during parsing (e.g.,node_modules,*.test).rules: Guidance strings that AI agents surface when answering queries about your library.previousVersions/branchVersions: Historical tags or branches to include in search indexes.
Claiming Ownership for Admin Access
If you own the library, you can claim it on Context7 to unlock additional capabilities. The claiming process, documented in the Library Owners section of docs/adding-libraries.mdx, provides:
- A web admin panel for editing configuration without committing changes to the repository.
- Team collaboration tools for inviting members and managing versions.
- Higher rate limits for documentation refreshes.
How AI Agents Retrieve Your Documentation
Once indexed, AI agents interact with your library through two primary tools implemented in the upstash/context7 repository:
-
Library Resolution: The
resolve-library-idtool (source:packages/tools-ai-sdk/src/tools/resolve-library-id.ts) executesclient.searchLibrary(query, libraryName)to map a plain library name to a Context7-compatible ID. -
Documentation Retrieval: The
query-docstool (source:packages/tools-ai-sdk/src/tools/query-docs.ts) invokesclient.getContext(query, libraryId)to fetch relevant documentation snippets.
The underlying SDK implementation in packages/sdk/src/client.ts exposes these methods to the AI tools, while packages/sdk/src/commands/search-library/index.ts and packages/sdk/src/commands/get-context/index.ts handle the HTTP requests to Context7's endpoints.
Implementation Examples
Programmatic Library Search
The following TypeScript example demonstrates how the SDK resolves library IDs using the Context7 class from packages/sdk/src/client.ts:
import { Context7 } from '@upstash/context7-sdk';
// Initialize the SDK – API key is read from CONTEXT7_API_KEY env var
const client = new Context7();
// Resolve the library ID for "react"
const libraries = await client.searchLibrary(
"React component library", // user query for relevance ranking
"react",
{ type: "txt" } // plain-text output for debugging
);
console.log(libraries); // -> array of library objects or formatted text
Adding context7.json to Your Repository
# Inside your library repo root
cat <<'EOF' > context7.json
{
"$schema": "https://context7.com/schema/context7.json",
"projectTitle": "My Library",
"description": "Utilities for XYZ",
"excludeFolders": ["examples", "benchmarks"],
"rules": ["Prefer async APIs", "Do not use deprecated `oldMethod`"]
}
EOF
git add context7.json && git commit -m "Add Context7 config"
git push origin main
After pushing, Context7 will re-crawl the repository and apply the new rules to AI-generated answers.
Querying Your Library in LLM Prompts
Once indexed, reference your library in any AI-powered coding assistant using slash syntax:
Generate a TypeScript function that parses ISO dates using the date-utils library. use library /my-org/date-utils
The LLM automatically calls the resolution and query tools to retrieve the latest API surface from your indexed documentation.
Summary
- Submit your library via https://context7.com/add-library or by adding a
context7.jsonfile to your repository root. - Configure indexing using the
context7.jsonschema to include specific folders, exclude test files, and provide AI guidance rules. - Claim ownership to access the web admin panel and higher refresh rate limits.
- AI integration works through the
resolve-library-idandquery-docstools inpackages/tools-ai-sdk/src/tools/, which utilize the SDK client inpackages/sdk/src/client.ts. - Reference syntax uses the format
/owner/repoin LLM prompts to fetch up-to-date documentation.
Frequently Asked Questions
What file format does Context7 use for configuration?
Context7 uses a JSON configuration file named context7.json placed in the repository root. The schema is available at https://context7.com/schema/context7.json and allows you to define include patterns, exclusions, and AI-specific rules as documented in docs/adding-libraries.mdx.
How long does it take for my library to be indexed after submission?
Context7 typically clones and parses your repository within minutes of submission via the web form or after detecting a context7.json file push. The exact timing depends on repository size and current system load.
Can I exclude specific files or folders from being indexed?
Yes. In your context7.json file, use the excludeFolders and excludeFiles fields to specify glob patterns for paths you want to skip, such as ["test", "node_modules"] or ["*.test.ts", "CHANGELOG.md"].
Do I need to claim ownership to add my library to Context7?
No, claiming ownership is optional. Anyone can submit a public repository to Context7. However, claiming ownership (available for repository maintainers) provides a web admin panel for configuration management and higher rate limits for documentation refreshes.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →