MarkIndex MCP

MarkIndex MCP

Enables LLMs to accurately navigate and retrieve information from complex documents using Page Index RAG methodology.

Category
访问服务器

README

<div align="center">

📄 MarkIndex MCP

Enterprise Document Intelligence Server

CI Python 3.11+ MCP Protocol Ruff License: MIT Version

Turn PDFs, Word docs, Markdown, websites, and YouTube transcripts into a local-first MCP knowledge base that LLMs can search, read, and navigate by stable section IDs — no vector database required.

If this helps your MCP/RAG workflow, please consider starring the repo ⭐

</div>

Key Advantages:

  • 🏠 Local-first architecture
  • 🚫 No vector DB required
  • 🔑 Stable section IDs
  • 📖 Section-level search/read/navigation
  • 🤖 Works seamlessly with Claude Desktop & MCP clients
  • ⚡ Built on Microsoft MarkItDown

Preview

Here’s what MarkIndex MCP looks like when an LLM searches and navigates a local policy document.

Server startup

Server startup

Search result

Search result

Stable outline IDs

Outline result

Read by section ID

Read section

Save outputs

Save output


✨ Features

Capability Description
📥 Universal Ingestion PDF, Word, Excel, PowerPoint, HTML, TXT, Markdown, URLs
🎬 YouTube Transcripts Auto-download and index video transcripts with time-chunking
📂 Batch Directory Scan Ingest all supported files from a directory in one call
🌳 Hierarchical Parsing Detects #, SECTION, CHAPTER, APPENDIX, numbered, Roman, and timestamp headers
🔍 TF-IDF Search Relevance-ranked full-text search with regex support and context snippets
📖 Paginated Reading Character-level pagination for reading large sections without overflow
🧭 Tree Navigation Parent, previous, next sibling traversal for sequential reading
📝 Extractive Summaries Term-frequency sentence scoring for quick section overviews
💾 Persistent Cache Markdown files with JSON frontmatter — human-readable, git-friendly

⚙️ How It Works: The 3-Folder Secret System

MarkIndex utilizes an organized, self-updating knowledge architecture:

  1. raw/: Drop your source materials here (PDFs, Word documents, HTML, etc.). The server reads these files but never alters them.
  2. wiki/: The server processes the raw files and structures them into cross-linked Markdown pages (one per document). It also generates a master index.md file that acts as a crawlable map, allowing the LLM to efficiently fetch context without wasting tokens.
  3. outputs/: This folder automatically saves the results, reports, or plans generated every time you ask the LLM to write something based on your knowledge base.

By implementing this architecture, you essentially build a self-updating, personal consultation engine tailored to your exact data and files.


⚖️ Vector RAG vs. MarkIndex

How does our MarkIndex methodology compare to traditional Vector Database RAG?

Feature Vector RAG MarkIndex RAG
Context Preservation 4/10 10/10
Setup Complexity 3/10 9/10
Cost to Run 5/10 10/10
Sequential Reading 2/10 10/10
Token Efficiency 3/10 9/10
Fuzzy Semantic Match 9/10 6/10
Total Score 26/60 54/60

MarkIndex excels by preserving the original document hierarchy and allowing the LLM to paginate through full, unbroken sections, rather than receiving fragmented, out-of-context vector chunks.

Why MarkIndex RAG is Different:

  1. Hierarchy vs. Chunks: Traditional Vector RAG chops documents into arbitrary 500-token chunks, destroying the author's intended structure. MarkIndex parses the actual headers (#, Chapter 1, etc.) to create a navigable tree with stable, unique section IDs.
  2. Full Context: When an LLM asks MarkIndex for a section, it gets the entire section, exactly as it was written, rather than a few stitched-together vector matches that lack surrounding context.
  3. No Expensive Embeddings: Vector RAG requires passing every document through an embedding model (like OpenAI text-embedding-ada-002), which costs time and API credits. MarkIndex uses an ultra-fast, local, pure-Python N-Gram TF-IDF engine for advanced multi-word lexical search.
  4. Stable IDs & Context: MarkIndex tracks document paths deterministically (chapter-1-summary-2) allowing the LLM to easily distinguish between duplicate subheadings. When an LLM asks MarkIndex for a section by ID, it gets the entire section.
  5. Token Efficiency: Vector RAG blindly dumps 5 to 10 disjointed chunks (2,500+ tokens) into the prompt. MarkIndex feeds the LLM a tiny structural map (index.md), and the LLM only fetches the specific, highly-relevant section it needs, drastically reducing token waste and API costs.
  6. LLM Agency: With MarkIndex, the LLM acts like a human reader. It can read the Table of Contents, search for keywords, jump to a specific section, and then navigate to the "next" or "previous" sections.

