simple-index-mcp
A Python MCP server for indexing projects using embeddings, providing semantic search to help AI agents navigate codebases.
README
Simple-Index MCP Server
A Python Model Context Protocol (MCP) server for indexing projects, files, and folders using embeddings. Provides semantic search capabilities to help AI agents understand and navigate your codebase.
Features
- Semantic Indexing: Uses embeddings (via Ollama) to create a searchable index of your project files
- Single Index File: All indexes are stored in
projectIndex.si(in project root or global location) - Incremental Updates: Only re-indexes files that have changed (based on content hash)
- Extensible Provider System: Easy to add new embedding providers beyond Ollama
- MCP Tools: Exposes powerful tools for indexing, searching, and retrieving context
Installation
Prerequisites
- Python 3.10 or higher
- Ollama installed and running locally
nomic-embed-textmodel pulled in Ollama:ollama pull nomic-embed-text
Setup
- Create a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
- Install dependencies:
pip install "mcp>=1.2.0" aiohttp
- Place
simple_index_server.pyin your project directory
Configuration
Claude Desktop Configuration
Add to your Claude Desktop config (~/Library/Application Support/Claude/claude_desktop_config.json on macOS):
{
"mcpServers": {
"simple-index": {
"command": "python",
"args": [
"/path/to/simple_index_server.py",
"/path/to/your/project"
],
"env": {
"OLLAMA_MODEL": "nomic-embed-text",
"OLLAMA_URL": "http://localhost:11434"
}
}
}
}
}
}
} }
### Global Index Mode (Optional)
If you prefer to store the index file in a central location (instead of the project root), set the `SIMPLE_INDEX_ROOT` environment variable.
```json
{
"mcpServers": {
"simple-index": {
"command": "python",
"args": ["/path/to/simple_index_server.py"],
"env": {
"SIMPLE_INDEX_ROOT": "/path/to/central/indexes",
"OLLAMA_MODEL": "nomic-embed-text"
}
}
}
}
Alternative Configuration Options
You can also specify the Ollama model and URL as command-line arguments:
{
"mcpServers": {
"simple-index": {
"command": "python",
"args": [
"/path/to/simple_index_server.py",
"/path/to/your/project",
"nomic-embed-text",
"http://localhost:11434"
]
}
}
}
Available Tools
1. index_file
Index a single file with embeddings.
Parameters:
file_path(string, required): Path to the file to indexforce(boolean, optional): Force reindexing even if file hasn't changed
Example:
Claude, please index the file /path/to/my/script.py
2. index_directory
Index all matching files in a directory recursively.
Parameters:
directory(string, required): Path to directory to indexpatterns(array of strings, optional): File patterns to match (default:["*.py", "*.js", "*.ts", "*.md", "*.txt"])exclude_patterns(array of strings, optional): Patterns to exclude (default:["*/node_modules/*", "*/.git/*", "*/venv/*"])
Example:
Claude, index all Python and JavaScript files in my project, excluding the tests directory
3. search
Search for files similar to a query using semantic search.
Parameters:
query(string, required): Search query describing what you're looking fortop_k(integer, optional): Number of results to return (default: 10)
Example:
Claude, search for files related to "database connection logic"
4. get_context
Get full file contents for the most relevant files to a query.
Parameters:
query(string, required): Query describing what context you needtop_k(integer, optional): Number of files to include in context (default: 5)
Example:
Claude, get context for "authentication implementation"
5. list_indexed_files
List all files currently in the index.
Example:
Claude, show me all indexed files
6. get_index_stats
Get statistics about the current index.
Example:
Claude, what are the index statistics?
7. remove_file
Remove a file from the index.
Parameters:
file_path(string, required): Path to file to remove from index
Example:
Claude, remove the file /path/to/old/file.py from the index
Index File Format
The projectIndex.si file is stored in JSON format with the following structure:
{
"version": "1.0",
"created_at": "2026-01-31T10:00:00Z",
"updated_at": "2026-01-31T12:30:00Z",
"project_root": "/path/to/project",
"metadata": {
"total_files": 42,
"total_size": 150000,
"embedding_model": "ollama:nomic-embed-text"
},
"files": {
"src/main.py": {
"path": "src/main.py",
"absolute_path": "/path/to/project/src/main.py",
"hash": "abc123...",
"embedding": [0.1, 0.2, ...],
"indexed_at": "2026-01-31T12:30:00Z",
"size": 1024,
"metadata": {
"extension": ".py",
"name": "main.py"
}
}
}
}
Index Management
- Atomic Writes: The index is written atomically using a temporary file to prevent corruption
- Change Detection: Files are only re-indexed if their content hash changes
- Incremental Updates: You can index new files without affecting existing entries
Usage Examples
Initial Project Indexing
You: Claude, index my entire project directory at /Users/me/myproject
Claude: [Uses index_directory tool]
I've indexed your project. Found 45 files, indexed 42, skipped 3 binary files.
Searching for Relevant Files
You: Find files related to user authentication
Claude: [Uses search tool]
I found these relevant files:
1. src/auth/login.py (similarity: 0.89)
2. src/middleware/auth_check.py (similarity: 0.85)
3. tests/test_auth.py (similarity: 0.78)
Getting Context for Development
You: I need to modify the payment processing logic. Show me the relevant code.
Claude: [Uses get_context tool]
Here's the relevant code from 3 files:
## File 1: src/payments/processor.py (similarity: 0.92)
[Full file contents...]
## File 2: src/payments/validators.py (similarity: 0.87)
[Full file contents...]
Checking Index Status
You: What's the status of the index?
Claude: [Uses get_index_stats tool]
Index Statistics:
- Total files: 42
- Total size: 150 KB
- Last updated: 2026-01-31T12:30:00Z
- Embedding model: ollama:nomic-embed-text
Architecture
Components
-
EmbeddingProvider: Abstract base class for embedding providers
OllamaProvider: Implementation using Ollama API- Easy to extend with OpenAI, Cohere, etc.
-
ProjectIndex: Manages the
projectIndex.sifile- Loading and saving with atomic writes
- Adding, removing, and querying files
- Computing statistics
-
SimpleIndexServer: Main MCP server implementation
- File reading and hashing
- Orchestrating indexing operations
- Semantic search functionality
-
MCP Integration: Standard Model Context Protocol server
- Tool registration and handling
- STDIO transport for communication
Adding New Embedding Providers
To add a new provider (e.g., OpenAI):
class OpenAIProvider(EmbeddingProvider):
def __init__(self, api_key: str, model: str = "text-embedding-3-small"):
self.api_key = api_key
self.model = model
async def embed(self, text: str) -> List[float]:
# Implementation using OpenAI API
pass
Then modify the main() function to support the new provider.
Best Practices
- Index Regularly: Run indexing after significant code changes
- Use Exclude Patterns: Exclude
node_modules,venv, build artifacts - Semantic Queries: Use descriptive queries like "error handling for API requests" rather than just "error"
- Monitor Index Size: Large projects may need chunking strategies for very large files
Troubleshooting
Ollama Connection Issues
# Check if Ollama is running
curl http://localhost:11434/api/version
# Pull the embedding model if not available
ollama pull nomic-embed-text
Index Corruption
If projectIndex.si becomes corrupted, simply delete it and re-index:
rm projectIndex.si
# Then ask Claude to re-index the directory
Logging
The server uses Python's logging module and writes to stderr (MCP requirement). Check your MCP client's logs for debugging information.
Performance Considerations
- Embedding Generation: ~100-500ms per file depending on size
- Index Size: ~4KB per file (768-dim embeddings + metadata)
- Search Speed: <100ms for typical project sizes (hundreds of files)
License
MIT License - Feel free to use and modify as needed.
Contributing
This is a reference implementation. Feel free to fork and extend with:
- Additional embedding providers
- Chunking strategies for large files
- Multi-language support
- Custom metadata extraction
- Integration with other tools
Credits
Built with:
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。