Skip to main content

MCP extension for writing-context retrieval relying on RTFM

Project description

Surgical Context for Writing Agents

Stop giving your AI agent the entire manuscript to write one section. Give it the exact paragraphs, constraints, and dependencies it needs to succeed. No token bloat. No hallucinations.

Lightweight · Task-Focused · Extension · MIT


PyPI Version License: MIT Python MCP Powered by RTFM


Your writing agent is drowning in tokens.

You ask Claude or Cursor to "Write the methodology section." To give it context, you feed it your 50-page manuscript, your related works, and your notes. The agent gets overwhelmed by the global narrative, loses track of the specific hyper-parameters you wanted to include, and writes a generic, repetitive summary that reads like a high-school essay.

The bottleneck isn't the model's writing ability — it's the noise.

writing-context-rtfm fixes the noise. It is a lightweight MCP extension built on top of rtfm-ai. Instead of letting the agent grep freely, it acts as a gatekeeper. It takes the agent's task, queries the underlying RTFM index, aggressively filters out background noise, and packs only the essential and supporting source chunks into a tight, highly-focused prompt.

writing-context-rtfm pack \
  --task "Write the methodology section detailing dataset and quantization" \
  --target sections/methodology.tex \
  --budget 4000

3 seconds later, the agent receives a compact context pack containing exactly the paragraphs and key terms needed, alongside stylistic constraints for the target section. The agent writes perfectly.

Token budgets respected. Constraints enforced. Progressive disclosure over context dumps.


Installation & Onboarding

writing-context-rtfm is published on PyPI and runs as a Model Context Protocol (MCP) server.

1. Install the CLI & Server

You can install the package globally or in your virtual environment:

# Using uv (recommended)
uv tool install writing-context-rtfm

# Using pipx
pipx install writing-context-rtfm

2. Quick Project Onboarding

To integrate the server into your manuscript repository, run the following two commands:

Step A: Initialize configuration and editor rules

writing-context-rtfm init

This command non-destructively:

  • Creates a self-documenting .writing-context/config.yaml file template showing how to tune token budgets and role weights.
  • Appends the cache database path to your .gitignore.
  • Updates your local .mcp.json to register the MCP server automatically.
  • Adds Agent Rules of Thumb blocks into CLAUDE.md, AGENTS.md, and GEMINI.md to guide AI agents on retrieving context first and respecting LaTeX boundaries.

Step B: Auto-scaffold your section cards

writing-context-rtfm init-cards

This scans your workspace for LaTeX files, parses \input structures and references, and scaffolds your manuscript sections and dependency mappings in .writing-context/section_cards.yaml.


MCP Server Integration

1. Claude Desktop

Add this to your claude_desktop_config.json (on macOS: ~/Library/Application Support/Claude/claude_desktop_config.json):

{
  "mcpServers": {
    "writing-context-rtfm": {
      "command": "writing-context-rtfm",
      "args": [
        "serve"
      ]
    }
  }
}

2. Cursor IDE

  1. Open Cursor Settings (Cmd + ,).
  2. Navigate to Features > MCP and click + Add New MCP Server.
  3. Name: writing-context-rtfm
  4. Type: command
  5. Command: writing-context-rtfm serve

3. VS Code Extensions (Cline, Roo Code)

Update your MCP settings file (e.g., cline_mcp_settings.json):

{
  "mcpServers": {
    "writing-context-rtfm": {
      "command": "writing-context-rtfm",
      "args": [
        "serve"
      ]
    }
  }
}

4. Claude Code (Anthropic CLI Agent)

# Global configuration
claude mcp add --scope user --transport stdio writing-context-rtfm -- writing-context-rtfm serve

# Repository-local configuration
claude mcp add --scope local --transport stdio writing-context-rtfm -- writing-context-rtfm serve

The Core Philosophy: RTFM Retrieves, We Pack

Tool Role Action Output
rtfm-ai The Retrieval Layer Indexes everything, runs FTS/Semantic search, returns raw hits. 25 raw chunks
writing-context-rtfm The Curation Layer Filters noise, applies constraints, ranks by structural priority. 4 essential chunks

We do not replace or fork RTFM. We wrap it. RTFM is built to fetch memory. writing-context-rtfm is built to decide what is enough memory to write a specific section.


Features

1. Agent Self-Correction Loop

If the requested token budget is too small to fit the necessary target context, the packer returns a "status": "degraded" and appends a warning to the warnings list recommending a specific minimum budget:

  • Writing Packs (pack): To resolve this, call the tool with a larger token_budget of at least X.
  • Proofreading Packs (proofread-pack): To resolve this, call the tool with a larger max_tokens value of at least X.

AI client agents are instructed via the auto-injected guidelines to parse this warning, extract the recommended value X, and automatically retry the call with the new budget to get the missing context.

