Skip to main content

Context Pager

A context-paging MCP tool that cuts agent token cost. Agents keep a tiny context window and pull only the pages they need — the way an OS pages memory.

  • compress_document — read one compressed page of a document instead of the whole file.
  • search_documents — find relevant documents (and silently recalled memory).
  • commit_to_long_term_memory — persist durable insights that resurface on later searches.
┌─────────────┐  MCP over HTTPS (bearer: pgr_agent_*)   ┌──────────────┐
│    Agent    │ ───────────────────────────────────────► │   RELAY      │
│ (Claude,    │  POST https://pager.duckdns.org/mcp      │ AWS t3.micro │
│  Cursor, …) │                                          │ dumb router  │
└─────────────┘                                          │ $0/mo, 0 ML  │
                                                         │ SQLite: keys │
                        WSS (handshake: pgr_bridge_*)    │ + usage rollup│
┌─────────────┐  JSON-RPC   ───────────────────────────► │              │
│   BRIDGE    │  wss://pager.duckdns.org/bridge          └──────────────┘
│   (laptop)  │ ◄───────────────────────────────────────
│ models +    │
│ sqlite-vec  │
└─────────────┘
   │ also serves localhost:8000/mcp (no auth, loopback only)
  • Relay (thin, AWS free tier): authenticates agent keys, rate-limits, and forwards tool calls to your live bridge over a persistent WSS channel. Zero ML, zero content storage — it never sees documents, only envelopes and daily usage rollups.
  • Bridge (on your laptop): owns the document library (sqlite-vec), embeddings (BGE-m3), compression (LLMLingua-2), PII masking (Presidio), long-term memory, and telemetry. It dials out to the relay.
  • Agent: any MCP client. Config is a single URL + bearer token (see CONNECTING_AGENTS.md).

Quick Start

Bridge (your laptop — owns your documents)

pip install "context-pager[bridge]"
pager bridge                       # preloads models, serves 127.0.0.1:8000/mcp

Local-only works with no keys. To relay through the internet, sign up and set the bridge key:

curl -X POST https://pager.duckdns.org/v1/signup   # returns agent_key + bridge_key
export PAGER_BRIDGE_KEY="pgr_bridge_..."           # PAGER_BRIDGE_WS_URL defaults to the relay
pager bridge

Manage documents and see cost savings:

pager docs add report.txt                          # copies + chunks + embeds
pager docs list | reindex <id> | remove <id>
pager stats                                        # tokens saved, cost saved

Agent (any MCP client)

Connect to https://pager.duckdns.org/mcp with Authorization: Bearer pgr_agent_... (or http://127.0.0.1:8000/mcp for local-only). Claude Code / Cursor / curl snippets are in CONNECTING_AGENTS.md. A complete reference agent is in examples/goldfish_agent/.

Relay (your own $0/mo server, optional)

If you don't want to use the shared relay, provision your own:

PAGER_DUCKDNS_DOMAIN=pager PAGER_DUCKDNS_TOKEN=... bash deploy/setup_relay.sh

See CONTEXT.md for the full architecture, tool contracts, configuration, and security model, and deploy/ for the relay provisioning script, systemd units, Caddyfile, and backup script.

Tools

All tools return a JSON envelope string (agent-friendly, never raises for recoverable conditions). Full contracts with examples live in CONTEXT.md.

Tool Purpose
compress_document(doc_id, page=1, focus_area=None, max_return_tokens=2048) Return one compressed, PII-masked page. Pages are canonical; focus_area re-ranks by relevance.
search_documents(query, top_k=10) KNN over chunk embeddings; best chunk per doc wins; best_page + recalled_insights included.
commit_to_long_term_memory(key, insights) Persist durable insights; recalled on later searches (cosine ≥ 0.78).

Testing

python -m pytest tests/          # unit + bridge↔relay + full E2E over real HTTP/WSS
python -m ruff check src tests

Opt-in real-model smoke tests: RUN_MODEL_TESTS=1 (not run in CI).

Known Limitations (v1)

  • Text/markdown/code only; PDFs/DOCX must be converted to text first.
  • Dense-only retrieval (no sparse/RRF).
  • Models run on your laptop; very large libraries need PAGER_LITE=true or a beefier box.
  • No admin UI; manage documents via pager docs.

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

context_pager-0.3.1.tar.gz (397.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

context_pager-0.3.1-py3-none-any.whl (32.3 kB view details)

Uploaded Python 3

File details

Details for the file context_pager-0.3.1.tar.gz.

File metadata

  • Download URL: context_pager-0.3.1.tar.gz
  • Upload date:
  • Size: 397.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for context_pager-0.3.1.tar.gz
Algorithm Hash digest
SHA256 6b113c1a511bb8035cc0535f8b024a17808d1d44e0132093b35260810d5f3d0f
MD5 e007c8b4863d41fcb5e1ac2735c7043c
BLAKE2b-256 08f7cc276cb2710175a8fab22609724273121e13f4631e6e5aa67426fc59c366

See more details on using hashes here.

File details

Details for the file context_pager-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: context_pager-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 32.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for context_pager-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c807965065e5fcde4a9e3067b4591cee03f4c2f485260f8f0c220eee2e618955
MD5 bf7c0c23157294746690b5f47b0bfdb2
BLAKE2b-256 6133e0d0dce29d72cdc802e3c7bbe8801502c52aa37f97fc5fa0746fe4d7b287

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page