mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-06-04 19:25:32 +00:00
This commit introduces MCP server functionality to Meilisearch, enabling AI assistants and LLM applications to interact with the search engine through a standardized protocol. Key features: - Dynamic tool generation from OpenAPI specification - Full API coverage with automatic route discovery - SSE and HTTP POST endpoint support at /mcp - Integration with existing authentication system - Comprehensive test suite (unit, integration, e2e) - Optional feature flag (--features mcp) The MCP server automatically exposes all Meilisearch endpoints as tools that AI assistants can discover and use, making it easier to integrate Meilisearch into AI-powered applications. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
5.2 KiB
5.2 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Repository Overview
Meilisearch is a lightning-fast search engine written in Rust. It's organized as a Rust workspace with multiple crates that handle different aspects of the search engine functionality.
Architecture
Core Crates Structure
crates/meilisearch/
- Main HTTP server implementing the REST API with Actix Webcrates/milli/
- Core search engine library (indexing, search algorithms, ranking)crates/index-scheduler/
- Task scheduling, batching, and index lifecycle managementcrates/meilisearch-auth/
- Authentication and API key managementcrates/meilisearch-types/
- Shared types and data structurescrates/dump/
- Database dump and restore functionalitycrates/meilitool/
- CLI tool for maintenance operations
Key Architectural Patterns
-
Data Flow:
- Write: HTTP Request → Task Creation → Index Scheduler → Milli Engine → LMDB Storage
- Read: HTTP Request → Search Queue → Milli Engine → Response
-
Concurrency Model:
- Single writer, multiple readers for index operations
- Task batching for improved throughput
- Search queue for managing concurrent requests
-
Storage: LMDB (Lightning Memory-Mapped Database) with separate environments for tasks, auth, and indexes
Development Commands
Building and Running
# Development
cargo run
# Production build with optimizations
cargo run --release
# Build specific crates
cargo build --release -p meilisearch -p meilitool
# Build without default features
cargo build --locked --release --no-default-features --all
Testing
# Run all tests
cargo test
# Run tests with release optimizations
cargo test --locked --release --all
# Run a specific test
cargo test test_name
# Run tests in a specific crate
cargo test -p milli
Benchmarking
# List available features
cargo xtask list-features
# Run workload-based benchmarks
cargo xtask bench -- workloads/hackernews.json
# Run benchmarks without dashboard
cargo xtask bench --no-dashboard -- workloads/hackernews.json
# Run criterion benchmarks
cd crates/benchmarks && cargo bench
Performance Optimizations
# Speed up builds with lindera cache
export LINDERA_CACHE=$HOME/.cache/lindera
# Prevent rebuilds on directory changes (development only)
export MEILI_NO_VERGEN=1
# Enable full snapshot creation for debugging tests
export MEILI_TEST_FULL_SNAPS=true
Testing Strategy
- Unit tests: Colocated with source code using
#[cfg(test)]
modules - Integration tests: Located in
crates/meilisearch/tests/
- Snapshot testing: Using
insta
for deterministic testing - Test organization: By feature (auth, documents, search, settings, index operations)
Important Files and Directories
Cargo.toml
- Workspace configurationrust-toolchain.toml
- Rust version (1.85.1)crates/meilisearch/src/main.rs
- Server entry pointcrates/milli/src/lib.rs
- Core engine entry pointcrates/meilisearch-mcp/
- MCP server implementationworkloads/
- Benchmark workload definitionsassets/
- Static assets and demo files
Feature Flags
Key features that can be enabled/disabled:
- Language-specific tokenizations (chinese, hebrew, japanese, thai, greek, khmer, vietnamese)
mini-dashboard
- Web UI for testingmetrics
- Prometheus metricsvector-hnsw
- Vector search with CUDA supportmcp
- Model Context Protocol server for AI assistants
Logging and Profiling
The codebase uses tracing
for structured logging with these conventions:
- Regular logging spans
- Profiling spans (TRACE level, prefixed with
indexing::
orsearch::
) - Benchmarking spans
For indexing profiling, enable the exportPuffinReports
experimental feature to generate .puffin
files.
Common Development Tasks
Adding a New Route
- Add route handler in
crates/meilisearch/src/routes/
- Update OpenAPI documentation if API changes
- Add integration tests in
crates/meilisearch/tests/
- If MCP is enabled, routes are automatically exposed via MCP
Modifying Index Operations
- Core logic lives in
crates/milli/src/update/
- Task scheduling in
crates/index-scheduler/src/
- HTTP handlers in
crates/meilisearch/src/routes/indexes/
Working with Search
- Search algorithms in
crates/milli/src/search/
- Query parsing in
crates/filter-parser/
- Search handlers in
crates/meilisearch/src/routes/indexes/search.rs
Working with MCP Server
- MCP implementation in
crates/meilisearch-mcp/
- Tools are auto-generated from OpenAPI specification
- Enable with
--features mcp
flag - Access via
/mcp
endpoint (SSE or POST)
CI/CD and Git Workflow
- Main branch:
main
- GitHub Merge Queue enforces rebasing and test passing
- Benchmarks run automatically on push to
main
- Manual benchmark runs: comment
/bench workloads/*.json
on PRs
Environment Variables
Key environment variables for development:
MEILI_NO_ANALYTICS
- Disable telemetryMEILI_DB_PATH
- Database storage locationMEILI_HTTP_ADDR
- Server binding addressMEILI_MASTER_KEY
- Master API key for authentication