This is the canonical standard for accessing documentation via MCP Local RAG.
Every repository context file should reference this document rather than duplicating these rules.
NEVER EVER use the Read tool on documentation files (PDF, DOCX, etc.)
If you find yourself about to use Read tool on a file in mcp-docs/, STOP and follow this workflow instead:
- Check if MCP is configured:
cat ~/.claude.json | grep "local-rag" - If NOT configured → Run
cd mcp-docs/claude-code && ./setup.shand tell user to restart - If configured → Use
mcp__local-rag__query_documentsinstead
BEFORE attempting to answer questions about specifications/documentation:
cat ~/.claude.json | grep "local-rag"If this returns empty, run setup automatically (see Step 5 below).
Each repository's root CLAUDE_CONTEXT.md defines these variables:
{{REPO_ROOT}}: Absolute path to repository root (e.g.,/Users/username/repos/my-repo){{DOCS_DIR}}: Relative path to documentation directory from repo root (e.g.,mcp-docs/){{DOC_TYPE}}: Type of documentation (e.g., "API specifications", "Technical manuals"){{SETUP_SCRIPT}}: Path to setup script (typicallymcp-docs/claude-code/setup.sh){{MCP_EXTERNAL_PATH}}: (Optional) External documentation path if docs are stored outside the repository
Example substitution:
When docs say: {{REPO_ROOT}}/{{DOCS_DIR}}/filename.pdf
You use: /Users/username/repos/my-repo/mcp-docs/filename.pdfNEVER use the Read tool on documentation files (PDF, DOCX, etc.). ALWAYS use MCP Local RAG tools instead.
❌ WRONG:
Read tool: /path/to/documentation.pdf
Read tool: /path/to/specification.docx✅ CORRECT:
mcp__local-rag__query_documents: "query about specific topic"Why?
- Binary files (PDF, DOCX) - Read tool cannot parse them properly
- Text files (TXT, MD, HTML) - MCP Local RAG provides better semantic search
- MCP Local RAG provides semantic search across all ingested documentation
- Query results are context-aware and return relevant excerpts
- Ingestion preprocesses files into searchable chunks with embeddings
Before attempting to access documentation, verify MCP Local RAG is set up:
# Check if MCP server is configured
cat ~/.claude.json | grep "local-rag"If not configured, proceed to Step 5 (Setup).
Ask yourself:
- Does the user's question require authoritative {{DOC_TYPE}} information?
- Is this information likely to be in the documentation (not in code)?
- Can I answer from code/context alone?
Examples that need documentation:
- "What are the field definitions for [specific format]?"
- "What are the requirements for [specific specification]?"
- "Explain the [technical standard] implementation"
Examples that don't need documentation:
- "How does this function work?" (read the code)
- "What's the bug in this code?" (analyze the code)
- "Refactor this module" (pure code task)
Use mcp__local-rag__query_documents with a specific, well-formed query:
mcp__local-rag__query_documents(
query: "specific topic or question",
limit: 10 # Adjust based on expected result size: 5 for precision, 10 for balance, 20 for broad exploration
)Query Best Practices:
- Be specific: "record format fields" not "file format"
- Include relevant identifiers: "authentication flow requirements"
- Use technical terms from the domain
- If results are poor, try alternate phrasing
Interpreting Results:
- score < 0.3: Highly relevant, use with confidence
- score 0.3-0.5: Moderately relevant, verify context
- score > 0.5: Low relevance, may not be useful
- No results: Documentation may not cover this topic, or it's not ingested yet
If you get no relevant results (or user reports documentation is missing):
A. Check what's currently ingested:
mcp__local-rag__list_filesB. Check what documentation exists in the repository:
find {{DOCS_DIR}} -type f \( -name "*.pdf" -o -name "*.docx" -o -name "*.txt" -o -name "*.md" -o -name "*.html" \) -not -path "*/claude-code/*"C. If documentation exists but isn't ingested:
Automatic ingestion (proactive):
mcp__local-rag__ingest_file(
filePath: "{{REPO_ROOT}}/{{DOCS_DIR}}/filename.pdf"
)Note: Always use absolute paths for ingestion. Construct them as:
{{REPO_ROOT}}/{{DOCS_DIR}}/filename.extSupported formats: PDF, DOCX, TXT, Markdown (.md), HTML
D. Ask user for module mapping: After ingesting, ask: "I've ingested [filename]. Which module(s) or code sections is this documentation relevant to?"
E. Update module context(s): Add an "External Documentation" section to relevant module CLAUDE_CONTEXT.md files:
## External Documentation
> **Documentation Access**: See `mcp-docs/claude-code/MCP_STANDARD_RULES.md` for complete MCP workflow
**Available [topic] specifications** (listed for auto-ingestion):
- **[filename-without-extension]**: [Brief description of contents]
**Query examples:**
- "[Example query relevant to this module]"
- "[Another example query]"F. If documentation doesn't exist at all: Inform the user that the documentation needs to be added to {{DOCS_DIR}}/ before it can be used.
If MCP Local RAG is not configured, AUTOMATICALLY run the setup:
A. Inform the user and run setup: Tell the user: "MCP Local RAG is not configured. I'll run the setup script now."
Then run:
cd {{REPO_ROOT}}/mcp-docs/claude-code && ./setup.shB. After setup completes, instruct the user: "Setup is complete! Please restart Claude Code completely (exit and relaunch) for the MCP server configuration to take effect. After restarting, ask your question again and I'll be able to query the documentation."
C. DO NOT attempt to query documentation until after restart - it will not work.
Solution: Run setup script and restart Claude Code (Step 5 above)
Solution: Verify file path is absolute and file exists:
ls -la {{REPO_ROOT}}/{{DOCS_DIR}}/filename.pdfSolution:
- Check if file is ingested:
mcp__local-rag__list_files - Try alternate query phrasing
- Verify documentation actually contains the information
Solution:
- Refine query to be more specific
- Check if correct documentation is ingested
- May indicate information isn't in documentation
- Start broad, then narrow: "authentication" → "OAuth token validation flow"
- Include context: "error code 400 handling for API requests"
- Use exact terminology from the domain
- Reference specific sections if known: "section 4.2 authentication flows"
- Always check the
scorefield - Cross-reference multiple results for confirmation
- If unsure, query again with refined terms
- Don't assume low-score results are correct
- Ingest documentation proactively when detected (don't wait for user request)
- Update module contexts after ingesting to create self-documenting system
- Re-ingest if documentation is updated (use same filePath to replace)
- Keep ingested documentation in sync with repository files
- Only mention documentation access in module contexts where it's truly needed
- Use the standard "External Documentation" format for consistency
- List 2-4 relevant query examples specific to each module
- Reference this file rather than duplicating rules
User asks a question
├─ Can be answered from code? → Read code, answer directly
│
├─ Requires {{DOC_TYPE}} info?
│ ├─ MCP configured? (check ~/.claude.json)
│ │ ├─ No → Run setup automatically (Step 5), then tell user to restart
│ │ └─ Yes → Continue
│ │
│ ├─ Query documentation (Step 3)
│ │ ├─ Good results (score < 0.3)? → Use results
│ │ └─ No results / poor results?
│ │ ├─ Check what's ingested (list_files)
│ │ ├─ Check what exists (find files)
│ │ ├─ Ingest if needed (Step 4)
│ │ └─ Query again
│ │
│ └─ Documentation missing entirely? → Inform user
│
└─ General question? → Answer normallyKey Points:
- Never Read files directly - always use MCP Local RAG tools
- Check MCP setup first - verify
~/.claude.jsonhas local-rag server - Auto-run setup if missing - run
setup.shautomatically, then tell user to restart - Query before ingesting - documentation might already be loaded
- Use absolute paths - construct as
{{REPO_ROOT}}/{{DOCS_DIR}}/filename.pdf - Interpret scores - < 0.3 is good, > 0.5 is questionable
- Update module contexts - create self-documenting system by adding External Documentation sections
- Be proactive - detect new files and ingest automatically, then ask user for module mapping
- Reference this file - don't duplicate these rules in module contexts
When in doubt: Query first, ingest if needed, setup if missing.