Skip to main content
Glama

Apollo β€” Anti-Poison & Anti-Hallucination Multi-Source Research MCP Server

CI/CD License: GPLv3 Python 3.11 Tests MCP Cost

Apollo is a standalone, production-grade Model Context Protocol (MCP) server engineered with a Dual-Pillar Defense: protecting AI agents from context poisoning (prompt injection & adversarial attacks) and retrieval-induced hallucinations (context overload & "Lost-in-the-Middle") across academic papers (arXiv, Semantic Scholar), open-source repositories (GitHub), Wikipedia encyclopedia, and web search. Built with $0 external API fees in mind.


πŸ›οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        Apollo MCP Server (Standalone)                  β”‚
β”‚                                                                        β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚   β”‚ 1. Multi-Source Ingestion & Tool Capability RAG Indexer        β”‚   β”‚
β”‚   β”‚    β”œβ”€ arXiv Atom API (100% Free / Public XML parser)           β”‚   β”‚
β”‚   β”‚    β”œβ”€ Semantic Scholar Graph API (Free Tier Public Endpoint)   β”‚   β”‚
β”‚   β”‚    β”œβ”€ GitHub REST API (Public Repos & Code Search)             β”‚   β”‚
β”‚   β”‚    β”œβ”€ Wikipedia API (100% Free / Foundational Concepts)        β”‚   β”‚
β”‚   β”‚    └─ DuckDuckGo Fallback Search (Zero API Keys)               β”‚   β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚                                   β”‚                                    β”‚
β”‚                                   β–Ό                                    β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚   β”‚ 2. Context Sanitization & Anti-Poisoning Layer (The Filter)    β”‚   β”‚
β”‚   β”‚    β”œβ”€ Prompt Injection Scanner (Adversarial regex & redaction) β”‚   β”‚
β”‚   β”‚    β”œβ”€ Invisible Unicode & BiDi Override Stripper               β”‚   β”‚
β”‚   β”‚    β”œβ”€ LaTeX & Markdown Normalizer (Preserves Math Blocks)      β”‚   β”‚
β”‚   β”‚    └─ Noise Reducer (Strips bibliographies & code licenses)    β”‚   β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚                                   β”‚                                    β”‚
β”‚                                   β–Ό                                    β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚   β”‚ 3. Guardrail RAG & Relevance Reranker                          β”‚   β”‚
β”‚   β”‚    β”œβ”€ Zero-Cost Bag-of-Words & Okapi BM25 CPU Indexer          β”‚   β”‚
β”‚   β”‚    β”œβ”€ FlashRank Ultra-Fast CPU Cross-Encoder (<25ms latency)   β”‚   β”‚
β”‚   β”‚    └─ Grounded Snippet Packer (Secure XML Enclosure + Citationsβ”‚   β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚                                   β”‚                                    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                    β–Ό
       Exposes Clean Tools to AI Agents / Claude / Cursor / Antigravity:
       β€’ `search_academic_papers(query, year_start, year_end, min_citations, top_k)`
       β€’ `fetch_paper_deep_context(arxiv_id, max_tokens)`
       β€’ `search_repo_implementations(topic, language, min_stars, top_k)`
       β€’ `search_wikipedia(query, max_results)`
       β€’ `fallback_web_search(query, max_results)`
       β€’ `match_tools_for_query(query, max_tools)`
       β€’ `unified_research_context(query, top_k)`

Related MCP server: Crawl4AI+SearXNG MCP Server

⚑ Zero-Cost Design

Apollo was designed specifically for students and researchers:

  • Zero API Costs: arXiv and DuckDuckGo require no API keys. Semantic Scholar and GitHub run on free public rate limits.

  • Zero Embedding/Vector Database Costs: Uses pure Python Okapi BM25 and FlashRank CPU Cross-Encoder (ms-marco-TinyBERT-L-2-v2) running directly in RAM with <25ms CPU latency.

  • Rate Limit Caching: Integrated disk and memory caching (diskcache) to respect public rate limits.


πŸš€ Quickstart

1. Installation

git clone https://github.com/Parth-Dhola/Apollo-AntiPoison-AntiHallucination-Research-MCP.git
cd Apollo-AntiPoison-AntiHallucination-Research-MCP

# Create conda environment
conda create -n apollo python=3.11 -y
conda activate apollo

# Install dependencies
pip install -r requirements.txt
pip install -e .

2. Standalone Tool Selector CLI

Test query intent classification directly from the command line:

python -m apollo.router.tool_selector "How to implement LoRA linear layer in PyTorch?"

Output:

============================================================
 Apollo Tool Selector & Intent Router
============================================================
Query:             How to implement LoRA linear layer in PyTorch?
Predicted Intent:  CODE_IMPLEMENTATION
Confidence:        95%
Keywords Matched:  pytorch, implementation, implement
Recommended Tools: search_repo_implementations, fallback_web_search
Reasoning:         Code implementation query matching keywords: pytorch, implementation, implement
============================================================

3. Run MCP Server

Local Stdio Mode (Claude Desktop / Cursor / Antigravity):

python -m apollo.main --transport stdio

HTTP / SSE Server Mode (Docker / EC2 Microservice):

python -m apollo.main --transport sse --port 8080

πŸ›‘οΈ Dual-Pillar Defense Architecture

Apollo solves the two fundamental failure modes of AI Agent retrieval: Security Hijacking (Context Poisoning) and Model Hallucination (Context Overload).

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                          APOLLO DUAL-PILLAR SHIELD                     β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ PILLAR 1: Security Firewall       β”‚ PILLAR 2: Anti-Hallucination Guard β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ β€’ Prompt Injection Scanner        β”‚ β€’ Adaptive Tool Gating (Tool RAG)  β”‚
β”‚ β€’ Invisible Unicode Stripper      β”‚ β€’ Anti-Context Bloat Pruning       β”‚
β”‚ β€’ LaTeX / Markdown Normalizer     β”‚ β€’ "Lost-in-the-Middle" Prevention  β”‚
β”‚ β€’ Hardened XML Isolation Tags     β”‚ β€’ Hard Token Budgeting (<2500 ch)  β”‚
β”‚ β€’ Academic Noise / License Strip  β”‚ β€’ FlashRank Cross-Encoder Precisionβ”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

1. Pillar 1: Anti-Poisoning & Security Guardrails

Apollo ensures context retrieved from external sources is safe before reaching your LLM:

  • Prompt Injection Redaction: Detects and neutralizes prompt override attempts (ignore previous instructions, system override, <<SYS>>, <|im_start|>).

  • Invisible Unicode Stripping: Removes zero-width spaces (\u200B), BiDi overrides (\u202E), and hidden character exploits.

  • Hardened XML Encapsulation: Encloses external context in <untrusted_academic_context> tags with explicit provenance metadata.

2. Pillar 2: Anti-Hallucination & Context-Overload Defense

Dumping too much unstructured search text into an LLM causes the "Lost-in-the-Middle" phenomenon (Stanford / Liu et al.) and leads to Retrieval-Induced Hallucinations. Apollo prevents this through:

  • Adaptive Tool Gating: The Tool RAG Indexer evaluates semantic fit and prunes away unneeded tools (e.g., skips Wikipedia & Web when arXiv matches), preventing redundant multi-source flooding.

  • Strict Score Thresholding: Prunes any candidate snippet whose relevance score falls below the cutoff threshold, eliminating distractor noise.

  • Hard Token Budgeting: Enforces a strict 2,500-character context budget to preserve LLM attention density and prevent token bloat.


πŸ›οΈ Source Authority & Credibility Hierarchy

Apollo prevents unverified or crowd-sourced summaries from displacing peer-reviewed science:

Tier

Source

Authority Weight

Role in Research Queries

Tier 1

arXiv & Semantic Scholar

1.00x

Primary Ground Truth: Peer-reviewed proofs, theorems, SOTA benchmarks.

Tier 2

GitHub Repos

0.90x

Verified Code: Runnable models, CUDA kernels, PyTorch modules.

Tier 3

Wikipedia

0.65x

Secondary Encyclopedia: Definitions & rate-limit safety net (Deprioritized for research).

Tier 4

DuckDuckGo

0.55x

General Web: Fallback for news and release notes.


🐳 Docker & Compose

Run Apollo in Docker:

docker compose up -d

Check health:

curl http://localhost:8080/sse

πŸ§ͺ Testing

Run test suite with coverage:

pytest tests/ -v --cov=src/apollo --cov-report=term-missing

πŸ”— Python SDK & Agent Integration

To call Apollo directly in your AI agentic workflows or Python scripts:

import asyncio
from apollo.server.mcp_server import create_mcp_server

async def get_clean_research_context(query: str):
    server = create_mcp_server()
    tool = await server.get_tool("unified_research_context")
    result = await tool.run({"query": query, "top_k": 3})
    return result.content[0].text

# Run
context = asyncio.run(get_clean_research_context("FlashAttention-2 forward backward pass"))
print(context)

πŸ“œ License

Licensed under the GNU General Public License v3.0 or later (GPL-3.0-or-later).

All derivative software and modifications must remain open-source under GPLv3. See the LICENSE file for the full license text.

Available Tools

6 tools
fetch_paper_deep_contextFetch Paper Deep ContextA

Fetch structured, sanitized abstract and detailed technical context for a specific arXiv ID. Normalizes LaTeX equations and neutralizes any prompt injection payloads.

Inputs: arxiv_id (required), max_tokens. Returns: result

match_tools_for_queryMatch Tools For QueryB

RAG over Tool Capabilities: Evaluates semantic capability fit to pick ONLY necessary tools, pruning irrelevant tools to prevent token bloat and context overload.

Inputs: query (required), max_tools. Returns: result

search_academic_papersSearch Academic PapersA

Search peer-reviewed papers and preprints across arXiv and Semantic Scholar. Returns sanitized paper abstracts with publication years, citation counts, and authors.

Inputs: query (required), top_k, year_end, year_start, +1 more. Returns: result

search_repo_implementationsSearch Repo ImplementationsB

Search verified open-source GitHub repositories for code implementations and architectural patterns. Strips license boilerplate and formats clean implementation snippets.

Inputs: topic (required), top_k, language, min_stars. Returns: result

unified_research_contextUnified Research ContextA

End-to-end multi-source research context pipeline with Tool Capability RAG & Token Budgeting.

  1. RAG-selects ONLY the top 1-2 optimal tools based on semantic capability match.

  2. Prunes unneeded tools to prevent API waste and context overload.

  3. Sanitizes all retrieved snippets and removes prompt injection payloads.

  4. Cross-encoder reranks on CPU and returns bounded, dense grounded context.

Inputs: query (required), top_k. Returns: result

Tool Schema Changelog

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

Loading tool schema changelog…

    TDQS

    B3.4/5.0

    Scored across 6 tools

    Disambiguation3/5

    The source-specific search tools are clearly distinct, but match_tools_for_query and unified_research_context both describe RAG-based tool selection and pruning, creating overlap in purpose. unified_research_context also partially subsumes the direct search tools, so boundaries are not fully clean.

    Naming Consistency3/5

    Most names use lower_snake_case and a search/fetch style, but the convention is inconsistent: fallback_web_search and unified_research_context are noun/adjective phrases rather than verb-first names. match_tools_for_query adds a prepositional construct, so the set doesn't follow a single predictable pattern.

    Tool Count4/5

    Six tools is a reasonable size for a multi-source research server. However, the set is slightly redundant because match_tools_for_query duplicates part of unified_research_context's functionality, so not every tool is strictly necessary.

    Completeness4/5

    The server covers academic search, deep paper context, code repository search, web fallback, and an end-to-end pipeline, which is solid for its stated purpose. Minor gaps remain, such as fetching papers by DOI or Semantic Scholar ID, but they are not blocking for typical research workflows.

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      Not graded
      maintenance
      Enables hybrid web search and intelligent content extraction, combining semantic search with documentation-optimized reading that strips noise and returns clean, token-efficient context for AI agents.
      2
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables AI agents to search the web, crawl websites, and perform intelligent RAG queries with semantic search capabilities. Includes integrated private search engine, vector database storage, and optional knowledge graph for AI hallucination detection in code repositories.
      1
      MIT
    • A
      license
      Not graded
      quality
      Not graded
      maintenance
      Provides AI agents with a comprehensive web intelligence stack including crawling, private search via SearXNG, and intelligent RAG capabilities for focused content extraction. It supports advanced features like semantic vector search and knowledge graph integration for code validation to enhance AI performance and reliability.
      MIT
    • F
      license
      Not graded
      quality
      C
      maintenance
      Provides AI agents and RAG pipelines with production-grade web search, deep research, news, academic, extraction, crawling, and source verification tools. Enables citation-anchored, deduplicated, fresh, and security-hardened evidence gathering from across the web.
      -