# KB-MCP Server: Technical Deep Dive
**Author**: Matrix Agent
---
## 1. MCP Protocol Overview
Model Context Protocol (MCP) is an open protocol that standardizes how AI models interact with external tools and data sources.
### Protocol Layers
| Layer | Purpose | Implementation |
|-------|---------|----------------|
| **Transport** | Message delivery | stdio, SSE, WebSocket |
| **Protocol** | Request/response | JSON-RPC 2.0 |
| **Schema** | Validation | Zod schemas |
| **Tools** | Business logic | Your handlers |
---
## 2. Embedding Strategy
### Current: Hash-Based (Demo)
- Dimension: 128
- Method: Word hashing + frequency
- Normalization: L2
### Production Options
- OpenAI text-embedding-3-small (1536 dims)
- Ollama nomic-embed-text (768 dims)
- Cohere embed-v3 (1024 dims)
---
## 3. Similarity Search
- **Algorithm**: Cosine similarity via dot product
- **Current**: Brute-force O(n)
- **Scale options**: HNSW, FAISS, vector DBs
---
## 4. Storage Options
| Option | Use Case |
|--------|----------|
| JSON file | <10K docs, simple |
| SQLite + vss | 10K-100K docs |
| Chroma | Easy vector DB |
| pgvector | Production scale |
---
## 5. Production Checklist
1. Swap hash embeddings for real ones
2. Use vector database for storage
3. Add document chunking
4. Implement hybrid search
5. Add authentication
---
## Performance
| Operation | 1K docs | 10K docs |
|-----------|---------|----------|
| Ingest | 2ms | 5ms |
| Query | 5ms | 45ms |
| List | 1ms | 10ms |