分别启用和禁用 Claude Context Local MCP,测试 Claude Code 在项目概览生成任务上的性能和 token 消耗比较
Claude Context Local MCP 使模型从通读部分文档转变为语义检索,使 Claude Code 在更少 token 消耗的情况下,产出了更具技术深度和代码细节的项目概览,提升了效率。

总 oken 消耗降低了约 12.5%,交互产生的 Messages 上下文部分节省了约 27.75%。

实验细节

不使用 Claude Context Local

执行过程
> 介绍一下这个项目

● 我来帮你探索和介绍这个项目。让我先了解一下项目的结构和内容。

● Read(README.md)
  ⎿  Read 865 lines

● Read(pyproject.toml)
  ⎿  Read 165 lines

● Search(pattern: "*.py")
  ⎿  Found 100 files (ctrl+o to expand)

● 让我再查看项目的实际源代码结构:

● Bash(find /home/tully/Python_Project/mineru-demo -maxdepth 3 -type f -name "*.py" | grep -v
      ".venv" | head -30)
  ⎿  /home/tully/Python_Project/mineru-demo/demo/demo.py
     /home/tully/Python_Project/mineru-demo/projects/mineru_tianshu/start_all.py
     /home/tully/Python_Project/mineru-demo/projects/mineru_tianshu/task_scheduler.py
     … +27 lines (ctrl+o to expand)

● Bash(ls -la /home/tully/Python_Project/mineru-demo)
  ⎿  total 1340
     drwxrwxr-x 13 tully tully    4096 Dec 27 12:17 .
     drwxrwxr-x 11 tully tully    4096 Dec 26 11:40 ..
     … +24 lines (ctrl+o to expand)

● 现在让我看一下项目的核心源代码结构:

● Bash(tree -d -L 2 /home/tully/Python_Project/mineru-demo/mineru)
  ⎿  /home/tully/Python_Project/mineru-demo/mineru
     ├── backend
     │   ├── pipeline
     … +26 lines (ctrl+o to expand)
结果展示
● 好的,现在我对项目有了充分的了解。让我为用户介绍这个项目:

  MinerU 项目介绍

  根据我的分析,这是 MinerU (又名 magic-pdf) —— 一个功能强大的 PDF 文档智能解析工具,由 OpenDataLab 开发并开源。

  🎯 核心功能

  MinerU 能够将 PDF 文档转换为机器可读格式(如 Markdown、JSON),主要特点包括:

  📄 文档理解能力

  - 布局分析: 自动识别文档结构(标题、段落、列表等)
  - 多栏处理: 支持单栏、多栏和复杂排版
  - 阅读顺序: 智能识别人类阅读顺序
  - 结构保留: 保持原文档的层级关系

  🔍 内容提取

  - 文本识别: 支持 109 种语言的 OCR 识别
  - 公式解析: 自动识别并转换为 LaTeX 格式
  - 表格识别: 转换为 HTML 格式,支持复杂表格
  - 图像提取: 包括图片说明文字和脚注

  🚀 技术亮点

  双引擎架构:
  1. pipeline 后端 (准确率 82+)
    - 快速,无幻觉
    - 支持纯 CPU 运行
  2. vlm 后端 (准确率 90+) - MinerU2.5 多模态模型
    - 仅 1.2B 参数,性能超越 GPT-4o/Gemini 2.5 Pro
    - 支持多种加速方式: vLLM, LMDeploy, MLX(Apple Silicon)
    - 单 4090 显卡可达 10,000+ tokens/s 吞吐量

  💻 项目结构

  mineru-demo/
  ├── mineru/              # 核心源代码
  │   ├── backend/        # 解析后端 (pipeline/vlm)
  │   ├── cli/            # 命令行工具
  │   ├── data/           # 数据读写模块
  │   ├── model/          # AI 模型 (OCR/表格/公式等)
  │   └── utils/          # 工具函数
  ├── demo/               # 示例代码
  ├── projects/           # 扩展项目
  └── tests/              # 测试代码

  🌟 应用场景

  - 学术文献处理: 准确识别科技论文中的公式和表格
  - 文档数字化: 将扫描的 PDF 转为可编辑格式
  - 知识提取: 为 LLM 准备高质量训练数据
  - 内容管理: 批量处理文档并结构化存储

  📊 技术栈

  - 深度学习: PyTorch, Transformers, ONNX Runtime
  - 视觉模型: YOLO, UniMERNet (公式), PaddleOCR
  - 推理加速: vLLM, LMDeploy, MLX
  - 接口: FastAPI, Gradio WebUI

  🔗 相关资源

  - 项目地址: /mineru-demo/README.md:588
  - 在线体验: https://mineru.net
  - 技术报告: https://arxiv.org/abs/2509.22186
  - 许可证: AGPL-3.0 (LICENSE.md)

  这是一个专为大模型时代设计的文档解析工具,特别适合处理科技文献中的复杂内容(公式、表格、多语言混排等)。
