This is a submission for the Sanity Challenge, Path One: Ship an Agent That Queries Real Content
What I Built
CanonKeeper is an AI-powered Fictional Universe Lore & Canon Resolution Engine.
When building expansive fictional universes (fantasy novels, sci-fi series, tabletop RPGs, or gaming franchises), lore accumulated over years frequently suffers from retcons, timeline contradictions, bardic folklore myths, and multi-hop custody chains. Traditional keyword search fails when an early edition book claims a commander entered a citadel in 734, but a later primary garrison ledger signed by the commander proves he remained at a northern outpost until 735.
CanonKeeper solves this by storing structured lore documents in Sanity CMS and running an intelligent Lore Verification Agent that:
- Queries atomic claims, source documents, characters, events, and locations via Sanity GROQ & MCP.
- Applies Source Authority Hierarchy Weighting (
PRIMARY_CANON>OFFICIAL_SECONDARY>REFERENCE>COMMUNITY). - Automatically detects and resolves Timeline Retcons (e.g., 1st Edition Chronicles vs. Imperial Garrison Ledgers & Revised Edition).
- Performs Multi-Hop Evidence Deduction to trace artifact possession and event chains across dates.
- Renders an Interactive SVG Evidence Graph mapping nodes (
Question,Claim,Source,Verdict) and directed relationship edges (retrieves,supported_by,contradicts,supersedes,resolves_to).
Demo
Watch the complete video walkthrough of CanonKeeper in action:
Video Link: https://youtu.be/Qoc_rMhq9z4
Code
Check out the full open-source codebase on GitHub:
🐙 GitHub Repository: https://github.com/scha54/Sanity-MCP-Hackathon
How I Used Sanity
Sanity served as the structured graph foundation for CanonKeeper's knowledge base.
1. Structured Schema Modeling
I designed 5 custom Sanity document schemas:
-
claim: Represents atomic lore facts with subject-predicate-object triples,sourcereference,canonStatus(CANON,RETCONNED,DISPUTED,AMBIGUOUS), timeline markers, confidence scores, and reference arrays forcontradicts,corroborates, andsupersedes. -
source: Documents withsourceType(CHRONICLE,MANUSCRIPT,BARDIC_SONG,LEDGER),edition,publicationDate,authorityLevel, andsupersedes/supersededByreferences. -
character: Character entities with aliases, descriptions, first appearance references, and typed relationships. -
event: Chronological events with location references, participants, and preceding/following event links. -
location: World locations linked to associated characters and events.
2. Sanity Model Context Protocol (MCP) Integration
I configured the Sanity Model Context Protocol (MCP) server integration (https://mcp.sanity.io) in .agents/mcp_config.json. This enables AI agents to inspect schema types and query content via standardized MCP tool calls.
3. GROQ Evidence Queries & Resolution Logic
The agent retrieves evidence from Sanity using GROQ queries:
*[_type == "claim"]{
_id,
statement,
subject,
predicate,
object,
"sourceId": source._ref,
sourceLocation,
canonStatus,
timeline,
confidence,
"contradictIds": contradicts[]._ref,
"corroborateIds": corroborates[]._ref,
"supersedeIds": supersedes[]._ref,
notes
}
What the agent does with retrieved Sanity content:
- Entity & Intent Recognition: Extracts entities (e.g., Arin Shadowstrider, Valemont Citadel) and timeframe constraints from user queries.
-
Graph Traversal: Fetches matched claims, resolves linked
sourcedocument authority levels, and expandscontradicts/supersedesgraph nodes. -
Authority & Retcon Resolution: Overrides outdated claims when a higher authority document (e.g.,
PRIMARY_CANONrevised ledger) supersedes an earlierOFFICIAL_SECONDARYaccount. - Interactive Visualization: Constructs node-link network graphs displaying claims, sources, and canon verdicts.
Sanity Project Details
-
Sanity Project ID:
demo-universe(Local fallback & Sanity dataset ready) -
Dataset:
production -
Seeding Script: Included at
scripts/seed-sanity.tsto populate Sanity CMS datasets using@sanity/client.
Top comments (0)