2. LaTeX Safety Checks

The extension automatically parses the target text and detects LaTeX math environments, macro calls, and cross-references (e.g., \ref{...}, \begin{equation} ... \end{equation}). It issues safety warnings to the AI writing agent containing the exact code patterns that must not be deleted or broken during edits, maintaining compilation safety.

3. SQLite Local Caching

To optimize token and response latency, generated context packs are hashed and cached locally in .writing-context/context_cache.sqlite. Cache keys are dynamically invalidated whenever the project configuration, section cards, or underlying RTFM indexes are updated.


The Section Cards Pattern

Writing agents need rules. We enforce them using a .writing-context/section_cards.yaml file.

version: 1
document:
  title: "TinyML Fault Detection"
sections:
  section_approach:
    title: "Proposed approach"
    path: "sections/03_approach.tex"
    key_terms: ["CNN", "quantization"]
    must_preserve:
      - "The train-test split is fixed and reproducible."
    avoid:
      - "real-time deployment claims"

When the agent asks for context to write section_approach, we:

  1. Expand the query: We don't just search the agent's prompt. We search the section title and key terms.
  2. Post-filter Avoids: If an RTFM result matches an avoid term, it is instantly discarded.
  3. Inject Constraints: The returned context pack explicitly feeds the must_preserve rules directly to the LLM.

[!IMPORTANT] Modular documents are required. This extension's noise-reduction algorithms heavily rely on the path defined in your section cards to perform "Target Boosts" and semantic scoping. If your entire manuscript is just a single monolithic main.tex or main.md file, the packer won't be able to distinguish the target section from background noise. Keep your writing modular (e.g., sections/01_intro.tex, sections/02_methodology.tex) for optimal results.


CLI Reference

# Initialize project config, gitignore, and editor rules
writing-context-rtfm init

# Scan workspace to scaffold section cards from LaTeX inputs and labels
writing-context-rtfm init-cards

# Run diagnostics health checks on databases and configuration files
writing-context-rtfm doctor

# Sync the underlying RTFM index
writing-context-rtfm sync

# Generate a context pack directly in the terminal
writing-context-rtfm pack \
  --task "Update the introduction" \
  --target sections/introduction.tex \
  --budget 4000

# Generate a proofreading context pack
writing-context-rtfm proofread-pack sections/abstract.tex --line-start 1 --line-end 10 --max-tokens 3000

# Start MCP Server
writing-context-rtfm serve

Where this fits

┌─────────────────────────────────┐
│       AI Agent / LLM Client     │  ← Execution (Cursor, Claude)
├─────────────────────────────────┤
│     writing-context-rtfm        │  ← Curation (Packs, Filters, Rules)
├─────────────────────────────────┤
│           rtfm-ai               │  ← Retrieval (Index, FTS, Semantic)
└─────────────────────────────────┘

Without the context packer, your agent retrieves 50 documents and hopes for the best. With it, the agent receives a surgically precise, prioritized briefing.

License

MIT License — use it, fork it, extend it.

Project details


Download files

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

Source Distribution

writing_context_rtfm-0.5.2.tar.gz (101.8 kB view details)

Uploaded Source

Built Distribution

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

writing_context_rtfm-0.5.2-py3-none-any.whl (53.2 kB view details)

Uploaded Python 3

File details

Details for the file writing_context_rtfm-0.5.2.tar.gz.

File metadata

  • Download URL: writing_context_rtfm-0.5.2.tar.gz
  • Upload date:
  • Size: 101.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for writing_context_rtfm-0.5.2.tar.gz
Algorithm Hash digest
SHA256 60cc3e3ef77de8252038f2beecdec798d4a697f5218fb2a947879f4c26ee9f47
MD5 a2ff6e3894d7012092e07eba8d43a9c7
BLAKE2b-256 2b1cab27a3a969f526ddd319f0633118a75792e5160845276c49035c0370da32

See more details on using hashes here.

Provenance

The following attestation bundles were made for writing_context_rtfm-0.5.2.tar.gz:

Publisher: publish.yml on joaocarlos/writing-context-rtfm

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file writing_context_rtfm-0.5.2-py3-none-any.whl.

File metadata

File hashes

Hashes for writing_context_rtfm-0.5.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3a35f4db092a330c180710cb4341fd728a59cf27440bac2d6dccb71da1b2a73f
MD5 38e357f3a317a4e8ac1b0b46eae040aa
BLAKE2b-256 405458ff089ffe7b303665ac40227a0a8b2389148a1e32c432f9c3fb31aec518

See more details on using hashes here.

Provenance

The following attestation bundles were made for writing_context_rtfm-0.5.2-py3-none-any.whl:

Publisher: publish.yml on joaocarlos/writing-context-rtfm

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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