PyContextify
Semantic search server with relationship-aware discovery across codebases and documents.
README
PyContextify

One-line: Semantic search server with relationship-aware discovery across codebases and documents.
PyContextify is a Python-based MCP (Model Context Protocol) server that provides intelligent semantic search capabilities over diverse knowledge sources. It combines vector similarity search with basic relationship tracking to help developers, researchers, and technical writers discover contextually relevant information across codebases and documentation.
Main Features:
- 🔍 Semantic Search: Vector similarity with FAISS + hybrid keyword search
- 📚 Multi-Source: Index code and documents (PDF/MD/TXT)
- 🧠 Smart Chunking: Content-aware processing (code boundaries, document hierarchy)
- ⚡ Pre-loaded Models: Embedders initialize at startup for fast first requests
- 🔗 Relationship Tracking: Basic relationship extraction (tags, references, code symbols)
- 🛠️ MCP Protocol: 5 essential functions for seamless AI assistant integration
Quickstart
# Install UV and dependencies
curl -LsSf https://astral.sh/uv/install.sh | sh
uv sync
# Run MCP server
uv run pycontextify --verbose
Run with uvx
If you want to execute the published CLI without modifying your current
environment, uvx can resolve pycontextify from PyPI and run its console
entry point directly:
uvx pycontextify -- --help
The double dash (--) ensures any following arguments are forwarded to
PyContextify itself. This requires a released version of the package to be
available on PyPI, which the manual publishing workflow now provides.
System Requirements
- Python: Python 3.10 or newer for the MCP server core (full test suite currently targets Python 3.13+).
- Package management: Ability to install dependencies via UV and resolve all runtime libraries, including FAISS, sentence-transformers, PDF processors, and supporting utilities.
- CPU: 64-bit multi-core processor (4+ cores recommended) so FAISS vector search and sentence-transformers embedding generation can run locally without bottlenecks.
- Memory: 8 GB RAM minimum (16 GB recommended for larger corpora) because embeddings and FAISS indexes reside in-process and scale with corpus size; switch to the lighter
all-MiniLM-L6-v2model if constrained. - Network access: Internet connectivity on first run to download sentence-transformers models and other remote assets.
- Storage & filesystem: At least 5 GB of free disk space to install Python dependencies, download embedding models, and persist FAISS indexes in
PYCONTEXTIFY_INDEX_DIR, along with write access for temporary working folders during indexing and testing. - Optional acceleration: CUDA-capable GPU support is available by installing the optional
gpudependency group (faiss-gpu) alongside the default CPU build.
Table of Contents
- Quickstart
- Installation
- Usage
- Chunking Techniques
- Configuration
- API Reference
- Tests & CI
- Changelog
- Contributing
- License
- Security
- Maintainers
Installation
PyPI (recommended)
pip install pycontextify
Extras are available for specific workflows:
pip install "pycontextify[dev]"– testing, linting, and packaging helperspip install "pycontextify[nlp]"– optional spaCy language modelpip install "pycontextify[ollama]"/[openai]– alternative embedding providers
From Source with UV
Requirements: Python 3.10+ and the UV package manager
# Install UV package manager
curl -LsSf https://astral.sh/uv/install.sh | sh
# Clone and install dependencies
git clone https://github.com/pycontextify/pycontextify.git
cd pycontextify
uv sync
# Optional: Install development + release tooling
uv sync --extra dev
To update dependencies from scratch use uv sync --reinstall.
Usage
Minimal example:
# Start the MCP server
uv run pycontextify
# Index content (via MCP client/AI assistant)
# The server exposes 5 MCP functions:
# - index_filebase(path, tags) - Unified indexing for code & docs
# - discover() - List indexed tags
# - search(query, top_k=5) - Semantic search
# - reset_index(remove_files=True, confirm=False) - Clear index data
# - status() - Get system status and statistics
Expected output:
Starting PyContextify MCP Server...
Server provides 5 essential MCP functions:
- index_filebase(path, tags): Unified filebase indexing
- discover(): List indexed tags
- search(query, top_k): Basic semantic search
- reset_index(confirm=True): Clear all indexed content
- status(): Get system status and statistics
MCP server ready and listening for requests...
Chunking Techniques
PyContextify employs a hierarchical chunking system with specialized processors for different content types, optimizing semantic search while preserving structural integrity.
Content-Aware Chunking Strategies
Code Chunking (CodeChunker)
- Primary Strategy: Structure-aware splitting by function/class boundaries
- Language Support: Python, JavaScript, TypeScript, Java, C/C++, Rust, Go, and more
- Boundary Detection:
def,class,function,const,var,let,public,private,protected - Relationship Extraction: Functions, classes, imports, variable assignments
- Fallback: Token-based splitting when code blocks exceed size limits
Document Chunking (DocumentChunker)
- Primary Strategy: Markdown header hierarchy preservation (
#,##,###) - Section Tracking: Maintains parent-section relationships for context
- Content Filtering: Requires minimum 50 characters per meaningful chunk
- Relationship Extraction: Links
[text](url), citations[1],(Smith 2020), emphasized terms - Fallback: Token-based splitting when no structure is detected
Simple Chunking (SimpleChunker)
- Fallback Strategy: Pure token-based chunking for unstructured content
- Basic Relationships: Capitalized word extraction for entity hints
- Universal Compatibility: Handles any text format as last resort
Technical Configuration
chunk_size: int = 512 # Target tokens per chunk (configurable)
chunk_overlap: int = 64 # Overlap between adjacent chunks
enable_relationships: bool # Extract lightweight knowledge graph data
max_relationships_per_chunk: int # Limit relationships to avoid noise
Key Features
- Smart Selection: Automatic chunker selection via
ChunkerFactorybased on content type - Token Estimation:
words × 1.3heuristic for English text with automatic oversized chunk splitting - Position Tracking: Maintains precise character start/end positions for all chunks
- Metadata Preservation: Source path, embedding info, creation timestamps, and custom metadata
- Relationship Graph: Lightweight knowledge extraction (imports, references, citations, links)
Bottom Line: PyContextify's chunking system intelligently adapts to content structure—respecting code boundaries and document hierarchy—while maintaining configurable token limits and extracting contextual relationships for enhanced semantic search.
Configuration
Required environment variables / config:
PYCONTEXTIFY_EMBEDDING_MODEL— string — default:all-MiniLM-L6-v2— Embedding model for semantic searchPYCONTEXTIFY_EMBEDDING_PROVIDER— string — default:sentence_transformers— Embedding provider (sentence_transformers, ollama, openai)PYCONTEXTIFY_INDEX_DIR— string — default:./index_data— Directory for storing search indicesPYCONTEXTIFY_AUTO_PERSIST— boolean — default:true— Automatically save after indexingPYCONTEXTIFY_AUTO_LOAD— boolean — default:true— Automatically load index on startupPYCONTEXTIFY_CHUNK_SIZE— integer — default:512— Text chunk size for processingPYCONTEXTIFY_USE_HYBRID_SEARCH— boolean — default:false— Enable hybrid vector + keyword search
Priority: CLI arguments > Environment variables > Defaults
Copy .env.example to .env and customize as needed.
API Reference
PyContextify exposes 5 MCP (Model Context Protocol) functions for semantic search and indexing:
index_filebase(path, tags)- Unified indexing for codebases and documents with relationship extractiondiscover()- List indexed tags for browsing and filteringsearch(query, top_k=5)- Hybrid semantic + keyword searchreset_index(remove_files=True, confirm=False)- Clear index datastatus()- Get system statistics and health
Full docs: See WARP.md for development guidance and architecture details
Tests & CI
Run tests:
# Run all tests with coverage (requires uv >= 0.4.20 for dependency groups)
uv run --extra dev --group dev pytest --cov=pycontextify
# Run MCP-specific tests
uv run python scripts/run_mcp_tests.py
# Quick smoke test
uv run python scripts/run_mcp_tests.py --smoke
CI: Manual testing
Publishing to PyPI
Use the dedicated release checklist in RELEASING.md when preparing a public build.
Quick reference:
-
Bump
versioninpyproject.toml(usepython scripts/bump_version.py [major|minor|patch]for automation and ensure changelog coverage) -
Run the full test suite or
uv run python scripts/run_mcp_tests.py --smoke -
Build distributables and run metadata checks:
python scripts/build_package.py -
Upload to TestPyPI or PyPI with Twine once validation passes:
twine upload dist/*
Changelog
Detailed release history lives in CHANGELOG.md. Update the changelog alongside any version bump so users can track notable changes between releases.
Contributing
Please read CONTRIBUTING.md (or follow the short flow below):
- Fork the project
- Create a branch
feature/your-feature - Add tests and documentation
- Open a pull request
Security
Please report security issues to: Create an issue in this repository (or see SECURITY.md)
License
This project is licensed under the MIT License — see the LICENSE file for details.
Maintainers
- PyContextify Project — contact: Create an issue for questions or support
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。