This document explains how CiteClaw works internally, with focus on execution flow, module boundaries, and design decisions.
CiteClaw has two runtime faces:
- CLI orchestrator (
scripts/citeclaw.js): one-shot commands (cite,cite-pdf,fetch-pdf,batch, etc.) and MCP stdio server mode. - HTTP service (
server.js+app.js): Citoid-compatible API endpoints used by CLI flows.
Both faces share the same core citation pipeline in lib/.
At a high level, each request follows this chain:
- Input normalization: classify DOI / URL / arXiv / local PDF and sanitize edge cases.
- Source acquisition: pull metadata from web pages, APIs, or PDF signal extraction.
- Translation and enrichment: map raw metadata into Zotero-like item schema.
- Export formatting: convert normalized item into requested format (
bibtex,mediawiki, CSL output).
Core modules:
lib/CitoidService.js: top-level orchestration and fallback strategy.lib/Scraper.js: webpage metadata extraction (HTML/metadata translators).lib/Exporter.js: schema normalization + output mapping.lib/ZoteroService.js: Zotero translator interaction.lib/CitoidRequest.js: HTTP request behavior and cookie handling.
citeclaw mcp exposes the same capabilities over JSON-RPC framing (Content-Length over stdio).
Implemented MCP methods:
initializepingtools/listtools/call
Tool handlers are thin adapters that invoke existing CLI internals:
citecite_pdffetch_pdfopenurl_resolve
This avoids duplicate business logic: MCP and CLI produce consistent behavior.
Runtime state is local and explicit:
.local/state: sync stamps and runtime markers..local/cache: response/PDF cache metadata and files..local/translators,.local/styles: merged translator/style runtime view.
Caching is key-based with TTL (cache-meta.json) to reduce repeated network/PDF resolution.
The repository vendors required upstream assets under vendor/ (e.g., Zotero translators, styles).
Principle: user should only need to clone/pull this repository and run commands; no extra third-party repo setup should be required.
Main latency sources are network fetches and PDF probing. The CLI exposes tuning knobs via environment variables (timeouts, concurrency, probe size, cache TTL), enabling controlled trade-offs between throughput and completeness.