AGENTS.md
Documents an MCP server for Cairo documentation with Gemini embeddings, Qdrant vector search, and four MCP tools.
What this file does
Documents an MCP server for Cairo documentation with Gemini embeddings, Qdrant vector search, and four MCP tools.
When to use it
- Setting up a Cairo documentation MCP server
- Replacing cairo-coder's RAG pipeline with a simpler stack
- Adding semantic search to an MCP server
- Understanding Gemini embedding requirements for MCP
Assumes this stack
AGENTS.md
This file provides guidance to agents when working with code in this repository.
Build & Run
- Build:
npm run build(compiles TypeScript todist/) - Dev mode:
npm run dev(runs source directly with tsx) - Test MCP:
npm run inspector(opens MCP inspector) - Generate embeddings:
npx tsx src/generate-embeddings.ts(one-time setup, requires Qdrant)
Architecture (Non-Obvious)
- MCP server:
src/index.ts- Stdio transport only, no HTTP - Embedding script:
src/generate-embeddings.ts- Standalone, run once - Documentation:
docs/- AI-summarized from cairo_coder_AI, not raw Cairo docs - Examples:
examples/- Full Scarb projects, not just .cairo files - Qdrant: Must be running on
localhost:6333for semantic search to work
Critical Dependencies
- Gemini API key required for embeddings (not OpenAI, despite what cairo-coder uses)
- Qdrant Docker container must be running before generating embeddings or using semantic search
- @google/genai SDK (not Google's older APIs)
- MCP SDK v1.20.1+ (uses stdio transport, not SSE)
MCP Tools (4 Total)
- get-cairo-docs - Keyword-based markdown search (fast, no embeddings)
- get-cairo-example - Returns full Cairo source code
- list-cairo-resources - Lists all available docs/examples
- semantic-search-cairo - Natural language search via Gemini embeddings + Qdrant (slower but more accurate)
Semantic Search Parameters (Simplified API)
Two parameters only:
score_threshold(0.0-1.0, default: 0.5) - Controls relevance cutoffmax_tokens(number, default: 50000) - Controls total output size
Automatic rounding (NEW):
- Each chunk = ~500 tokens (from size-based chunking)
max_tokensautomatically rounds up to nearest 500- Examples:
- 290 → 500 (minimum: 1 chunk)
- 750 → 1000 (2 chunks)
- 10000 → 10000 (20 chunks)
Why this works:
- No confusing
max_resultsvsmax_tokensdual system - Prevents fetching 100 results when only 10 fit in token budget
- Automatic optimization:
limit = Math.ceil(maxTokens / 500)
Key Gotchas
- Embedding dimension: MUST be 768 (not 3072) - normalized for cosine similarity accuracy
- Chunk size: MUST be 500 tokens (~2000 chars) - enforced in generate-embeddings.ts
- Chunking strategy: Size-based (not just header-based) - prevents massive sections
- File paths: Use relative paths from
__dirname(e.g.,../docs/cairo_book_summary.md) - Task type:
RETRIEVAL_DOCUMENTfor docs,RETRIEVAL_QUERYfor queries (Gemini API requirement) - Collection name: Hardcoded as
cairo-docsin both scripts - must match exactly - Score threshold: Higher = stricter (0.9 = nearly identical, 0.5 = moderate, 0.3 = loose)
- Token estimation: Character-based heuristic (1 token ≈ 4 chars) - conservative, no external tokenizer
Comparison to cairo-coder
This project intentionally differs from cairo-coder:
- No Docker (except external Qdrant)
- No PostgreSQL/pgvector (uses Qdrant instead)
- No HTTP API (MCP protocol only)
- No LLM for retrieval (just embeddings)
- Single API key (Gemini only, not OpenAI + Anthropic)
- Direct file access (no complex RAG pipeline)
Source Attribution
- Documentation extracted from KasarLabs/cairo-coder project (Python summarizer outputs)
- Architecture inspired by Upstash/context7 MCP server
- Built for Model Context Protocol (MCP) specification by Anthropic
What's inside
Build commands, architecture notes, 4 MCP tools, semantic search parameters, gotchas, and comparison to cairo-coder.
Change this for your project
- Replace
cairo-docswith your Qdrant collection name - Replace
../docs/cairo_book_summary.mdwith your documentation path - Replace
Gemini API keywith your own key - Replace
RETRIEVAL_DOCUMENTandRETRIEVAL_QUERYwith your Gemini task types
Where it goes
Save as AGENTS.md in your repository root. Read by Codex, Cursor and other agents that follow the AGENTS.md convention.
Worth borrowing
- Automatic chunk rounding to nearest 500 tokens simplifies max_tokens vs max_results confusion
- Single API key design reduces operational complexity compared to multi-provider setups
- Size-based chunking prevents oversized sections from header-only splitting
Related Documents
Browser-only development
Guides AI assistants on an Electron + React + TypeScript desktop app for browsing and organizing AI-generated images locally.
Claude Agents — Reference & Recommendations
Catalogues 40+ Claude agents and marketing skills for building a cat adoption charity landing page, with a ready-to-paste prompt and backend API reference.
Golden DKG Prototype -- Master Plan
Defines an 8-phase implementation plan for a Rust prototype of the Golden non-interactive DKG protocol using BLS12-381 and tokio.
Swarms Examples Index
Lists 60+ example scripts for building single and multi-agent systems with the Swarms framework, organized by category and use case.