This document provides complete setup and integration patterns for using CTX with AI agents, Cursor IDE, and MCP (Model Context Protocol) servers.
- Quick Setup
- MCP Integration
- Cursor IDE Integration
- Agent Workflow Patterns
- Memory Server Integration
- Production Deployment
- Troubleshooting
- Python 3.7+ with
pip - Cursor IDE (recommended) or VS Code
- CTX tools installed (
pip install -e .)
# Clone and install
git clone https://github.com/yourusername/ctx-tools.git
cd ctx-tools
python3 install_ctx.pyThe project includes pre-configured VS Code/Cursor settings:
# Files already configured:
.vscode/mcp.json # MCP server for ctx integration
.vscode/settings.json # Python environment and CTX vars
.vscode/tasks.json # Quick access to ctx commands# Test basic functionality
ctx create test-integration --description "Testing agentic setup"
ctx set-state in-progress
ctx note "Integration test started"
# Test Cursor integration (in Cursor chat):
# Use: ctx_status, ctx_list, ctx_note toolsThe included MCP server (cursor_ctx_integration.py) exposes 6 tools:
| Tool | Purpose | Parameters |
|---|---|---|
ctx_status |
Get current context status | None |
ctx_list |
List all contexts | None |
ctx_create |
Create new context | name, description |
ctx_switch |
Switch to context | name |
ctx_set_state |
Update context state | state |
ctx_note |
Add note to context | text |
The MCP server is configured in .vscode/mcp.json:
{
"mcpServers": {
"ctx-tools": {
"command": "python3",
"args": ["/path/to/ctx-tools/cursor_ctx_integration.py"],
"env": {
"CTX_PROJECT": "your-project-name"
}
}
}
}Access via Ctrl+Shift+P → "Tasks: Run Task":
- ctx: Show Status - Display current context
- ctx: Add Note - Interactive note entry
- ctx: Set State - [state] - Quick state transitions
- ctx: List Contexts - Show all contexts
- Install ctx-tools - Reinstall/update
- Run ctx tests - Execute test suite
Set in .vscode/settings.json:
{
"terminal.integrated.env.linux": {
"CTX_PROJECT": "your-project-name",
"CTX_AUTO_ACTIVATE": "true"
}
}# Initialize sprint context
ctx create JIRA-123-feature --description "New API endpoint"
ctx set-state in-progress
ctx note "SERVICE: PaymentAPI | ENDPOINT: /api/v1/payments"
ctx note "BRANCH: feature/JIRA-123 | TARGET: dev-environment"
# Track implementation
ctx note "IMPL: Database schema - COMPLETE"
ctx note "IMPL: Service layer - IN_PROGRESS"
ctx note "TEST: Unit tests - 15/20 passing"
# Handoff to QA
ctx set-state in-review
ctx note "HANDOFF: PR #1234 ready for QA review"# Incident detection
ctx create INC-2025-001-api-down --description "API outage"
ctx set-state blocked # Using 🚫 emoji
ctx note "SEVERITY: P1 | SERVICE: payment-api"
ctx note "SYMPTOMS: 500 errors on /api/v1/process"
# Investigation
ctx note "CHECK: Database - HEALTHY"
ctx note "CHECK: External gateway - DEGRADED"
ctx note "ACTION: Enabled circuit breaker - SUCCESS"
# Resolution
ctx set-state completed
ctx note "RCA: Payment gateway provider database failover"# Feature development
ctx create feature-auth-system
ctx set-state in-progress
ctx note "ARCHITECTURE: JWT tokens + refresh mechanism"
ctx note "DEPENDENCIES: bcrypt, jsonwebtoken, redis"
# Technical decisions
ctx note "DECISION: Using RS256 for token signing"
ctx note "DECISION: 15min access token, 7day refresh token"
# Implementation tracking
ctx note "PROGRESS: User model complete"
ctx note "PROGRESS: Login endpoint 80% complete"
ctx note "NEXT: Implement token refresh logic"For advanced setups with external memory servers:
# Bidirectional sync pattern
def sync_context_to_memory(context_name):
context = ctx.get(context_name)
# Create memory entity
memory.create_entity(
name=context.name,
type="development_context",
observations=context.notes
)
# Create relations
for dependency in context.metadata.get('dependencies', []):
memory.create_relation(
from_entity=context.name,
to_entity=dependency,
relation_type="depends_on"
)
# Usage in agent workflows
ctx create PROJECT-456
memory_sync(ctx.active_context)
ctx note "Started implementation"
memory.add_observation(ctx.active_context, "Implementation started")# Hook into ctx events
class MemorySyncPlugin(Plugin):
def on_note_added(self, context, note):
memory.add_observation(context.name, note.text)
def on_state_changed(self, context, old_state, new_state):
memory.add_observation(
context.name,
f"State changed: {old_state} → {new_state}"
)# Production environment variables
export CTX_STORAGE_TYPE=sqlite
export CTX_DB_PATH=/shared/contexts/production.db
export CTX_BACKUP_ENABLED=true
export CTX_BACKUP_INTERVAL=3600 # 1 hour# Shared context setup for teams
ctx export critical-incident > shared/contexts/critical-incident.json
# Team members can import:
ctx import shared/contexts/critical-incident.json
# Or use shared storage
export CTX_STORAGE_PATH=/shared/team-contexts/# Docker compose example
services:
ctx-agent:
build: .
environment:
- CTX_PROJECT=production-system
- CTX_STORAGE_TYPE=sqlite
- CTX_DB_PATH=/data/contexts.db
volumes:
- ./contexts:/data
- ./scripts:/app/scriptsMCP Tools Not Available
# Check MCP server status
ps aux | grep cursor_ctx_integration
# Restart Cursor IDE
# Check .vscode/mcp.json path is absoluteContext Not Found
# List all contexts including completed
ctx list --all
# Check active context
ctx statusPerformance Issues
# Use SQLite for better performance
export CTX_STORAGE_TYPE=sqlite
# Clean up old contexts
ctx list --state completed | xargs ctx deleteInstallation Issues
# Reinstall with verbose output
python3 install_ctx.py
# Check Python version
python3 --version # Must be 3.7+
# Check dependencies
pip install -e .[dev] --verbose# Enable debug logging
export CTX_DEBUG=true
ctx status # Will show detailed debug info
# Check MCP server logs
tail -f ~/.cursor/logs/mcp.log# Run comprehensive tests
python3 -m pytest tests/ -v
# Test MCP integration
curl -X POST http://localhost:3000/mcp/ctx-tools/ctx_status
# Test memory sync (if configured)
memory search "test context"
ctx notes | grep "test"- State-Driven Logic: Always check context state before taking action
- Atomic Notes: One concept per note for better searchability
- Consistent Tagging: Use consistent prefixes (IMPL:, TEST:, ERROR:)
- Handoff Protocols: Clear state transitions with handoff notes
- Batch Operations: Group multiple ctx operations when possible
- Selective Sync: Only sync relevant contexts to memory servers
- Regular Cleanup: Archive completed contexts periodically
- Index Management: Use tags for efficient context filtering
- Sensitive Data: Never store secrets in context notes
- Access Control: Use shared storage with proper permissions
- Audit Trail: Enable logging for production environments
- Backup Strategy: Regular exports of critical contexts
# Agent handoff pattern
class DevAgent:
def complete_implementation(self, context_name):
ctx.set_state(context_name, "in-review")
ctx.note(context_name, "HANDOFF: Ready for QA review")
ctx.note(context_name, f"PR: #{self.pr_number}")
# Signal QA agent
memory.create_relation(context_name, "qa-queue", "ready_for")
class QAAgent:
def pick_up_work(self):
ready_contexts = memory.search_relations("ready_for qa-queue")
for context in ready_contexts:
ctx.switch(context)
ctx.set_state("in-progress")
ctx.note("QA: Started test execution")# Parent-child context relationships
ctx create EPIC-100 --description "Payment system overhaul"
ctx create EPIC-100-auth --description "Authentication module" --parent EPIC-100
ctx create EPIC-100-api --description "API endpoints" --parent EPIC-100
# Inherit configuration from parent
ctx note EPIC-100 "CONFIG: payment_gateway_url=https://api.payment.com"
# Child contexts automatically inherit parent configThis guide provides the foundation for sophisticated agentic workflows with CTX. Start with basic patterns and gradually adopt advanced features as your team's needs evolve.