Skip to main content
Glama

primarysource

A primary source is the text itself: answer from it, and say exactly where it is.

One package, many collections. The core is a sectioned-document model, a ref grammar, token-budgeted paging, a fixed result shape, readers, a full-text index, a CLI and an MCP server. Each collection is a subpackage behind an extra: rfc (the RFC series, moved in from rfclib), nist, usb, itu, zim, cve, and more. PLAN.md has the design and ROADMAP.md the open work.

pip install "primarysource[rfc,mcp]"
primarysource collections
primarysource mcp --collection rfc

Pre-alpha. It ships no document text: you fetch the sources yourself.

What works today

from primarysource.budget import page
from primarysource.model import Document, Section, Unit, span_hash
from primarysource.refs import RefGrammar
from primarysource.render import render

grammar = RefGrammar(r"(?:RFC|BCP|STD)\d+")
ref = grammar.parse("RFC9000§9.6¶2")          # Ref(doc='RFC9000', section='9.6', para=2)

document = Document("demo", "Demo", Unit.SENTENCE, (Section("1", "Scope", ("First.", "Second.")),))
section = document.section("1")
result = page(section.units, start=1, max_tokens=2000)
print(render(" ".join(result.units), {"cite": "Demo §1", "unit": document.unit, "span": span_hash("First.")}))

Module

What it does

primarysource.model

Document, Section, the declared Unit that ¶n counts, span_hash

primarysource.refs

RefGrammar: <doc>§<section>[#anchor][¶n] and <doc>:<first>-<last>, for a library's own document-id pattern

primarysource.budget

tokens, page: whole units up to a token budget, always making progress, with next_start

primarysource.render

body plus cite:, unit:, span:, next:, relaxed:, warning: footer lines in a fixed order

primarysource.errors

LibError(message, hint): an error that names its remedy

primarysource.home

resolve_home(app): $<APP>_HOME or the per-user data directory; atomic_write

Related MCP server: KSoR

What it does not do yet

It reads no file format, builds no index, has no command and serves nothing. No library depends on it.

Tests

python -m pytest -q from this directory. All tests use invented text.

Tool Schema Changelog

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

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • F
      license
      Not graded
      quality
      F
      maintenance
      Enables searching and researching document collections through hybrid semantic search and agentic research queries with grounded, cited answers. It allows users to list collections, scan document sections, and retrieve full Markdown content via MCP-compatible agents.
      46 npm
      -
    • F
      license
      Not graded
      quality
      C
      maintenance
      Serves a governed knowledge system of record over MCP, letting agents answer questions with citations drawn only from approved documents and explicitly decline when the record does not cover the question.
      -
    • A
      license
      Not graded
      quality
      B
      maintenance
      Provides MCP tools to search local document corpora with conservative semantic deduplication, source retention, and version/scope filtering, returning compact evidence packets with original passages and source IDs for agents.
      MIT
    • A
      license
      Not graded
      quality
      C
      maintenance
      Exposes a markdown knowledge base to MCP clients so they can search pages, fetch individual documents, and ask grounded questions that come back with numbered citations or a refusal. Retrieval is graded before answering, with a single query rewrite before giving up when nothing relevant is found.
      1
      MIT