RAG & MCP Engineering
A systems view of retrieval and tool integration: how to select context, expose capabilities, enforce permissions, structure outputs, evaluate grounding, and keep model behavior inside application boundaries.
Retrieval pipeline
Good RAG starts before the vector search call. Chunking, metadata, freshness, filtering, reranking, and source attribution all shape answer quality.
- Chunk around meaningful semantic boundaries
- Filter by tenant, product, policy, and freshness when relevant
- Use hybrid search when lexical precision matters
- Rerank before sending context to the model
Context selection
The model should receive the smallest useful context for the current step rather than every available document or conversation turn.
- Separate workflow state from long-term memory
- Summarize long conversations
- Prefer authoritative sources
- Do not let retrieved text override system or developer instructions
MCP & tool contracts
MCP standardizes how tools, resources, and context can be exposed, but the architecture principles remain the same with or without it.
- Clear tool name and description
- Typed input and output schemas
- Timeout and retry behavior
- Permission boundaries
- Structured errors and logs
Safety & permissions
Read operations and write operations should have different risk levels, with high-impact actions protected by deterministic checks and approval gates.
- Least-privilege credentials
- Validate identity and ownership
- Require confirmation for destructive or financial actions
- Never execute raw model-generated SQL or shell commands
Evaluation
Evaluate retrieval and tool traces, not just the final prose response.
- Retrieval hit rate
- Citation/source correctness
- Tool selection accuracy
- Argument validity
- Policy compliance
- Task completion and cost per successful task