上下文消耗
> /context
  ⎿
      Context Usage
     ⛁ ⛀ ⛀ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁   claude-sonnet-4-5-20250929 · 88k/200k tokens (44%)
     ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁
     ⛁ ⛁ ⛁ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛁ System prompt: 3.1k tokens (1.5%)
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛁ Custom agents: 279 tokens (0.1%)
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛁ Messages: 40.0k tokens (20.0%)
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛶ Free space: 112k (55.8%)
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛝ Autocompact buffer: 45.0k tokens (22.5%)
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛝ ⛝ ⛝
     ⛝ ⛝ ⛝ ⛝ ⛝ ⛝ ⛝ ⛝ ⛝ ⛝
     ⛝ ⛝ ⛝ ⛝ ⛝ ⛝ ⛝ ⛝ ⛝ ⛝

     MCP tools · /mcp
     └ mcp__context7__resolve-library-id: 0 tokens
     └ mcp__context7__get-library-docs: 0 tokens
     └ mcp__exa-pool__exa_search: 0 tokens
     └ mcp__exa-pool__exa_get_contents: 0 tokens
     └ mcp__exa-pool__exa_find_similar: 0 tokens
     └ mcp__exa-pool__exa_answer: 0 tokens
     └ mcp__exa-pool__exa_create_research: 0 tokens
     └ mcp__exa-pool__exa_get_research: 0 tokens
     └ mcp__code-search__search_code: 0 tokens
     └ mcp__code-search__index_directory: 0 tokens
     └ mcp__code-search__find_similar_code: 0 tokens
     └ mcp__code-search__get_index_status: 0 tokens
     └ mcp__code-search__list_projects: 0 tokens
     └ mcp__code-search__switch_project: 0 tokens
     └ mcp__code-search__index_test_project: 0 tokens
     └ mcp__code-search__clear_index: 0 tokens
     └ mcp__ide__getDiagnostics: 0 tokens
     └ mcp__ide__executeCode: 0 tokens

     Custom agents · /agents

     Plugin
     └ python-development:python-pro: 74 tokens
     └ python-development:fastapi-pro: 74 tokens
     └ python-development:django-pro: 69 tokens

     Project
     └ research-innovate: 23 tokens
     └ review: 21 tokens
     └ plan-execute: 18 tokens

使用 Claude Context Local

执行过程
> 使用Claude Context Local MCP(已完成索引)介绍一下这个项目

