Context42
Your coding standards, always in context.
An open-source MCP server that gives your AI assistant semantic search over your personal documentation and coding guidelines. 100% offline.
Website · Documentation · Issues
______________________________________________________________________
为什么是Context42?
你的AI助手不知道你团队的编码惯例。每个会话都从零开始——你的标准丢失了,文档分散在wiki和README中,将整个文档粘贴到提示中会浪费令牌。
Context42通过在本地为您的文档建立索引,并通过以下方式将最相关的块提供给您的AI助手来解决这个问题 主控程序 --自动、语义和 没有任何数据离开您的机器.
运作原理
- 添加 将文档目录作为源
- 索引 --Context42将文档分块并创建局部向量嵌入
- 商店 --矢量保存在LanceDB中的本地
- 服务 --您的AI助手通过MCP查询相关内容,按优先级加权
安装
需要 Python 3.11+
# Using pipx (recommended)
pipx install context42-io
# Using uv
uvx context42-io
# Using pip
pip install context42-io快速开始
# 1. Add your documentation
c42 add ~/my-coding-standards --name standards --priority 0.9
# 2. Index the content
c42 index
# 3. Start the MCP server
c42 serveClaude桌面集成
添加到您的Claude Desktop配置文件中:
| 平台 | 路径 |
|---|---|
| Linux | ~/.config/claude/claude_desktop_config.json |
| macOS | ~/Library/Application Support/Claude/claude_desktop_config.json |
| 窗户 | %APPDATA%\Claude\claude_desktop_config.json |
{
"mcpServers": {
"context42": {
"command": "c42",
"args": ["serve"]
}
}
}添加配置后重新启动Claude Desktop。
CLI参考
添加和索引源
c42 add
--name # Add a documentation source
c42 add
--name --priority 0.9 # Add with priority (0.1–1.0)
c42 add
--name --exclude "*.log,tmp/*" # Exclude file patterns
c42 index # Index all pending sources管理资源
c42 list # List all sources with status
c42 set-priority # Change source priority
c42 remove # Remove a source
c42 status # Show index statistics搜索和服务
c42 search "error handling" # Search from the CLI
c42 serve # Start the MCP server
c42 --help # Show all available commands优先级系统
为您的个人指示设置更高的优先级,使其优先于参考文档:
# Your rules — highest weight
c42 add ~/my-standards --name standards --priority 1.0
# Team guidelines — medium weight
c42 add ~/team-docs --name team --priority 0.7
# Reference docs — lower weight
c42 add ~/library-docs --name reference --priority 0.4搜索结果按优先级加权,因此您的个人偏好始终显示在第一位。
支持格式
| 格式 | 扩展名 | 注释 |
|---|---|---|
| Markdown | .md | 完全支持CommonMark |
| 重新结构化文本 | .rst | Sphinx兼容 |
计划更多格式--请参阅 路线图.
MCP工具
Context42公开了一个 search 通过MCP工具:
search(query: string, top_k?: int) → SearchResult[]每个结果包括:
text--匹配的内容块source--来源名称file--文件的相对路径score--相似性得分(0-1,越高=相关性越高)priority--源优先级权重is_priority—true如果源的优先级≥0.8
配置
Context42开箱即用,无需配置。以下所有设置都是可选的:
| 变量 | 默认值 | 描述 |
|---|---|---|
C42_EMBEDDING_MODEL | BAAI/bge-small-en-v1.5 | 句子变换器嵌入模型 |
C42_CHUNK_SIZE | 500 | 每块字符数 |
C42_BATCH_SIZE | 50 | 每个索引批次的块数 |
C42_DATA_DIR | 平台默认 | 数据存储目录 |
HF_TOKEN | -- | 拥抱Face代币,加快模型下载速度 |
# Example: use a different embedding model
export C42_EMBEDDING_MODEL="BAAI/bge-base-en-v1.5"
# Optional: set HuggingFace token for faster downloads
export HF_TOKEN="hf_your_token_here"注: 更改嵌入模型需要重新索引所有源(c42 index).获取您的HF代币:https://huggingface.co/settings/tokens
数据存储
| 平台 | 路径 |
|---|---|
| Linux | ~/.local/share/context42/ |
| macOS | ~/Library/Application Support/context42/ |
| 窗户 | %LOCALAPPDATA%\context42\ |
安全与隐私
Context42在本地处理所有内容。你的代码和文档永远不会离开你的机器。
- 零数据传输 --无出站网络呼叫
- 仅本地嵌入 --AI模型在CPU上运行,不向外部API发送令牌
- 无遥测 --没有分析,没有事故报告,没有电话回家行为
- 工作气隙 --初始设置后,不需要互联网连接
了解更多信息,请访问 上下文42.io.
路线图
- \[ \] Git克隆源 --将任何Git存储库添加为源
- \[ \] 文件监视器 --磁盘上文件更改时自动重新索引
- \[ \] Git同步 --检测新提交并自动重新索引
查看所有计划中的功能并建议新功能 .
贡献
欢迎投稿!请随意:
许可证
麻省理工学院
