PS

prism-shadow/context9

开发工具
30 stars 0 forks 质量 90 趋势 90

Your personal knowledge MCP engine. Up-to-date, local-first, low-hallucination.

概览

Up-to-date · Local-first · Low-hallucination https://github.com/user-attachments/assets/553ab8a2-5227-42fa-a8bd-692cd13c0b96 - 🎯 Up-to-date knowledge: Real-time knowledge synchronization and reduce AI agent hallucinations. - 🔐 Local-first: Fully open sourced and deploy on your own server, safely access your private knowledge. - ⚙️ Easy-to-use Web UI: Easily manage your repositories and API-key permissions through the Context9 Panel. is an MCP (Model Context Protocol) server. With local deployment, Context9 securely feeds agents with the most up-to-date documentation, reducing LLM hallucinations. Or you can specify the port on which Context9 runs. Visit http:// :8011/ to login to Context9 - Default username: ctx9-admin - Default password: 88888888 Remember to change the default password when you first log in to Context9.

README

Context9 - Bring Live Doc into Your Agent Context


https://github.com/user-attachments/assets/553ab8a2-5227-42fa-a8bd-692cd13c0b96

Why Context9?

  • 🎯 Up-to-date knowledge: Real-time knowledge synchronization and reduce AI agent hallucinations.
  • 🔐 Local-first: Fully open sourced and deploy on your own server, safely access your private knowledge.
  • ⚙️ Easy-to-use Web UI: Easily manage your repositories and API-key permissions through the Context9 Panel.

What Context9 Actually Does

Context9 (Context Mine) is an MCP (Model Context Protocol) server. With local deployment, Context9 securely feeds agents with the most up-to-date documentation, reducing LLM hallucinations.

Install Context9

Run Context9 server

docker run -d \
    --name context9 \
    -p 8011:8011 \
    --restart unless-stopped \
    ghcr.io/prism-shadow/context9:latest \
    python -m context9.server --github_sync_interval 600

Or you can specify the port on which Context9 runs.

docker run -d \
    --name context9 \
    -e CONTEXT9_PORT= \
    -p : \
    --restart unless-stopped \
    ghcr.io/prism-shadow/context9:latest \
    python -m context9.server --github_sync_interval 600

Configure Context9

Login to Context9

Visit http://:8011/ to login to Context9

  • Default username: ctx9-admin
  • Default password: 88888888

Remember to change the default password when you first log in to Context9.

Add repositories

Add the repositories you need in Context9 by filling in the repository owner, repository name, and branch.

  • For private repositories, you also need to provide a GitHub Token

Export & Import Repos using the Context9 template

  • Export Repos: You can click the Export Repos button to export the current repository configuration as a local template, making it easy to reuse later.
  • Import Repos: You can click the Import Repos button to import a Context9 template into your repository configuration. Context9 also provides several templates for reference and use.

Add API Keys

Generate an API key that can be used to access Context9.

After generating the API key, you need to configure which repositories the API key is allowed to access.

Test Context9 (Optional)

You can test your configured Context9 instance by simply entering the current Context9 Server IP and API key in the MCP Inspector.

Integrate Context9 with Agent

After deploying the Context9 service, you can seamlessly integrate both private and public real-time code documentation into your agents. You can connect to the Context9 MCP service using tools such as Cursor and Claude Code.

Install in Cursor

Go to: Settings ->Cursor Settings -> Tools & MCP -> Add a Custom MCP Server

Paste the configuration below into ~/.cursor/mcp.json. If you want to configure Context9 for a specific project only, create .cursor/mcp.json in the project directory and paste the configuration there.

{
  "mcpServers": {
    "Context9": {
      "url": "http://:8011/api/mcp/",
      "headers": {
        "Authorization": "Bearer "
      }
    }
  }
}

Install in Claude Code

Run the following command to add Context9 to Claude Code.

claude mcp add --transport http Context9 http://:8011/api/mcp/ --header "Authorization: Bearer "

Suggestions for Context9 Usage

To avoid adding extra prompts every time you use Context9, we recommend that you:

  • Use CLAUDE.md in Claude Code.
  • Use AGENTS.md for Cursor, CodeX and other agents.
  • Add rules in Cursor.

Use CLAUDE.md for Claude Code

Add a prompt to CLAUDE.md to enable Context9:

- Always retrieve required documentation via Context9

Use AGENT.md for Cursor, CodeX and other agents

Add rules to AGENTS.md, for example:

Rules:
- Always retrieve required documentation via Context9

Add Rule for Cursor

Go to: Setting -> Rules and Commands -> Add Rule

Rule example:

Always use Context9 MCP to obtain the necessary documentation, regardless of whether I explicitly ask for it.

Work with Context9

Set up entry documentation

To enable Context9 to correctly discover and index your repository documentation, each repository should provide a Spec document. By default, Context9 expects a file named spec.md at the root of the repository.

your-repo/
├── spec.md          ← Specification entry point
├── README.md
├── docs/
│   └── ...
└── ...

If you need to use a different filename or path, remember to update the repository configuration.

You do not need to think about MCP, indexing, or document resolution. Just maintain documentation links using normal repository-relative paths, exactly as you would for human readers.

Example in documentation.

## Related Documents
- [Detailed Guide](docs/detailed-guide.md)
- [API Reference](guides/api-reference.md)
- [FAQ](faq.md)

As long as these links are valid within the repository, Context9 will:

  • Discover the documents
  • Index them correctly
  • Make them available to AI agents in real time

Deploy Context9 from source

Configure Environment

Set the following environment variables (create a .env file or export them directly):

CTX9_API_KEY (Required): API key used for server authentication to access private resources. Specified by an administrator. Keep it random and confidential. GITHUB_TOKEN (Optional): Required when configuring private repositories in config.yaml. This is not limited to a GitHub personal access token—any organization-issued repository access token is supported, as long as it conforms to the GitHub API specification. CONTEXT9_PORT (Optional): Specifies the port number on which the Context9 MCP service runs. If not specified, it defaults to 8011.

An example of .env file. .env example

GITHUB_TOKEN=github_token CTX9_API_KEY=XXXXXXXXXXXXXXXX

Optional

CONTEXT9_PORT=8080

Launch Context9 server

Default:

Sync repos every 600 seconds (10 minutes)

Run server on port 8011

uv run python -m context9.server --config_file config.yaml

Sync repos every 60 seconds (1 minute)

uv run python -m context9.server --github_sync_interval 60 --config_file config.yaml

Run server on port 8080 (or define CONTEXT9_PORT in .env)

CONTEXT9_PORT=8080 uv run python -m context9.server --config_file config.yaml

Launch Context9 Server with Docker

You can also run Context9 using Docker. Context9 provides a ready-to-use Dockerfile.

The config.yaml file is included in the Docker image during the build process, so there is no need to provide it again when starting the container.

Build docker image

docker build -f docker/Dockerfile-cli -t context9:latest .

Run docker container

Change port mapping according to your .env

docker run -d
–name context9
-p 8011:8011
–env-file .env
–restart unless-stopped
context9:latest

License

Licensed under the Apache License, version 2.0. See LICENSE for details.

Acknowledge

This repo benefits from context7. Thanks to the authors and contributors for their excellent work and inspiration.

⭐ Star History

View this README on GitHub

安装

docker run -d \

配置

{ "mcpServers": { "Context9": { "url": "http://<server_ip>:8011/api/mcp/", "headers": { "Authorization": "Bearer <CTX9_API_KEY>" } } } }