● I'll help you explore and introduce this project using the indexed codebase. Let me search through the code to understand what this project is about.
  ⎿ {
      "result": "{\n  \"index_statistics\": {\n    \"total_chunks\": 571,\n    \"index_size\":
     571,\n    \"embedding_dimension\": 768,\n    \"index_type\": \"IndexReplicas\",\n    \"fi
    … +16 lines (ctrl+o to expand)



● Read(README.md)
  ⎿  Error: File content (27393 tokens) exceeds maximum allowed tokens (25000). Please use offset
     and limit parameters to read specific portions of the file, or use the GrepTool to search for
     specific content.

● code-search - search_code (MCP)(query: "main entry point application initialization", k: 5)
  ⎿ {
      "result": "{\"query\":\"main entry point application initialization\",\"results\":[{\"fi
    le\":\"tests/test_data/python_project/main.py\",\"lines\":\"18-35\",\"kind\":\"function\",
    … +13 lines (ctrl+o to expand)



● Read(README.md)
  ⎿  Read 100 lines

● code-search - search_code (MCP)(query: "code search semantic similarity indexing", k: 5)
  ⎿ {
      "result": "{\"query\":\"code search semantic similarity indexing\",\"results\":[{\"file\
    ":\"mcp_server/code_search_server.py\",\"lines\":\"155-254\",\"kind\":\"method\",\"score\"
    … +15 lines (ctrl+o to expand)



● Search(pattern: "*.py")
  ⎿  Found 100 files (ctrl+o to expand)

● Let me look at the project structure more clearly:

● Read(README.md)
  ⎿  Read 150 lines

● Read(pyproject.toml)
  ⎿  Read 165 lines

● code-search - search_code (MCP)(query: "PDF parsing document extraction layout analysis", k: 5)
  ⎿ {
      "result": "{\"query\":\"PDF parsing document extraction layout analysis\",\"results\":[{
    \"file\":\"chunking/languages/markdown_chunker.py\",\"lines\":\"58-164\",\"kind\":\"method
    … +17 lines (ctrl+o to expand)



● Now let me check the actual project structure:

● Bash(ls -la /home/tully/Python_Project/mineru-demo)
  ⎿  total 1340
     drwxrwxr-x 13 tully tully    4096 Dec 27 12:17 .
     drwxrwxr-x 11 tully tully    4096 Dec 26 11:40 ..
     … +24 lines (ctrl+o to expand)

● Bash(find /home/tully/Python_Project/mineru-demo -maxdepth 2 -name "*.py" -type f | grep -v
      ".venv" | head -20)
  ⎿  /home/tully/Python_Project/mineru-demo/demo/demo.py
     /home/tully/Python_Project/mineru-demo/update_version.py
     /home/tully/Python_Project/mineru-demo/mineru/version.py
     … +3 lines (ctrl+o to expand)

● Read(demo/demo.py)
  ⎿  Read 241 lines

● Bash(ls -la /home/tully/Python_Project/mineru-demo/mineru)
  ⎿  total 44
     drwxrwxr-x  9 tully tully 4096 Dec 26 11:44 .
     drwxrwxr-x 13 tully tully 4096 Dec 27 12:17 ..
     … +9 lines (ctrl+o to expand)
结果展示
● Based on the indexed codebase and project files, let me provide you with a comprehensive introduction to this project:

  ---
  MinerU 项目介绍

  项目概述

  MinerU 是一个功能强大的 PDF 到 Markdown 转换工具,由 OpenDataLab 开发。这是一个开源项目(AGPL-3.0 许可证),专门用于将 PDF 文档转换为结构化的 Markdown 格式,特别擅长处理复杂的学术论文、技术文档等。

  核心特性

  1. 多后端支持

  - Pipeline 后端:更通用,适合大多数场景
  - VLM(视觉语言模型)后端:
    - vlm-transformers:通用性强
    - vlm-vllm-engine:更快(使用 vLLM 引擎加速)
    - vlm-lmdeploy-engine:支持 Windows 平台的本地推理加速
    - vlm-mlx-engine:专为 Apple Silicon 优化,速度提升 100%-200%
    - vlm-http-client:客户端模式,连接远程服务器

  2. MinerU2.5 模型

  项目的核心是 MinerU2.5 多模态大模型:
  - 仅有 1.2B 参数,但性能超越 Gemini 2.5 Pro、GPT-4o 等大型模型
  - 在 OmniDocBench 基准测试中达到 SOTA(最先进)水平
  - 支持五大核心能力:
    - ✅ 布局分析(Layout Analysis)
    - ✅ 文本识别(OCR)
    - ✅ 公式识别(Formula Recognition)
    - ✅ 表格识别(Table Recognition)
    - ✅ 阅读顺序识别(Reading Order)

  3. 强大的解析能力

  - 多语言 OCR:支持 37 种语言(中英法德俄韩日等)
  - 公式解析:支持复杂数学公式、中英混合公式
  - 表格解析:
    - 支持旋转表格(0°/90°/270°)
    - 无边框/半结构化表格
    - 跨页表格合并
    - 复杂长表格
  - 布局检测:精确识别页眉、页脚、页码、列表、引用等非正文内容

  4. 性能优化

  - OCR 速度提升 200%-300%
  - 支持批量处理
  - 高并发场景优化
  - GPU/CPU 资源配置灵活

  项目结构

  mineru-demo/
  ├── mineru/                 # 核心代码
  │   ├── backend/           # 后端实现(pipeline, vlm)
  │   ├── cli/               # 命令行工具
  │   ├── data/              # 数据读写处理
  │   ├── model/             # 模型相关代码
  │   ├── utils/             # 工具函数
  │   └── resources/         # 资源文件
  ├── demo/                  # 示例代码(demo.py:1-241)
  ├── tests/                 # 测试代码
  ├── docs/                  # 文档
  └── docker/                # Docker 配置

  主要用法

  Python API 示例(demo/demo.py)

  from pathlib import Path
  from mineru.demo.demo import parse_doc

  # 解析 PDF 文档
  doc_path_list = [Path("document.pdf")]
  output_dir = "output"

  # 使用 Pipeline 后端
  parse_doc(doc_path_list, output_dir, backend="pipeline")

  # 或使用 VLM 后端(更快更准)
  parse_doc(doc_path_list, output_dir, backend="vlm-vllm-engine")

  命令行工具

  项目提供多个命令行工具(pyproject.toml:112-118):
  - mineru - 主程序
  - mineru-models-download - 模型下载
  - mineru-api - FastAPI 服务
  - mineru-gradio - Web UI
  - mineru-vllm-server - vLLM 推理服务器

  输出格式

  MinerU 可以生成多种输出:
  - Markdown 文件:格式化的文本内容
  - content_list.json:结构化内容列表(带坐标)
  - middle.json:中间处理结果
  - layout.pdf:布局可视化(标注边界框)
  - 图片提取:提取文档中的图片

  技术亮点

  1. 两阶段推理架构:将布局分析与内容识别解耦
  2. 原生高分辨率支持:处理高分辨率文档不失真
  3. 混合表格结构解析:结合有线框表格识别模型
  4. 跨页表格续接:智能合并跨页表格
  5. 环境变量配置:灵活的参数配置(超时、并发、特性开关等)

  应用场景

  - 📚 学术论文解析
  - 📄 技术文档提取
  - 📊 表格数据提取
  - 🔢 数学公式识别
  - 🌐 多语言文档处理
  - 🤖 RAG(检索增强生成)系统的文档预处理

  社区与文档

  - GitHub: https://github.com/opendatalab/MinerU
  - 在线文档: https://opendatalab.github.io/MinerU/
  - 在线体验: https://mineru.net/
  - HuggingFace Demo: https://huggingface.co/spaces/opendatalab/MinerU
  - 技术报告: https://arxiv.org/abs/2509.22186

  ---
  这个项目是目前最先进的 PDF 文档解析工具之一,特别适合需要高质量文档解析和结构化提取的场景!
上下文消耗
> /context
  ⎿
      Context Usage
     ⛁ ⛀ ⛀ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁   claude-sonnet-4-5-20250929 · 77k/200k tokens (39%)
     ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛶ ⛶ ⛶
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛁ System prompt: 3.1k tokens (1.5%)
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛁ Custom agents: 279 tokens (0.1%)
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛁ Messages: 28.9k tokens (14.5%)
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛶ Free space: 123k (61.3%)
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛝ Autocompact buffer: 45.0k tokens (22.5%)
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛝ ⛝ ⛝
     ⛝ ⛝ ⛝ ⛝ ⛝ ⛝ ⛝ ⛝ ⛝ ⛝
     ⛝ ⛝ ⛝ ⛝ ⛝ ⛝ ⛝ ⛝ ⛝ ⛝

     MCP tools · /mcp
     └ mcp__context7__resolve-library-id: 0 tokens
     └ mcp__context7__get-library-docs: 0 tokens
     └ mcp__exa-pool__exa_search: 0 tokens
     └ mcp__exa-pool__exa_get_contents: 0 tokens
     └ mcp__exa-pool__exa_find_similar: 0 tokens
     └ mcp__exa-pool__exa_answer: 0 tokens
     └ mcp__exa-pool__exa_create_research: 0 tokens
     └ mcp__exa-pool__exa_get_research: 0 tokens
     └ mcp__code-search__search_code: 0 tokens
     └ mcp__code-search__index_directory: 0 tokens
     └ mcp__code-search__find_similar_code: 0 tokens
     └ mcp__code-search__get_index_status: 0 tokens
     └ mcp__code-search__list_projects: 0 tokens
     └ mcp__code-search__switch_project: 0 tokens
     └ mcp__code-search__index_test_project: 0 tokens
     └ mcp__code-search__clear_index: 0 tokens
     └ mcp__ide__getDiagnostics: 0 tokens
     └ mcp__ide__executeCode: 0 tokens

     Custom agents · /agents

     Plugin
     └ python-development:python-pro: 74 tokens
     └ python-development:fastapi-pro: 74 tokens
     └ python-development:django-pro: 69 tokens

     Project
     └ research-innovate: 23 tokens
     └ review: 21 tokens
     └ plan-execute: 18 tokens

Claude Context Local MCP 介绍

概况

本地化的代码库语义索引工具,可零 API 成本、完全私密地由嵌入向量 (embeddings) 将整个代码库转化为可检索的上下文,显著减少 token 消耗并提升代码理解准确性。

安装

  1. 执行 curl -fsSL https://raw.githubusercontent.com/FarhanAliRaza/claude-context-local/main/scripts/install.sh | bash 命令,即可完成自动化的环境检测、依赖安装、Embedding 模型下载。再次执行该命令可以执行一次更新;
Error

该命令可能因未获取到 Hugging Face 令牌而下载 Embedding 模型失败,需要依次:

  1. 创建 Read 权限的 token 后,执行 (cd ~/.local/share/claude-context-local && uv run huggingface-cli login --token hf_***) 命令登录;
  2. 访问 google/embeddinggemma-300m 接受模型使用条款;
  3. 重新手动下载模型:(cd ~/.local/share/claude-context-local && uv run scripts/download_model_standalone.py)
  1. 安装至 Claude Code:claude mcp add code-search --scope user -- uv run --directory ~/.local/share/claude-context-local mcp_server/server.py

使用

在项目中首次使用时,向 Claude Code 声明 “索引代码库” 即可。少量的代码更新可由 Merkle Tree 智能增量更新文件哈希树变更;大量的代码变更可再次向 Claude Code 声明 “索引代码库”。亦可设置 Git Hook(如.git/hooks/post-merge)提示重新索引。

我有几个问题想请佬咨询一下
  1. 这个 MCP 是否类似于 Cursor 的 Codebase Indexing 功能?
  2. 有更好的类似工具或 MCP 工具吗?欢迎推荐

📌 转载信息
原作者:
Tully
转载时间:
2025/12/29 12:26:32