Architecture

MarkIndex uses a robust "3-Folder Secret System" for enterprise knowledge management:

  • raw/: Your original, untouched source documents (PDFs, Word docs, etc.).
  • wiki/: The LLM's internal representation, stored as hierarchical Markdown files with JSON frontmatter.
  • outputs/: Where the LLM automatically saves the persistent reports and answers it generates for you.

Note: You can strictly control whether the LLM is allowed to access files outside the raw/ directory via the MARKINDEX_ALLOW_EXTERNAL_FILES=true/false setting.

markindex-mcp/
├── markindex/                       # Python package
│   ├── __init__.py                  # Version & metadata
│   ├── __main__.py                  # python -m markindex
│   ├── config.py                    # Centralized Settings dataclass
│   ├── logger.py                    # Structured logging
│   ├── exceptions.py                # Custom exception hierarchy
│   ├── server.py                    # FastMCP server & lifecycle
│   ├── core/                        # Business logic
│   │   ├── parser.py                # Hierarchical document parser
│   │   ├── search.py                # TF-IDF ranking engine
│   │   ├── summarizer.py            # Extractive summarization
│   │   └── storage.py               # Frontmatter serialization & I/O
│   └── tools/                       # MCP tool definitions
│       ├── ingest.py                # Ingestion tools
│       ├── query.py                 # Querying tools
│       ├── navigate.py              # Navigation tools
│       └── manage.py                # Management tools
├── tests/                           # Test suite
├── pyproject.toml                   # PEP 621 packaging
├── requirements.txt                 # Dependencies
├── raw/                             # [NEW] Drop your source files here
├── wiki/                            # [NEW] Auto-generated markdown & master index.md
└── outputs/                         # [NEW] Claude's generated reports and summaries

⏱️ 30-Second Demo

Here are example MCP tool calls an LLM can make to process documents efficiently:

# 1. Ingest document (Place files in raw/ first unless MARKINDEX_ALLOW_EXTERNAL_FILES=true)
ingest_document("raw/company_policy.pdf")

# 2. Search for relevant sections using fast TF-IDF
search_sections(doc_id="doc_xyz123", query="vehicle compensation", limit=3)

# 3. Read specific section with full surrounding context
read_section(doc_id="doc_xyz123", section_title="vehicle-claims-compensation")

# 4. Navigate sequentially through the document
get_adjacent_sections(doc_id="doc_xyz123", section_title="vehicle-claims-compensation")

# 5. Save the final report locally
save_to_outputs("vehicle_claims_summary.md", summary)

Example Output

When you search or read sections, MarkIndex returns clean JSON structures:

search_sections() Result:

{
  "success": true,
  "data": [
    {
      "section_title": "vehicle-claims-compensation",
      "snippets": ["...eligible for vehicle compensation...", "...$0.65 per mile..."],
      "score": 12.4
    }
  ],
  "error": null,
  "code": null
}

read_section() Result:

{
  "success": true,
  "data": "## Vehicle Compensation\n\nEmployees who use their personal vehicles for corporate travel are eligible for vehicle compensation.\nThe rate is $0.65 per mile.",
  "error": null,
  "code": null
}

🚀 Quick Start

Prerequisites

  • Python 3.11+
  • pip

Installation

# Clone the repository
git clone https://github.com/rajfazulhussain2008/markindex-mcp.git
cd markindex-mcp

# Create a virtual environment
python -m venv venv
venv\Scripts\activate       # Windows
# source venv/bin/activate  # macOS/Linux

# Install dependencies
pip install -r requirements.txt

# Optional: YouTube transcript support
pip install youtube-transcript-api

