Skip to main content
Glama
tbrandenburg

PyContextify

by tbrandenburg

PyContextify Python License Tests Coverage

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.

Related MCP server: RAG MCP Server

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-v2 model 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 gpu dependency group (faiss-gpu) alongside the default CPU build.

Table of Contents

Installation

pip install pycontextify

Extras are available for specific workflows:

  • pip install "pycontextify[dev]" โ€“ testing, linting, and packaging helpers

  • pip install "pycontextify[nlp]" โ€“ optional spaCy language model

  • pip 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 ChunkerFactory based on content type

  • Token Estimation: words ร— 1.3 heuristic 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 search

  • PYCONTEXTIFY_EMBEDDING_PROVIDER โ€” string โ€” default: sentence_transformers โ€” Embedding provider (sentence_transformers, ollama, openai)

  • PYCONTEXTIFY_INDEX_DIR โ€” string โ€” default: ./index_data โ€” Directory for storing search indices

  • PYCONTEXTIFY_AUTO_PERSIST โ€” boolean โ€” default: true โ€” Automatically save after indexing

  • PYCONTEXTIFY_AUTO_LOAD โ€” boolean โ€” default: true โ€” Automatically load index on startup

  • PYCONTEXTIFY_CHUNK_SIZE โ€” integer โ€” default: 512 โ€” Text chunk size for processing

  • PYCONTEXTIFY_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:

  1. index_filebase(path, tags) - Unified indexing for codebases and documents with relationship extraction

  2. discover() - List indexed tags for browsing and filtering

  3. search(query, top_k=5) - Hybrid semantic + keyword search

  4. reset_index(remove_files=True, confirm=False) - Clear index data

  5. status() - 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 Tests Coverage

Publishing to PyPI

Use the dedicated release checklist in RELEASING.md when preparing a public build.

Quick reference:

  1. Bump version in pyproject.toml (use python scripts/bump_version.py [major|minor|patch] for automation and ensure changelog coverage)

  2. Run the full test suite or uv run python scripts/run_mcp_tests.py --smoke

  3. Build distributables and run metadata checks:

    python scripts/build_package.py
  4. 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):

  1. Fork the project

  2. Create a branch feature/your-feature

  3. Add tests and documentation

  4. Open a pull request

Security

Please report security issues to: Create an issue in this repository (or see SECURITY.md)

License

MIT 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

Install Server
A
license - permissive license
A
quality
D
maintenance

Maintenance

โ€“Maintainers
โ€“Response time
โ€“Release cycle
โ€“Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • A
    license
    -
    quality
    D
    maintenance
    An intelligent codebase processing server that provides agentic RAG capabilities for code repositories, enabling semantic search and contextual understanding through self-evaluating retrieval loops.
    2
    MIT
  • F
    license
    C
    quality
    D
    maintenance
    Combines a knowledge graph with RAG (Retrieval-Augmented Generation) capabilities for semantic code indexing and search. Enables creating entity relationships, managing observations, and performing semantic searches across indexed codebases.
    13
  • A
    license
    -
    quality
    D
    maintenance
    Enables semantic code search across multiple repositories using AST-aware chunking and relationship tracking. Supports local LLM embeddings, real-time indexing, and cross-codebase dependency analysis through vector and graph databases.
    3
    MIT
  • A
    license
    -
    quality
    C
    maintenance
    Semantic search server for code and documentation using Qdrant vector database. Supports multi-language indexing, live updates, and natural language queries.
    1
    Apache 2.0

View all related MCP servers

Related MCP Connectors

  • Enterprise code intelligence for M&A, security audits, and tech debt. Hosted server with 200k free.

  • Software component catalog: search your org's services, docs, APIs, dependencies, and ownership.

  • Search a billion+ documents โ€” papers, books, code, legal cases, forums, Wikipedia, and more.

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/tbrandenburg/pycontextify'

If you have feedback or need assistance with the MCP directory API, please join our Discord server