Skip to main content
Glama
dis70rt

closed-book-mcp

by dis70rt

Zero-Hallucination, Closed-Book Retrieval Engine via Model Context Protocol (MCP)

Python Version MCP Compatible Local Privacy License: MIT

A lightning-fast, local Retrieval-Augmented Generation (RAG) system built on the Model Context Protocol (MCP). ClosedBook enforces authoritative, ground-truth retrieval over your local documents (PDFs, manuals, SOPs, study materials) using Hybrid Search (Dense Semantic + BM25Okapi)—completely cutting out hallucinations and overriding unverified model assumptions.

CAUTION

This software is provided for educational, research, and audit purposes only. The creator assumes no responsibility for misuse of this software, including academic dishonesty or unauthorized use during proctored examinations. Always use responsibly.


Features

  • Hybrid Search Architecture: Combines BAAI/bge-small-en-v1.5 (semantic understanding) with BM25Okapi (exact keyword matching) to catch tricky legal or technical phrasing.

  • Strict Closed-Book Mode: Forces the AI to rely entirely on the provided PDFs, ignoring conflicting pretrained knowledge (perfect for exams where the textbook has specific/outdated answers).

  • 100% Local Privacy: Runs embedding and vector searches locally on your CPU using faiss-cpu. No cloud API required.

  • Agent Integration: Plugs directly into the Antigravity AI agent framework or any MCP-compatible client.


Related MCP server: PDF RAG MCP Server

Prerequisites

Before you begin, ensure you have met the following requirements:

  • You have installed Python 3.12+.

  • You have installed uv (an extremely fast Python package installer and resolver).


Getting Started

1. Install Dependencies

Clone the repository, navigate to the folder, and run:

uv sync

2. Add Your Study Materials

Place your exam study materials (PDFs) into the resources/ directory.

mkdir -p resources
# copy your PDFs here (e.g., cp ~/Downloads/lecture_slides.pdf resources/)

3. Build the Search Index

Run the ingestion script to chunk your PDFs and generate the vector embeddings.

uv run ingest.py
NOTE

On the first run, it will automatically download a ~130MB embedding model from Hugging Face.

4. Configure Antigravity (or your MCP Client)

Open your Antigravity MCP configuration file (typically ~/.gemini/config/mcp_config.json) and add this server block. Make sure to update the absolute path to point to your cloned repository:

{
  "mcpServers": {
    "mcp_closed_book": {
      "command": "uv",
      "args": [
        "--directory",
        "/ABSOLUTE/PATH/TO/ExamMCP",
        "run",
        "server.py"
      ]
    }
  }
}

Usage

Once the MCP server is configured and your AI Agent is restarted, it will automatically detect the rules in GEMINI.md.

Simply batch paste your multiple-choice questions into the chat:

1. According to the act, no suit or prosecution shall lie against whom?
A) The contractor
B) Any person acting in good faith
C) The court
D) The victim

The AI will run parallel background searches against your PDF index and immediately output the correct option based only on the text.


Customizing

If you are forking this repo for your own exams, here is what you need to change:

  1. The PDFs (resources/): Delete the existing PDFs and replace them with your own study guides, lecture slides, or textbooks.

  2. Chunking Size (ingest.py): By default, the system uses 1000-character chunks with a 200-character overlap. If your exam requires extreme precision (like math formulas), you may want to decrease chunk size.

  3. The System Prompt (GEMINI.md): The root GEMINI.md file contains the strict rules for the AI. If your exam requires essay-style answers instead of Multiple Choice (MCQ), edit GEMINI.md and change the instructions to output detailed paragraphs instead of just "Option A".

  4. Rebuild the Index: Whenever you change your PDFs, you must run uv run ingest.py again!


Contributing

Contributions, issues, and feature requests are welcome! Feel free to check the issues page.


License

This project is licensed under the MIT License - see the LICENSE file for details.

Available Tools

3 tools
list_indexed_documentsA

Return all indexed PDFs and their page counts.

ParametersJSON Schema
NameRequiredDescriptionDefault

No parameters

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A3.8/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are present, and the description only says 'Return', leaving side effects, permissions, and potential limitations unstated.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

A single, focused sentence with no unnecessary words or repetition.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Adequate for a simple list operation, though it does not specify output format or error behavior, which are not critical here.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

No parameters exist, so the description needs no parameter details; the output scope is clear from the description.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Clearly states the tool returns all indexed PDFs and their page counts; this is distinct from sibling tools like search and page reading.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Implicitly suggests use when a full listing is needed, but does not explicitly contrast with closed_book_search or read_document_page.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

read_document_pageB

Return the complete extracted text of a specific page from a document.

ParametersJSON Schema
NameRequiredDescriptionDefault
pageYes
documentYes

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

B3.3/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It discloses that the operation is a read (returns text) but does not mention edge cases (e.g., invalid page, unindexed document) or any implicit side effects. For a simple read tool, this is minimally transparent but not rich in behavioral detail.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, front-loaded sentence that states the action and outcome with zero filler. It is efficient and immediately informative.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The tool is simple but the description omits critical context: it does not mention that the document must be indexed (as suggested by the sibling list_indexed_documents), nor does it state the page numbering convention. Without this, an agent might attempt to read an unindexed document or misinterpret page numbers, leading to errors.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate for parameter meaning. It only implies that 'document' identifies a document and 'page' specifies a page number, but does not clarify page indexing (0- or 1-based), expected document ID format, or constraints. This is insufficient given the lack of schema descriptions.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states a specific action ('Return'), the resource ('complete extracted text of a specific page'), and the target ('document'). It clearly differentiates from siblings: closed_book_search (search) and list_indexed_documents (list), so an agent can distinguish without ambiguity.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus closed_book_search or list_indexed_documents. It does not mention that the document must already be indexed or that this tool is for retrieving raw page text rather than searching. An agent is left to infer usage from the tool name.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

  1. 3 tool updatesv0.1.0
    • First observedclosed_book_search
    • First observedlist_indexed_documents
    • First observedread_document_page

TDQS

A4/5.0

Scored across 3 tools

Disambiguation5/5

Each tool has a clear, non-overlapping purpose: search across documents, read a specific page, and list available documents. There is no ambiguity about which tool to use for a given task.

Naming Consistency5/5

All tool names follow a consistent verb_noun pattern (closed_book_search, read_document_page, list_indexed_documents) using lowercase with underscores. The naming is uniform and predictable.

Tool Count5/5

With exactly three tools, the server is well-scoped for its purpose of closed-book document retrieval. Each tool serves a distinct necessary function without redundancy or bloat.

Completeness5/5

The tool set covers the full workflow: discover available documents, search their contents, and read specific pages. This is sufficient for the stated domain of closed-book question answering over PDFs.

Maintenance

ActivityMaintained
ResponsivenessNo issues

Related MCP Connectors

Related MCP Servers