Claude Desktop Configuration

Add the following to your claude_desktop_config.json (ensure you use absolute paths, install dependencies first, and restart Claude after saving):

{
  "mcpServers": {
    "markindex": {
      "command": "python",
      "args": ["-m", "markindex"],
      "cwd": "/absolute/path/to/markindex-mcp"
    }
  }
}

🔧 Configuration

All settings are managed via environment variables (prefix: MARKINDEX_):

Variable Default Description
MARKINDEX_RAW_DIR ./raw Source materials directory
MARKINDEX_WIKI_DIR ./wiki Processed markdown & master index directory
MARKINDEX_OUTPUTS_DIR ./outputs AI generated reports directory
MARKINDEX_LOG_LEVEL INFO Log verbosity: DEBUG, INFO, WARNING, ERROR
MARKINDEX_ALLOW_EXTERNAL_FILES false Enable access outside raw/ directory
MARKINDEX_MAX_FILE_MB 50 Maximum file size for local/URL downloads

Copy .env.example.env and customize as needed.


📚 Tool Reference

All tools return a consistent standard dictionary: {"success": true/false, "data": ..., "error": null, "code": null}

Core Tools

Tool Description
ingest_document(filepath) Download a URL or ingest a local file (strict size/type safety constraints).
ingest_directory(dir_path) Recursively ingest a whole folder.
list_documents() View all ingested docs.
delete_document(doc_id) Completely purge a document from memory and disk.

LLM Exploration Tools

Tool Description
get_document_outline(doc_id) View the document's structure, titles, stable IDs, and sizes.
search_sections(doc_id, query) Find specific keywords/regex using N-Gram TF-IDF engine.
read_section(doc_id, section_id) Fetch the full markdown content of a section.
get_adjacent_sections(...) Read the parent, previous, or next section.
summarize_section(...) Generate an extractive summary of a huge section.

Management Tools

Tool Description
list_documents() List all ingested documents
delete_document(doc_id) Delete a document from index and cache
save_to_outputs(filename, content) Save AI-generated reports to the outputs/ folder
get_server_status() Get the server's version, uptime, and memory statistics

🛡️ Security & Troubleshooting

Strict Path Security

MarkIndex enforces strict path traversal mitigation. By default, MARKINDEX_ALLOW_EXTERNAL_FILES=false. You cannot ingest local files outside of the raw/ directory, nor save outputs outside of outputs/. Files ingested via local paths or URLs are heavily sanitized. The maximum file size limit is controlled by MARKINDEX_MAX_FILE_MB (default 50).

Resolving Duplicate Section IDs

If a document contains multiple headers with the exact same text (e.g. ## Summary), MarkIndex assigns them deterministic, stable IDs by appending numerical counters (summary, summary-2, summary-3). When calling read_section or get_adjacent_sections, always use the exact section ID provided by get_document_outline or search_sections to avoid ambiguity.

Missing Any or dict Type Hint Errors

If you are upgrading from 1.x to 2.x, ensure you have installed the exact 2.0.0 version. MarkIndex 2.0.0 uses Python 3.11+ strictly typed ToolResponse models to guarantee clean JSON structures for all LLM tools.

Common Errors

Error Code Meaning & Resolution
ACCESS_DENIED You tried to ingest a local file outside the raw/ directory. Move the file into raw/ or set MARKINDEX_ALLOW_EXTERNAL_FILES=true.
FILE_TOO_LARGE The file exceeds the MARKINDEX_MAX_FILE_MB setting (default 50MB).
TEXT_TOO_LARGE The raw text passed to ingest_text exceeds MARKINDEX_MAX_TEXT_CHARS.
SECTION_NOT_FOUND You requested a section title that doesn't exist. Check the suggestions in the error message or use get_document_outline().

🧪 Testing & Development

See our Contributing Guide to get started!

# Run the test suite
python -m pytest tests/ -v

📄 License

This project is licensed under the MIT License.

<div align="center"> Built with ❤️ by Rajmohamed H

Recommended Topics: mcp, model-context-protocol, rag, document-ai, document-intelligence, markitdown, python, llm-tools, claude, ai, knowledge-base, tf-idf, markdown </div>

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选