Skip to main content

mcp-notion-bridge

PyPI version Python versions License: MIT Downloads

Lightweight Model Context Protocol (MCP) bridge and hybrid sync engine connecting Notion workspaces with AI agents and vector RAG pipelines.

Stop serving obsolete data from static vector indices. mcp-notion-bridge implements an event-driven retrieval layer adhering to Anthropic's open Model Context Protocol (MCP). It dynamically intercepts volatile documentation updates from live Notion workspaces and fuses them with local vector stores (ChromaDB, Pgvector) and sparse BM25 search using Reciprocal Rank Fusion (RRF).


⚡ The Problem: The Stale Embeddings Crisis

Real-world enterprise documentation lives in collaborative workspaces like Notion. When teams update discount policies, compliance clauses, or fee structures:

  • The vector index is instantly obsolete: Embeddings do not auto-sync without expensive batch re-indexing.
  • Batch re-embedding is slow and costly: Processing millions of tokens on every minor edit causes write-locks, high API bills, and synchronization lag.
  • LLMs confidently hallucinate outdated terms: RAG pipelines retrieve stale chunks with high cosine similarity.
[Traditional RAG]
[User Query] ──> [Static Vector DB (Stale Chunks!)] ──> [LLM] ──> ❌ Outdated Policy Answer

🛡️ The Architecture: Live MCP Hybrid Retrieval

                             ┌──────────────────────────────────────────────┐
                             │       Live Notion Workspace (via MCP)        │
                             └──────────────────────┬───────────────────────┘
                                                    │
                                  [Live Volatile Chunks (Priority)]
                                                    │
[User Query] ──> [HybridMCPRetriever] ──────────────┼─────────────────────────┐
                        │                           │                         │
                        ▼                           ▼                         ▼
            [Live Notion MCP Stream]    [Dense ChromaDB Vectors]    [Sparse BM25 Lexical]
                        │                           │                         │
                        └───────────────────┬───────┴─────────────────────────┘
                                            ▼
                           [Reciprocal Rank Fusion (RRF k=60)]
                                            │
                                            ▼
                        [Zero-Staleness Context + Provenance]
                                            │
                                            ▼
                               [AI Agent / LangGraph Graph]

mcp-notion-bridge solves this with a multi-pass hybrid engine:

  1. Live MCP Interception: Checks active Notion pages over MCP before querying static indices.
  2. Dense Semantic Retrieval: Queries local ChromaDB or pgvector embeddings.
  3. Sparse Lexical Retrieval: Executes BM25 keyword matching for exact IDs, SKUs, and codes.
  4. Reciprocal Rank Fusion (RRF): Mathematically fuses candidate rankings with zero arbitrary hyperparameter weighting.

📦 Installation

pip install mcp-notion-bridge

Optional Extras (for ChromaDB and Rank-BM25):

pip install "mcp-notion-bridge[rag]"

Zero heavy dependencies. Pure Python with Pydantic v2 and HTTPX.


🚀 Quickstart in 4 Lines

import asyncio
from mcp_notion_bridge import HybridMCPRetriever

async def main():
    retriever = HybridMCPRetriever()
    result = await retriever.retrieve("What is the active cancellation policy?", top_k=3)
    
    print(f"Latency: {result.latency_ms} ms | Live Freshness: {result.is_fresh}")
    for doc in result.fused_results:
        print(f"[{doc.source.upper()}] (Score: {doc.score:.4f}) {doc.text[:100]}...")

asyncio.run(main())

🧩 LangGraph & Agentic Workflows

Integrate mcp-notion-bridge directly into your LangGraph state graph as an autonomous retrieval node:

from mcp_notion_bridge import HybridMCPRetriever
from typing import TypedDict, List

class AgentState(TypedDict):
    query: str
    context_chunks: List[str]
    is_live_notion: bool

retriever = HybridMCPRetriever()

async def retrieve_context_node(state: AgentState):
    result = await retriever.retrieve(state["query"], top_k=4)
    return {
        "context_chunks": [c.text for c in result.fused_results],
        "is_live_notion": result.is_fresh
    }

📐 Mathematical Formulation: Reciprocal Rank Fusion

Candidate chunks from heterogeneous sources (live Notion MCP $M$, dense vector search $D$, and sparse BM25 $S$) are merged using Reciprocal Rank Fusion:

$$\text{RRF}(d) = \sum_{m \in {M, D, S}} \frac{w_m}{k + r_m(d)}$$

Where:

  • $k = 60$ (standard smoothing constant preventing rank saturation).
  • $r_m(d)$ is the 1-based ordinal rank of document $d$ in retrieval system $m$.
  • $w_m = 1.25$ for live MCP streams (ensuring verified volatile changes override older static embeddings).

🖥️ Command-Line Interface (CLI)

mcp-notion-bridge includes a built-in terminal CLI:

# Inspect live Notion workspace via MCP
mcp-notion-bridge inspect "refund policy" --limit 3

# Run full hybrid retrieval with RRF
mcp-notion-bridge retrieve "overdue library fees" --top-k 5

# Benchmark in-flight RRF latency
mcp-notion-bridge benchmark

🧪 Running Unit Tests

git clone https://github.com/samjanjua6/mcp-notion-bridge.git
cd mcp-notion-bridge
pip install -e ".[dev]"
pytest

👤 Author & Research Citation

Engineered by Shaheer Ul Hassan (Muhammad Shaheer)
Agentic AI & Systems Engineer | Islamabad, Pakistan


📄 License

MIT License. Open-source for academic, enterprise, and personal development.

Metadata

Release files for mcp-notion-bridge 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mcp-notion-bridge 0.1.0
File Size Uploaded Provenance
mcp_notion_bridge-0.1.0.tar.gz 16.6 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for mcp-notion-bridge 0.1.0
File Interpreter ABI Platform
mcp_notion_bridge-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 30.8 kB

Release files / mcp_notion_bridge-0.1.0.tar.gz

Download URL mcp_notion_bridge-0.1.0.tar.gz
Size 16.6 kB
Tags Source
SHA-256 checksum
How to use checksums
e58062450d143ffcc98e59421a09048d6f1bd14186acc47f1b54ca3b699750c6
BLAKE2b-256 checksum
How to use checksums
fdd0cb93678a0250c068a8e2d6a2147e9138167a332a120ebf22afc24316b719
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Release files / mcp_notion_bridge-0.1.0-py3-none-any.whl

Download URL mcp_notion_bridge-0.1.0-py3-none-any.whl
Size 14.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cad10e59f65d10586367fdf451e5d84c00790cc0208eb7f2bd7e7a8b498859f1
BLAKE2b-256 checksum
How to use checksums
dbcd9700b19dec6783ce7e203d2560aeede1041bcb4a8bb299a0d14db78c9384
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Security for mcp-notion-bridge 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page