AI Book Agent MCP Server

AI Book Agent MCP Server

Provides AI assistants with intelligent access to ML textbook content for creating accurate, source-grounded documentation using local models for privacy and cost efficiency.

Category
访问服务器

README

AI Book Agent MCP Server

An MCP (Model Context Protocol) server that provides AI assistants with intelligent access to ML textbook content for creating accurate, source-grounded documentation. This pure Python implementation uses local models for complete privacy and cost efficiency.

Overview

This project transforms authoritative ML textbooks into a knowledge service that any MCP-compatible AI assistant can access. Using local LLMs (Qwen) and embeddings (sentence-transformers), it creates a private, cost-effective RAG system exposed via the official Python MCP SDK.

Why MCP?

Traditional Approach Limitations

  • Knowledge locked in a single application
  • Users must switch between tools
  • Cannot leverage AI assistants they already use
  • Difficult to integrate with existing workflows

MCP Server Benefits

  • Universal Access: Works with Claude Desktop, VS Code, and any MCP client
  • Workflow Integration: Use book knowledge directly in your IDE or chat
  • Composability: Combine with other MCP servers (filesystem, GitHub, etc.)
  • Future-Proof: As MCP ecosystem grows, your book agent automatically works with new tools

Architecture

┌─────────────────────┐     ┌─────────────────────┐
│   Claude Desktop    │     │      VS Code        │
│  "Explain ML drift  │     │  "Generate docs     │
│   from textbooks"   │     │   for monitoring"   │
└──────────┬──────────┘     └──────────┬──────────┘
           │                           │
           └─────────────┬─────────────┘
                         │ MCP Protocol (stdio/HTTP)
                         ▼
            ┌─────────────────────────────────────┐
            │     Python MCP Server               │
            │  (Official modelcontextprotocol/    │
            │         python-sdk)                 │
            ├─────────────────────────────────────┤
            │ MCP Tools:                          │
            │ - @mcp.tool() search_books()        │
            │ - @mcp.tool() get_chapter_content() │
            │ - @mcp.tool() generate_section()    │
            │ - @mcp.tool() cite_sources()        │
            ├─────────────────────────────────────┤
            │ RAG Components (same process):      │
            │ - EPUB Parser (ebooklib)            │
            │ - Embeddings (sentence-transformers)│
            │ - Vector Store (ChromaDB/FAISS)     │
            │ - LLM Generation (Ollama/Qwen)      │
            └─────────────────────────────────────┘

Technology Stack

  • MCP Framework: Official Python SDK (mcp[cli])
  • Language: Python 3.11+
  • Embeddings: sentence-transformers (all-MiniLM-L6-v2)
  • LLM: Ollama with Qwen 2.5 7B
  • Vector Store: ChromaDB/FAISS
  • Book Parsing: ebooklib, BeautifulSoup4
  • Transport: stdio (local) or HTTP (remote)

Core Features as MCP Tools

1. searchBooks

Search across all indexed books for relevant content

{
  name: "searchBooks",
  description: "Search ML textbooks for specific topics or concepts",
  inputSchema: {
    query: string,
    bookFilter?: string[],
    maxResults?: number,
    includeContext?: boolean
  }
}

2. getChapterContent

Retrieve specific chapter or section content

{
  name: "getChapterContent",
  description: "Get full content of a specific book chapter",
  inputSchema: {
    bookId: string,
    chapterId: string,
    format?: "markdown" | "plain"
  }
}

3. generateSection

Generate documentation based on book content

{
  name: "generateSection",
  description: "Generate documentation section grounded in textbook sources",
  inputSchema: {
    topic: string,
    outline?: string[],
    style?: "technical" | "tutorial" | "overview",
    maxSources?: number
  }
}

4. citeSources

Get proper citations for content

{
  name: "citeSources",
  description: "Generate proper citations for book content",
  inputSchema: {
    bookId: string,
    pageNumbers?: number[],
    format?: "APA" | "MLA" | "Chicago"
  }
}

Resources

The server exposes book content as browsable resources:

/books
├── /designing-ml-systems
│   ├── metadata.json
│   ├── /chapters
│   │   ├── /1-introduction
│   │   ├── /2-ml-systems-design
│   │   └── ...
│   └── /topics
│       ├── /monitoring
│       ├── /deployment
│       └── ...
└── /other-ml-book
    └── ...

Prompts

Pre-configured prompts for common tasks:

doc_generator

name: doc_generator
description: Generate technical documentation from book sources
arguments:
  - name: topic
    description: The topic to document
  - name: audience
    description: Target audience (beginner/intermediate/advanced)
  - name: length
    description: Desired length (brief/standard/comprehensive)

concept_explainer

name: concept_explainer
description: Explain ML concepts using textbook definitions
arguments:
  - name: concept
    description: The concept to explain
  - name: include_examples
    description: Whether to include practical examples

Use Cases

1. In Claude Desktop

User: "Explain model drift using the ML textbooks"
Claude: [Uses searchBooks tool to find drift content]
        [Retrieves relevant chapters]
        [Generates explanation with citations]

