文档索引MCP
 ](https://nodejs.org/)  ](https://pnpm.io/)
用于访问和搜索库文档的通用MCP(模型上下文协议)服务器。使LLM代理能够使用高级文本排名算法检索和分析任何配置库的文档。
特性
- 多库支持:同时访问多个已配置库的文档
- 高级搜索:使用BM25排名算法进行基于关键字的文档检索,以获得精确的结果
- 智能文档处理:分析和处理带有令牌估计的降价文档
- 语义分块:将文档拆分为语义上有意义的块,以更好地进行上下文管理
- 许可证管理:LLM上下文窗口的高效令牌计数和管理
- 元数据抽取:自动提取文档结构和元数据(标题、代码块、表格)
- 基于类别的权重:基于文档类别和部分的智能排名
- 灵活的配置:支持多种搜索模式和可定制的关键字权重
- 使用TypeScript构建:全类型安全和全面的测试覆盖
安装
NPM
npm install -g package7-mcp史密瑟里
通过以下方式自动为任何客户端安装文档索引MCP服务器 史密瑟里:
npx -y @smithery/cli@latest install package7-mcp --client 可用客户端: cursor, claude, vscode, windsurf, cline, zed等等。
光标示例:
npx -y @smithery/cli@latest install package7-mcp --client cursor来源
# Install dependencies
pnpm install
# Build the project
pnpm build
# Run the server
pnpm startMCP客户端集成
文档索引MCP可以与支持模型上下文协议(MCP)的各种AI编码助手和IDE集成。
需求
- Node.js>=v18.0.0
- pnpm>=v8.0.0
- MCP兼容客户端(Cursor、Claude Code、VS Code、Windsurf等)
Install in Cursor
首选 Settings -> Cursor Settings -> MCP -> Add new global MCP server
将以下配置添加到您的 ~/.cursor/mcp.json 文件:
{
"mcpServers": {
"docs-index": {
"command": "npx",
"args": ["-y", "package7-mcp"]
}
}
}Install in Claude Code
运行此命令:
claude mcp add docs-index -- npx -y package7-mcpInstall in VS Code
将此添加到您的VS Code MCP配置文件中。看 VS代码MCP文档 了解更多信息。
"mcp": {
"servers": {
"docs-index": {
"type": "stdio",
"command": "npx",
"args": ["-y", "package7-mcp"]
}
}
}Install in Windsurf
将此添加到您的Windsurf MCP配置文件中:
{
"mcpServers": {
"docs-index": {
"command": "npx",
"args": ["-y", "package7-mcp"]
}
}
}Install in Cline
- 打开 克莱恩
- 点击汉堡菜单图标(☰)进入 MCP服务器 章节
- 选择 远程服务器 标签
- 点击 编辑配置 按钮
- 将文档索引添加到
mcpServers:
{
"mcpServers": {
"docs-index": {
"command": "npx",
"args": ["-y", "package7-mcp"]
}
}
}Install in Claude Desktop
打开Claude Desktop开发人员设置并编辑您的 claude_desktop_config.json 文件:
{
"mcpServers": {
"docs-index": {
"command": "npx",
"args": ["-y", "package7-mcp"]
}
}
}Install in Zed
将此添加到您的Zed settings.json:
{
"context_servers": {
"docs-index": {
"source": "custom",
"command": "npx",
"args": ["-y", "package7-mcp"]
}
}
}Install in Roo Code
将此添加到Roo Code MCP配置文件中:
{
"mcpServers": {
"docs-index": {
"command": "npx",
"args": ["-y", "package7-mcp"]
}
}
}Using with Bun
{
"mcpServers": {
"docs-index": {
"command": "bunx",
"args": ["-y", "package7-mcp"]
}
}
}用法
MCP服务器提供以下工具:
获取库列表
检索可用库及其元数据的列表。
参数: 无
退货:
{
"libraries": [
{
"id": "react",
"name": "React",
"version": "18.0.0",
"description": "A JavaScript library for building user interfaces"
}
]
}获取文档
使用BM25排名算法通过基于关键字的检索搜索图书馆文档。
参数:
{
"libraryId": "react",
"query": "hooks state management",
"limit": 10
}退货: 包含分数和元数据的文档数组:
{
"documents": [
{
"id": "doc-123",
"title": "Using the State Hook",
"content": "...",
"score": 0.95,
"metadata": {
"section": "Hooks",
"category": "Advanced"
}
}
]
}按id文档
按ID获取完整文档内容。
参数:
{
"documentId": "doc-123"
}退货:
{
"id": "doc-123",
"title": "Using the State Hook",
"content": "Complete document content...",
"metadata": {
"tokens": 1250,
"section": "Hooks"
}
}用法示例
示例1:搜索文档
在光标/克劳德代码中:
Search for React documentation about hooks and find examples of useState usage示例2:获取特定的库信息
在任何MCP客户端中:
What libraries are available and show me the latest React documentation示例3:分析代码模式
在光标/克劳德代码中:
I need to understand how to manage state in React.
Search the React documentation for state management patterns.建筑
该项目采用模块化架构:
- 常数/:配置常数和基本提示
- 文件/:文档处理逻辑
- 分流器/:Markdown解析和文档分块实用程序 - 解析器/:针对不同节点类型的专用解析器
- 存储库/:数据访问层和文档存储库
- 模式/:用于运行时类型验证的Zod模式
- 工具/:MCP工具实现
- server.ts:主服务器入口点
核心组件
- MarkdownSplitter:具有语义感知的智能标记文档拆分
- BM25计算器:搜索相关性的高级排名算法
- 令牌估计器:用于上下文管理的高效令牌计数
- 文档加载器:灵活的文档加载和缓存
- Chunk转换器:不同文档格式之间的转换
发展
设置
# Install dependencies
pnpm install
# Run in development mode (watch mode)
pnpm dev
# Type check
pnpm typecheck建筑
pnpm build代码质量
# Lint code
pnpm lint
# Fix linting issues
pnpm lint:fix
# Format code with Prettier
pnpm format测试
# Run all tests
pnpm test
# Run tests in watch mode
pnpm test:watch
# Generate coverage report
pnpm test:coverage该项目涵盖了以下方面的全面测试:
- 文档处理和解析
- BM25排名算法
- 代币估算
- 搜索功能
- 存储库操作
项目结构
src/
├── constants/ # Configuration constants and prompts
│ ├── base-prompt.ts # Base system prompts
│ ├── category.ts # Category definitions
│ ├── keyword-weight-config.ts # Search weight configuration
│ └── search-mode.ts # Search mode definitions
├── document/ # Document processing logic
│ ├── splitter/ # Markdown splitting utilities
│ │ ├── markdown-splitter.ts # Main splitter
│ │ ├── parser/ # Node-type specific parsers
│ │ └── extractMetadata.ts # Metadata extraction
│ ├── token-estimator.ts # Token counting
│ ├── document-loader.ts # Document loading
│ ├── chunk-converter.ts # Format conversion
│ └── __test__/ # Document tests
├── repository/ # Data access layer
│ ├── docs.repository.ts # Document repository
│ └── createDocsRepository.ts # Factory function
├── schema/ # Zod schemas
│ └── get-document-schema.ts # Request schemas
├── tool/ # MCP tool implementations
│ └── tools.ts # Tool definitions
└── server.ts # Main server entry point配置
搜索模式
服务器支持通过常量配置的多种搜索模式:
- BM25:高级相关性排名(默认)
- 关键词:简单的关键字匹配
- 语义:上下文感知搜索
类别权重
文档可以按类别加权以获得更好的排名:
const categoryWeights = {
'Getting Started': 1.2,
'API': 1.0,
'Examples': 0.9
};脚本
pnpm build-使用TypeScript构建项目pnpm dev-手表开发模式pnpm start-启动MCP服务器pnpm test-运行所有测试pnpm test:watch-在监视模式下运行测试pnpm test:coverage-生成覆盖率报告pnpm lint-使用ESLint的Lint代码pnpm lint:fix-修复掉毛问题pnpm format-使用Prettier格式化代码pnpm typecheck-无建筑类型检查
Docker支持
构建Docker镜像
docker build -t package7-mcp .使用Docker运行
docker run -d -p 3000:3000 \
--name docs-index \
package7-mcpDocker编写示例
创建一个 docker-compose.yml:
version: '3.8'
services:
docs-index:
build: .
ports:
- "3000:3000"
environment:
- NODE_ENV=production
restart: unless-stopped
healthcheck:
test: ["CMD", "node", "-e", "require('http').get('http://localhost:3000/mcp', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})"]
interval: 30s
timeout: 3s
retries: 3
start_period: 5s使用Docker Compose运行:
docker-compose up -d贡献
欢迎投稿!请随时提交拉取请求。
许可证
麻省理工学院
作者
choesumin
