CTX MCP Server
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@CTX MCP Servergenerate a bounded context summary for this codebase"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
CTX β Portable Project Context Engine & Agent Harness
CTX is a lightweight, agent-agnostic project context engine and deterministic coding harness. It equips AI coding agents (such as OpenCode, Claude Desktop, and custom MCP clients) with structured repository intelligence, abstract syntax tree (AST) symbol indexing, and bounded context without requiring external LLM calls or cloud dependencies.
π Overview & Problem Statement
Modern AI coding agents struggle on non-trivial codebases due to two recurring bottlenecks:
Context Window Saturation & Inefficiency: Dumping raw files or relying purely on fuzzy vector embeddings wastes tokens, degrades reasoning quality, and introduces hallucinated API boundaries.
Lack of Deterministic Engineering Structure: LLMs lack an instant, exact mental model of project architecture, AST symbol definitions, and internal import graphs.
ββββββββββββββββββββββββββββββββββββββββββββββββ
β AI Coding Agent β
β (OpenCode, Claude, Cursor, etc.) β
ββββββββββββββββββββββββ¬ββββββββββββββββββββββββ
β MCP (JSON-RPC 2.0)
βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββ
β CTX Engine β
β ββββββββββββββββββββββ¬ββββββββββββββββββββ β
β β Tree-sitter AST β SQLite Relationalβ β
β β Symbol Indexer β Dependency Graph β β
β ββββββββββββββββββββββΌββββββββββββββββββββ€ β
β β Bounded Context Genβ Harness Injector β β
β ββββββββββββββββββββββ΄ββββββββββββββββββββ β
ββββββββββββββββββββββββ¬ββββββββββββββββββββββββ
β Read-Only / Non-Destructive
βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββ
β Target Codebase β
ββββββββββββββββββββββββββββββββββββββββββββββββCTX solves this by acting as a deterministic intelligence layer:
Zero Cloud / Zero LLM Overhead: Runs 100% locally and offline. No API keys, zero inference cost, and zero external network calls.
Tree-sitter Powered: Exact AST extraction of functions, methods, classes, interfaces, types, and constants across multiple languages.
Fast Incremental Indexing: SHA-256 fingerprinting ensures sub-second re-indexing of only modified source files.
Standards-Compliant MCP Server: Exposes structured repository intelligence directly to LLM agents via standard Model Context Protocol (MCP) over stdio.
Related MCP server: Codex MCP Server
β¨ Core Features
Feature | Description |
π³ Polyglot AST Symbol Engine | Multi-language parsing powered by |
β‘ Incremental Relational Index | Embedded SQLite index with SHA-256 file fingerprinting for instant, cached symbol and dependency lookups. |
π Import & Dependency Graph | Tracks file-level inbound and outbound import relationships with internal project target resolution. |
π‘οΈ Non-Destructive Harness Setup | Idempotent initialization that configures |
π¦ Bounded Context Generation | Delivers token-optimized, compact repository digests to agents without bloating prompt budgets. |
π» Intuitive CLI & Rich Terminal UI | Clean, diagnostic-friendly terminal interface built with Typer and Rich. |
ποΈ System Architecture
CTX is engineered around modular service layers and strict separation of concerns:
src/ctx/
βββ cli.py # Typer CLI entrypoint & formatted Rich UI
βββ config/
β βββ manager.py # TOML configuration lifecycle & schema validation
βββ harness/
β βββ agents.py # Non-destructive AGENTS.md block manager
β βββ mcp.py # JSON-RPC 2.0 stdio Model Context Protocol server
β βββ opencode.py # OpenCode JSON configuration integration
β βββ setup.py # Orchestrator for agent harness provisioning
βββ intelligence/
β βββ imports.py # Import specifier extractors & path resolvers
β βββ index.py # SQLite schema, query engine & transaction manager
β βββ languages.py # Language detection & Tree-sitter grammar registry
β βββ summary.py # Token-bounded context summary generators
β βββ symbols.py # AST visitors for functions, classes, and types
βββ project/
β βββ initializer.py # Idempotent .ctx/ scaffolding
β βββ root.py # Repository root resolution & marker traversal
βββ scanner/
β βββ detector.py # Heuristic detection for frameworks, tests & tools
βββ status/
βββ reporter.py # Comprehensive system health and index metricsπ Quick Start
Prerequisites
Python 3.11+
Git
Installation
Clone the repository and install in editable mode:
git clone https://github.com/your-username/ctx.git
cd ctx
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
pip install -e ".[dev]"Verify the installation:
ctx --helpπ οΈ Usage & Workflow
1. Initialize CTX in a Repository
Run ctx init at the root of any software project. It safely creates .ctx/config.toml without touching existing files:
cd /path/to/target-project
ctx init2. Configure Agent Harness (OpenCode / MCP)
Automatically configure your agent environment, register the MCP server, and set up project instructions:
ctx setupThis idempotently:
Injects a managed context block into
AGENTS.md.Registers the local
ctx mcpserver inopencode.json.Updates
.ctx/config.tomlharness state.
3. Build & Query the Project Index
Build or incrementally refresh the AST symbol database:
# Build / update the index (cached by SHA-256 fingerprint)
ctx index
# Rebuild the index from scratch
ctx index --resetQuery symbols, dependencies, and file relationships instantly:
# Find functions, classes, or types by name
ctx symbols OrderService --kind class
# Inspect outbound and inbound dependencies of a module
ctx deps src/services/order.py
# Query import references for a specific file
ctx imports src/api/routes.py4. Inspect Project Health & Status
Get a consolidated overview of project structure, index coverage, and agent configuration:
ctx status5. Run the MCP Server
When invoked by an MCP client (such as OpenCode or Claude Desktop), CTX runs an interactive stdio server exposing the ctx_context tool:
ctx mcpπ Comparison: CTX vs. Traditional Approaches
Dimension | Raw LLM Context | Vector Embeddings (RAG) | CTX Engine |
Accuracy | Prone to truncation | Approximate / Fuzzy | 100% Deterministic (AST) |
Token Consumption | Extremely High | Moderate to High | Minimal / Bounded |
Execution Cost | Costly API usage | Embedding API costs | $0.00 (Zero external calls) |
Offline Support | β No | β Rare (Needs local models) | β 100% Offline |
Update Latency | Full re-scan | Slow re-vectorization | Sub-second (SHA-256 diff) |
Protocol Support | Ad-hoc prompts | Custom vector integrations | Standard MCP (JSON-RPC) |
πΊοΈ Project Roadmap & Ongoing Development
CTX is under active development. Below is the current evolution roadmap:
π’ Phase 0: Foundation (Completed)
Project root detection & directory hierarchy traversal
Idempotent
.ctx/config.tomlschema and configuration lifecycleRich diagnostic status reporter (
ctx status)
π’ Phase 1: Agent Harness & Protocol Integration (Completed)
Stdio-based JSON-RPC 2.0 Model Context Protocol (MCP) server
Safe, idempotent
AGENTS.mdblock injectorAutomated OpenCode integration (
opencode.jsonconfiguration manager)Read-only bounded
ctx_contexttool for AI agents
π’ Phase 2: Polyglot Project Intelligence (Completed)
Persistent embedded SQLite index (
.ctx/index/index.db)Tree-sitter AST extractors for Python, JavaScript, TypeScript, Go, Rust, and Java
SHA-256 fingerprint-based incremental indexing
Exact symbol lookup (
ctx symbols), import tracing (ctx imports), and dependency graph (ctx deps)Configurable index exclusion filters (
[index] ignore)
π‘ Phase 3: Active Execution & Verification Harness (In Progress)
Test discovery and targeted test runner harness (
ctx test)Automated regression check hooks before agent commit
Git diff & change-impact analysis engine
βͺ Phase 4: Long-Term Memory & Multi-Repo Intelligence (Planned)
Architectural Decision Record (ADR) synchronization
Task execution memory & persistent agent scratchpad (
.ctx/memory/)Multi-workspace and monorepo cross-indexing
π§ͺ Testing & Code Quality
CTX maintains a comprehensive automated test suite with temporary directory isolation, ensuring no tests modify workspace files.
# Run full test suite
pytest
# Run tests with coverage reporting
pytest --cov=src/ctx --cov-report=term-missing
# Lint and check style
ruff check src/ tests/π Repository Strategy & Cleanliness
Committed Files:
.ctx/config.toml, documentation, and core project settings.Ignored / Disposable Artifacts:
.ctx/index/index.db, caches, and temporary scan output. The SQLite index is treated as disposable cache and can be safely regenerated at any time withctx index --reset.
π License
This project is licensed under the MIT License β see the LICENSE file for details.
This server cannot be deployed
Maintenance
Related MCP Connectors
Codebase graphs, caller impact analysis, and recorded project context for AI coding agents.
Project memory, semantic code search, and grounded agent context.
Give your AI agent a persistent map of your project's structure, dependencies, and bugs.
Deterministic context layer for your codebase: change impact, blast radius, answers with receipts.
Related MCP Servers
- AlicenseNot gradedqualityAmaintenanceProvides LLMs with code intelligence tools like relationship explanation, PR impact analysis, and health reports via the Model Context Protocol.3MIT
- AlicenseNot gradedqualityDmaintenanceA Model Context Protocol server for local repository indexing and code understanding, enabling semantic search, AST analysis, dependency tracking, and symbol resolution.577 npmISC
- FlicenseNot gradedqualityCmaintenanceProvides persistent codebase memory and semantic context for AI agents via AST-aware chunking and symbol graph indexing.1-
- AlicenseNot gradedqualityBmaintenanceTurns a codebase into a queryable graph with semantic search, call graphs, and control/data flow analysis, served to AI coding agents via the Model Context Protocol.161 npmMIT