2. In VS Code

# User comment: "TODO: Add monitoring based on best practices"
# AI Assistant uses book agent to generate monitoring code

3. Documentation Pipeline

# Automated doc generation using MCP tools
mcp-client generate-docs \
  --server ai-book-agent \
  --topics "deployment,monitoring,testing" \
  --output ml-best-practices.md

Getting Started

Prerequisites

  • Linux system (Ubuntu 22.04+ recommended)
  • Python 3.11+
  • Node.js 18+
  • 16GB RAM minimum
  • 20GB free disk space

Installation

# Clone the repository
git clone <repository-url>
cd ai-book-agent

# Install Python dependencies (with MCP SDK)
pip install "mcp[cli]" sentence-transformers chromadb ollama ebooklib beautifulsoup4

# Or use requirements.txt
pip install -r requirements.txt

# Install Ollama for local LLM
curl -fsSL https://ollama.ai/install.sh | sh

# Pull required models
ollama pull qwen2.5:7b

# Index existing books
python scripts/index_books.py

Configuration

Configure the server:

# config.yaml
embeddings:
  model: "all-MiniLM-L6-v2"
  device: "cpu"  # or "cuda"
  
generation:
  provider: "ollama"
  model: "qwen2.5:7b"
  base_url: "http://localhost:11434"
  
books:
  data_dir: "data/epub"
  index_dir: "data/vector_db"

Add to Claude Desktop config:

{
  "mcpServers": {
    "ai-book-agent": {
      "command": "python",
      "args": ["/path/to/ai-book-agent/server.py"]
    }
  }
}

Basic Usage

Once configured, the tools are available in any MCP client:

You: What does the <author> say about feature engineering?
Assistant: I'll search the ML textbooks for information about feature engineering.

[Calling searchBooks with query="feature engineering"]
[Found 5 relevant sections in "<Book Title>"]

According to <author> in "<Book Title>":

Feature engineering is described as... [content with citations]

Development

Adding New Books

# Place EPUB in data directory
cp new-ml-book.epub data/epub/

# Re-index all books
python scripts/index_books.py

# Server will automatically pick up new content

Extending Tools

Add new tools directly in server.py:

from mcp.server.fastmcp import FastMCP

mcp = FastMCP("ai-book-agent")

@mcp.tool()
def compare_approaches(approach1: str, approach2: str) -> str:
    """Compare different ML approaches from multiple books"""
    results1 = search_books(approach1, 3)
    results2 = search_books(approach2, 3)
    
    comparison = generate_comparison(results1, results2)
    return comparison

@mcp.resource("book://{book_id}/summary")
def get_book_summary(book_id: str) -> str:
    """Get a summary of a specific book"""
    return load_book_summary(book_id)

Testing

# Test MCP server locally
mcp dev server.py

# Test individual components
python scripts/test_components.py
python scripts/test_search.py

# Run full test suite
pytest tests/

# Test with Claude Desktop
mcp install server.py

Project Structure

ai-book-agent/
├── server.py             # Main MCP server (entry point)
├── src/                  # Python modules
│   ├── parsers/          # EPUB parsing
│   ├── embeddings/       # Embedding generation
│   ├── search/           # Vector search & retrieval
│   ├── generation/       # LLM integration (Ollama)
│   └── utils/            # Configuration and helpers
├── scripts/              # Utility scripts
│   ├── index_books.py    # Index EPUB files
│   ├── test_*.py         # Test individual components
│   └── setup.py          # Initial setup
├── data/
│   ├── epub/             # Source EPUB files
│   ├── processed/        # Processed book content
│   └── vector_db/        # Vector store data
├── tests/                # Test suites
├── config.yaml           # Configuration
├── requirements.txt      # Python dependencies
└── README.md

Pure Python Architecture

This project uses a simplified, single-language approach:

  • Python MCP Server: Official SDK handles MCP protocol and tool exposure
  • Integrated RAG: All ML components run in the same Python process
  • Local Models: Complete privacy with Ollama and sentence-transformers

Benefits of this approach:

  • Simpler deployment: Single Python service
  • Direct ML access: No API overhead between MCP and RAG
  • Easier debugging: One codebase, one process
  • Better performance: No network calls between components

Remote Access

For accessing the server from anywhere:

# Option 1: Cloudflare Tunnel (recommended)
cloudflared tunnel create book-agent
cloudflared tunnel run --url http://localhost:8080 book-agent

# Option 2: Configure with your domain
# See USER_GUIDE.md for detailed setup

Roadmap

  • [x] Basic MCP server structure
  • [x] EPUB parsing and indexing
  • [x] Core search tools
  • [ ] Advanced RAG features
  • [ ] Multi-book cross-referencing
  • [ ] PDF support
  • [ ] Streaming responses for long content
  • [ ] Caching layer for performance
  • [ ] Book update notifications

Contributing

See USER_GUIDE.md for details on:

  • Adding new tools
  • Improving search algorithms
  • Supporting new book formats
  • Performance optimizations

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选