Skip to content

Commit fdb41cd

Browse files
tpayetclaude
andcommitted
Add comprehensive CLAUDE.md documentation
- Document modular manager architecture and MCP integration patterns - Include complete development commands for setup, testing, and code quality - Add GitHub Actions integration documentation for Claude Code workflow - Document testing strategies and tool simulation approaches - Update Black version requirement to match current dependencies 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent a54dbfb commit fdb41cd

File tree

1 file changed

+169
-0
lines changed

1 file changed

+169
-0
lines changed

CLAUDE.md

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
This is a **Model Context Protocol (MCP) server** for Meilisearch, allowing LLM interfaces like Claude to interact with Meilisearch search engines. The project implements a Python-based MCP server that provides comprehensive tools for index management, document operations, search functionality, and system monitoring.
8+
9+
## Development Commands
10+
11+
### Environment Setup
12+
```bash
13+
# Create virtual environment and install dependencies
14+
uv venv
15+
source .venv/bin/activate # On Windows: .venv\Scripts\activate
16+
uv pip install -e .
17+
18+
# Install development dependencies
19+
uv pip install -r requirements-dev.txt
20+
```
21+
22+
### Testing
23+
```bash
24+
# Run all tests
25+
python -m pytest tests/ -v
26+
27+
# Run specific test file
28+
python -m pytest tests/test_mcp_integration.py -v
29+
30+
# Run tests with coverage
31+
python -m pytest --cov=src tests/
32+
33+
# Run integration tests (requires running Meilisearch)
34+
python -m pytest tests/test_mcp_integration.py -v
35+
```
36+
37+
### Code Quality
38+
```bash
39+
# Format code (Black >=23.0.0)
40+
black src/ tests/
41+
42+
# Run the MCP server locally for testing
43+
python -m src.meilisearch_mcp
44+
45+
# Test with MCP Inspector
46+
npx @modelcontextprotocol/inspector python -m src.meilisearch_mcp
47+
```
48+
49+
### Prerequisites for Testing
50+
- **Meilisearch server** must be running on `http://localhost:7700`
51+
- **Docker option**: `docker run -d -p 7700:7700 getmeili/meilisearch:v1.6`
52+
- **Node.js** for MCP Inspector testing
53+
54+
## Architecture
55+
56+
### Modular Manager Design
57+
The codebase follows a modular architecture where functionality is organized into specialized managers:
58+
59+
```
60+
MeilisearchClient
61+
├── IndexManager - Index creation, listing, deletion
62+
├── DocumentManager - Document CRUD operations
63+
├── SettingsManager - Index configuration management
64+
├── TaskManager - Asynchronous task monitoring
65+
├── KeyManager - API key management
66+
└── MonitoringManager - Health checks and system metrics
67+
```
68+
69+
### MCP Server Integration
70+
- **Server Class**: `MeilisearchMCPServer` in `server.py` handles MCP protocol communication
71+
- **Tool Registration**: All tools are defined with JSON schemas for input validation
72+
- **Error Handling**: Comprehensive exception handling with logging through `MCPLogger`
73+
- **Dynamic Configuration**: Runtime connection settings updates via MCP tools
74+
75+
### Key Components
76+
77+
#### Tool Handler Pattern
78+
All MCP tools follow a consistent pattern:
79+
1. Input validation via JSON schema
80+
2. Delegation to appropriate manager class
81+
3. Error handling with structured logging
82+
4. Formatted response as `TextContent`
83+
84+
#### Search Architecture
85+
- **Single Index Search**: Direct search in specified index
86+
- **Multi-Index Search**: Parallel search across all indices when no `indexUid` provided
87+
- **Result Aggregation**: Smart filtering of results with hits
88+
89+
#### Connection Management
90+
- **Runtime Configuration**: Dynamic URL and API key updates
91+
- **Environment Variables**: `MEILI_HTTP_ADDR` and `MEILI_MASTER_KEY` for defaults
92+
- **Connection State**: Maintained in server instance for session persistence
93+
94+
## Testing Strategy
95+
96+
### Test Structure
97+
- **Integration Tests** (`test_mcp_integration.py`): End-to-end MCP tool execution with real Meilisearch
98+
- **Synchronous Tests** (`test_mcp_sync.py`, `test_mcp_simple.py`): Simplified testing avoiding async complications
99+
- **Unit Tests** (`test_server.py`): Basic server instantiation
100+
101+
### Tool Simulation
102+
Tests use `simulate_tool_call()` function that:
103+
- Directly invokes server tool handlers
104+
- Bypasses MCP protocol overhead
105+
- Returns proper `TextContent` responses
106+
- Provides comprehensive coverage of all 20+ tools
107+
108+
### Test Isolation
109+
- **Unique Index Names**: Timestamped index names prevent test interference
110+
- **Cleanup Fixtures**: Automatic test environment cleanup
111+
- **Service Dependencies**: Tests require running Meilisearch instance
112+
113+
## Environment Configuration
114+
115+
### Required Environment Variables
116+
```bash
117+
MEILI_HTTP_ADDR=http://localhost:7700 # Meilisearch server URL
118+
MEILI_MASTER_KEY=your_master_key # Optional: API key for authenticated instances
119+
```
120+
121+
### Claude Desktop Integration
122+
Add to `claude_desktop_config.json`:
123+
```json
124+
{
125+
"mcpServers": {
126+
"meilisearch": {
127+
"command": "uvx",
128+
"args": ["-n", "meilisearch-mcp"]
129+
}
130+
}
131+
}
132+
```
133+
134+
### GitHub Actions Integration
135+
The repository includes Claude Code integration via GitHub Actions:
136+
- **Trigger**: Comments containing `@claude` on issues, PRs, or reviews
137+
- **Workflow**: `.github/workflows/claude.yml` handles automated Claude responses
138+
- **Permissions**: Read contents, write to pull requests and issues
139+
140+
## Available MCP Tools
141+
142+
### Core Categories
143+
- **Connection Management**: Dynamic configuration updates
144+
- **Index Operations**: CRUD operations for search indices
145+
- **Document Management**: Add, retrieve, and manage documents
146+
- **Search Capabilities**: Single and multi-index search with filtering
147+
- **Settings Control**: Index configuration and optimization
148+
- **Task Monitoring**: Asynchronous operation tracking
149+
- **API Key Management**: Authentication and authorization
150+
- **System Monitoring**: Health checks and performance metrics
151+
152+
### Search Tool Features
153+
- **Flexible Targeting**: Search specific index or all indices
154+
- **Rich Parameters**: Filtering, sorting, pagination support
155+
- **Result Formatting**: JSON formatted responses with proper serialization
156+
- **Error Resilience**: Graceful handling of index-specific failures
157+
158+
## Development Notes
159+
160+
### Dependencies
161+
- **MCP Framework**: `mcp>=1.2.1` for protocol implementation
162+
- **Meilisearch Client**: `meilisearch>=0.33.0` for search engine integration
163+
- **HTTP Client**: `httpx>=0.24.0` for async HTTP operations
164+
- **Data Validation**: `pydantic>=2.0.0` for structured data handling
165+
166+
### Logging Infrastructure
167+
- **Structured Logging**: JSON-formatted logs with contextual information
168+
- **Log Directory**: `~/.meilisearch-mcp/logs/` for persistent logging
169+
- **Error Tracking**: Comprehensive error logging with tool context

0 commit comments

Comments
 (0)