上下文中心mcp
本地第一台MCP服务器 .context/ 将markdown文件文件夹放入AI编码代理的可搜索知识层。
- 用markdown写领域知识,用git保存
- 在本地对其进行索引以实现快速检索
- 将其作为MCP工具公开给Claude Code、Copilot和其他MCP客户端
降价是真理的源泉。SQLite只是一个本地运行时索引——不要提交它。
快速启动
# 1. Scaffold the .context/ folder
npx context-hub-mcp init
# 2. Build the local index
npx context-hub-mcp reindex
# 3. Generate MCP client config
npx context-hub-mcp config --target claude-code --cwd /absolute/path/to/project将生成的JSON粘贴到MCP客户端配置中。然后,客户端将调用 serve 自动运行——您不需要手动运行它。
.上下文/结构
.context/
├── schema.md ← authoring conventions
├── domains/ ← business rules, workflows, state machines
├── integrations/ ← third-party APIs, auth, webhooks
└── pitfalls/ ← gotchas, lessons learned, failure modes写作知识
每个文档都需要YAML frontmatter:
---
title: Payment Rules
domain: payments
tags: [payments, line-pay]
last_verified: 2026-03-28
confidence: high
---
# Payment Rules
## Key Files
- `src/payments/service.ts` - entrypoint
## Payment State Machine
stateDiagram-v2 pending --> paid
领域: title, domain, tags, last_verified, confidence (high / medium / low), related (相关文档路径的可选列表)
使用 Key Files 源代码引用和状态机标题的部分将进行结构化解析。
这 related 字段接受相对于的路径 .context/:
related:
- integrations/stripe-webhooks.md
- pitfalls/payment-idempotency.md使用Claude代码导入文档
如果你使用Claude Code,该仓库包括 /import_context 命令,用于将任何URL、wiki或规范转换为格式正确的 .context/ 文件:
/import_context https://stripe.com/docs/webhooks
/import_context the spec at ./docs/payment-rules.mdClaude将获取源代码,提取相关知识,选择正确的子目录,并使用正确的frontmatter编写文件。跑 npx context-hub-mcp reindex 之后更新索引。
MCP工具
| 工具 | 目的 |
|---|---|
list_domains | 发现可用的知识领域 |
search_context | 在索引文档中进行全文搜索 |
get_context | 阅读特定文档 |
get_context_structured | 将文档作为结构化数据读取(keyFiles、stateMachines、陷阱、章节、相关) |
get_pitfalls | 列出陷阱,可选择按域过滤 |
list_tags | 列出所有具有文档计数的唯一标签;可选的 domain 过滤器 |
get_stale_docs | 列出旧的或丢失的文档 last_verified,或 confidence: low |
get_related | 返回与给定路径相关的文档(双向,深度1或2) |
annotate_context | 在过时或缺失的文档上留下注释 |
rate_context | 标记文档是否有用 |
list_annotations | 查看累积注释 |
reindex_context | 强制重新构建索引 |
search_context--筛选参数
除了a query 字符串, search_context 接受可选筛选器:
| 参数 | 类型 | 描述 |
|---|---|---|
tags | string[] | OR match:返回具有任何列出标签的文档 |
confidence | string | 最低置信水平(low, medium, high) |
verified_after | string | 仅包含以下内容的文档 last_verified 在此日期或之后(YYYY-MM-DD) |
verified_before | string | 仅包含以下内容的文档 last_verified 在此日期或之前(YYYY-MM-DD) |
get_sale_docs--参数
| 参数 | 类型 | 默认值 | 描述 |
|---|---|---|---|
domain | string | -- | 限制到特定域 |
days_threshold | number | 90 | 在这几天内未验证的文档被视为过时 |
limit | number | -- | 限制结果数量 |
get_related--参数
| 参数 | 类型 | 描述 | |
|---|---|---|---|
path | string | 源文档的路径(相对于 .context/) | |
depth | `1 \ | 2` | 1 返回直接链接的文档; 2 也遵循他们的链接 |
命令行界面
npx context-hub-mcp init # scaffold .context/ workspace
npx context-hub-mcp add # create a new context document with frontmatter
npx context-hub-mcp reindex # rebuild the local SQLite index
npx context-hub-mcp doctor # inspect workspace health
npx context-hub-mcp config # generate MCP client config JSON
npx context-hub-mcp serve # run the MCP server (usually invoked by the client)使用以下命令运行任何命令 --help 对于可用的标志。
添加--标志
npx context-hub-mcp add [--domain ] [--title ] [--tags ] \
[--confidence high|medium|low] [--template domain|integration|pitfall] \
[--no-edit]| 标志 | 描述 |
|---|---|
--domain | 用于放置文件的域子文件夹(例如。 payments) |
--title | 文档标题(用于文件名和封面) |
--tags | 以逗号分隔的标签列表 |
--confidence | 初始置信水平;默认为 medium |
--template | 初学者模板: domain, integration,或 pitfall |
--no-edit | 跳过在中打开文件 $EDITOR 创作后 |
客户端设置
克劳德代码
npx context-hub-mcp config --target claude-code --cwd /absolute/path/to/projectExample output
{
"mcpServers": {
"context-hub": {
"command": "npx",
"args": ["-y", "context-hub-mcp@latest", "serve", "--cwd", "/absolute/path/to/project"]
}
}
}GitHub Copilot
npx context-hub-mcp config --target copilot --cwd /absolute/path/to/projectExample output
{
"mcpServers": {
"context-hub": {
"type": "local",
"command": "npx",
"args": ["-y", "context-hub-mcp@latest", "serve", "--cwd", "/absolute/path/to/project"]
}
}
}另请参见: examples/claude-code.mcp.json, examples/copilot.mcp.json
配置
context-hub.config.json 是可选的。默认值:
{
"contextDir": ".context",
"dbPath": ".context/context_hub.db",
"watch": true,
"reindexDebounceMs": 250,
"includeGlobs": ["**/*.md"],
"excludeGlobs": ["**/.git/**"]
}CLI标志覆盖配置文件值。相对路径解析自 cwd.
故障排除
搜索未返回任何结果 --奔跑 npx context-hub-mcp reindex那么 npx context-hub-mcp doctor常见原因:缺失 .context/,格式错误的frontmatter,文件位于索引球体之外。
文档解析失败 --检查所有5个frontmatter字段是否存在且有效。
数据库文件以git格式显示 --确保 .context/.gitignore 包含 context_hub.db, context_hub.db-shm, context_hub.db-wal.
客户端无法连接 --验证客户端是否使用stdio MCP --cwd 路径正确,并且项目已被索引至少一次。
许可证
麻省理工学院
