Skip to main content
Glama

Chat Context MCP

by aolshaun

Cursor Cross-Session Context Retrieval

Unlock the power of your Cursor chat history โ€“ Search, organize, and retrieve context from past conversations to enhance your AI-assisted development workflow.

Tests TypeScript License

๐ŸŽฏ The Problem

Every Cursor Composer session is isolated โ€“ when you start a new chat, the AI has no memory of your previous conversations. This leads to:

  • โŒ Repeating context and explanations

  • โŒ Lost architectural decisions and discussions

  • โŒ Manual copy-pasting from old chats

  • โŒ Difficulty finding specific conversations

  • โŒ No organization or categorization of chat history

โœจ The Solution

This library gives you programmatic access to your entire Cursor chat history with powerful organization and retrieval features:

  • โœ… Nickname sessions โ€“ Give chats memorable names instead of UUIDs

  • โœ… Tag & organize โ€“ Categorize sessions by feature, bug, topic, etc.

  • โœ… Project-scoped search โ€“ Automatically filters chats by project

  • โœ… Full-text search โ€“ Search across nicknames, tags, messages, and projects

  • โœ… Rich formatting โ€“ Export sessions as Markdown, JSON, or compact previews

  • โœ… Type-safe API โ€“ Fully typed TypeScript interface

๐Ÿš€ Quick Start

Installation

npm install cursor-context-core

CLI Tool

The package includes a powerful command-line interface:

# Show statistics cursor-context stats # List sessions cursor-context list --limit 10 # Search for sessions cursor-context search "authentication" # Get session details cursor-context get my-nickname --format markdown # Set nickname and tags cursor-context nickname abc-123 my-important-chat cursor-context tag add abc-123 feature backend

See CLI.md for complete CLI documentation.

MCP Server

Let AI automatically search and retrieve past chat sessions:

Setup:

  1. Build the project: npm run build

  2. Configure Cursor (see MCP-SETUP.md)

  3. Restart Cursor

Usage in Chat:

You: "How did I implement authentication in that project?" AI: *Automatically calls search_sessions tool* "I found your session 'auth-implementation' from 5 days ago..." You: "Load that session" AI: *Calls get_session tool* [Shows full conversation]

The AI decides when to search based on your conversation. See MCP-SETUP.md for setup instructions.

Library Usage

import { CursorContext } from 'cursor-context-core'; // Create API instance (auto-detects Cursor DB path) const api = new CursorContext(); // Sync recent sessions await api.syncSessions(50); // Give a session a nickname await api.setNickname('session-id', 'auth-implementation'); await api.addTag('session-id', 'feature'); // Retrieve by nickname const session = await api.getSession('auth-implementation'); console.log(session.messages); // Search across all sessions const results = await api.searchSessions({ query: 'authentication', projectPath: '/path/to/project' }); // Clean up api.close();

๐Ÿ“š Core Features

1. Session Management

// List sessions with filtering const sessions = await api.listSessions({ projectPath: '/path/to/project', // Filter by project sortBy: 'newest', // newest, oldest, most_messages limit: 10, // Limit results tag: 'feature', // Filter by tag taggedOnly: true // Only tagged sessions }); // Get a specific session const session = await api.getSession('nickname-or-id', { includeMessages: true, // Load full messages parseOptions: { excludeTools: false, // Include tool calls maxContentLength: 10000 // Truncate long messages } });

2. Organization

// Set nicknames await api.setNickname('session-id', 'database-migration'); // Add tags await api.addTag('session-id', 'backend'); await api.addTag('session-id', 'database'); // Remove tags await api.removeTag('session-id', 'backend'); // List all tags const tags = api.getTags(); // [{ tag: 'backend', count: 15 }, { tag: 'frontend', count: 8 }, ...]

3. Search

// Simple search const results = await api.searchSessions({ query: 'authentication' }); // Advanced search const results = await api.searchSessions({ query: 'API endpoints', projectPath: '/my/project', // Scope to project taggedOnly: true, // Only tagged sessions limit: 20, // Limit results caseSensitive: false // Case sensitivity });

4. Project Management

// List all projects const projects = api.getProjects(); // [ // { path: '/path/to/project', name: 'my-app', session_count: 42 }, // ... // ] // Get sessions for a specific project const projectSessions = await api.listSessions({ projectPath: '/path/to/project' });

5. Formatting

import { formatSessionMarkdown, formatSessionJSON, formatSessionPreview, formatSessionList } from 'cursor-context-core'; // Markdown format (great for AI context) const markdown = formatSessionMarkdown(session, { maxMessages: 10, // Limit messages includeTools: true, // Include tool calls includeMetadata: true // Include header }); // JSON format const json = formatSessionJSON(session); // Compact preview const preview = formatSessionPreview(session.metadata); // "๐Ÿ“ auth-implementation โ€ข ๐Ÿ“ my-app โ€ข ๐Ÿ’ฌ 42 โ€ข ๐Ÿ“… 2 days ago" // List of sessions const list = formatSessionList(sessions);

6. Statistics

const stats = api.getStats(); console.log(stats); // { // totalSessionsInCursor: 560, // totalSessionsWithMetadata: 50, // sessionsWithNicknames: 12, // sessionsWithTags: 25, // sessionsWithProjects: 35, // totalTags: 15, // totalProjects: 8 // }

๐Ÿ—๏ธ Architecture

Core Modules

src/core/ โ”œโ”€โ”€ api.ts # Main CursorContext API โ”œโ”€โ”€ cursor-db.ts # Read-only access to Cursor's SQLite DB โ”œโ”€โ”€ metadata-db.ts # Separate DB for nicknames/tags โ”œโ”€โ”€ message-parser.ts # Parse Lexical richText format โ”œโ”€โ”€ workspace-extractor.ts # Extract project paths from tool results โ”œโ”€โ”€ formatter.ts # Format sessions for output โ”œโ”€โ”€ platform.ts # Platform detection (macOS/Linux/Windows) โ”œโ”€โ”€ errors.ts # Custom error types โ””โ”€โ”€ types.ts # TypeScript interfaces

How It Works

  1. Read-only Access โ€“ Safely reads Cursor's internal SQLite database

  2. Separate Metadata โ€“ Stores your nicknames/tags in ~/.cursor-context/metadata.db

  3. Auto-sync โ€“ Automatically syncs sessions on first access

  4. Project Detection โ€“ Extracts workspace paths from tool results in messages

  5. Smart Parsing โ€“ Handles Cursor's complex Lexical richText format

๐Ÿ“– Advanced Usage

Custom Database Paths

const api = new CursorContext( '/custom/path/to/cursor.db', '/custom/path/to/metadata.db', true // Enable auto-sync );

Direct Database Access

// Access underlying databases for advanced operations const cursorDB = api.getCursorDB(); const metadataDB = api.getMetadataDB(); // List all composer IDs const allIds = cursorDB.listComposerIds(1000); // Get raw composer data const composerData = cursorDB.getComposerData('session-id');

Batch Operations

// Sync many sessions const synced = await api.syncSessions(100); console.log(`Synced ${synced} new sessions`); // Bulk tagging const sessions = await api.listSessions({ limit: 50 }); for (const session of sessions) { if (session.has_project) { await api.addTag(session.session_id, `project:${session.project_name}`); } }

๐Ÿงช Testing

The library includes 169 comprehensive tests:

# Run all tests npm test # Run specific test suite npm test tests/core/api.test.ts # Watch mode npm run test:watch # Build npm run build

Test coverage includes:

  • โœ… Unit tests for each module

  • โœ… Integration tests for the API

  • โœ… End-to-end workflow tests

  • โœ… Error handling and edge cases

๐Ÿ› ๏ธ Development

# Install dependencies npm install # Build TypeScript npm run build # Run examples npm run dev examples/test-api.ts # Run tests npm test

๐Ÿ“‹ Database Schema

Cursor's Database (state.vscdb)

-- Key-value store cursorDiskKV ( key TEXT PRIMARY KEY, -- e.g., "composerData:{uuid}" value TEXT -- JSON data )

Metadata Database (~/.cursor-context/metadata.db)

session_metadata ( session_id TEXT PRIMARY KEY, nickname TEXT UNIQUE, tags TEXT, -- Comma-separated project_path TEXT, project_name TEXT, has_project INTEGER, created_at INTEGER, last_accessed INTEGER, first_message_preview TEXT, message_count INTEGER )

๐Ÿ”’ Security & Privacy

  • โœ… Read-only access to Cursor's database

  • โœ… Local-only โ€“ No data sent to external servers

  • โœ… Separate metadata โ€“ Your organization data is stored separately

  • โœ… Retry logic โ€“ Handles database locks gracefully

  • โœ… No modifications โ€“ Never writes to Cursor's internal database

๐ŸŽฏ Use Cases

1. MCP Server (Recommended)

Integrate with Cursor's Model Context Protocol to let AI automatically fetch context:

// MCP tool: list_sessions const sessions = await api.listSessions({ limit: 10 }); // MCP tool: fetch_session_by_nickname const session = await api.getSession('auth-implementation'); return formatSessionMarkdown(session);

2. CLI Tool

Build a command-line interface:

cursor-context list --project /path/to/project cursor-context get auth-implementation --format markdown cursor-context search "authentication" --limit 5 cursor-context tag session-id feature backend

3. VS Code Extension

Create a sidebar that shows session history with search and filters.

4. Custom Integrations

  • Export sessions to Notion/Obsidian

  • Generate documentation from chat history

  • Analyze development patterns

  • Create knowledge bases

๐Ÿ—บ๏ธ Roadmap

Phase 1: Core Library โœ… (Complete!)

  • โœ… Database access

  • โœ… Message parsing

  • โœ… Metadata management

  • โœ… Full API with search, tagging, formatting

  • โœ… 169 comprehensive tests

Phase 2: CLI Tool โœ… (Complete!)

  • โœ… List, get, search commands

  • โœ… Nickname and tag management

  • โœ… Stats and projects views

  • โœ… Configuration management

  • โœ… Multiple output formats (table, json, markdown, compact)

  • โœ… Color support

  • Interactive TUI mode (future)

  • Shell completion (future)

Phase 3: MCP Server โœ… (Complete!)

  • โœ… MCP protocol implementation

  • โœ… 9 tool definitions with clear descriptions

  • โœ… AI-invoked session search and retrieval

  • โœ… Session management (tag, nickname)

  • โœ… Universal (works in Cursor, VSCode, Claude Desktop)

  • โœ… Stdio-based communication

  • โœ… Integration with core library

Phase 4: VSCode/Cursor Extension (Future)

  • Slash commands (/chat, /chat search, etc.)

  • Session browser UI (sidebar panel)

  • Quick pick menus for explicit control

  • Status bar integration

  • Right-click context menus

  • User-invoked actions (vs AI-invoked in MCP)

Phase 5: Advanced Features

  • Full-text search with SQLite FTS5

  • Session similarity matching (vector embeddings)

  • Automatic tagging with AI

  • Multi-workspace support

  • Session analytics and insights

๐Ÿค Contributing

Contributions are welcome! Please:

  1. Fork the repository

  2. Create a feature branch

  3. Add tests for new functionality

  4. Ensure all tests pass (npm test)

  5. Submit a pull request

๐Ÿ“„ License

MIT License - see LICENSE file for details.

๐Ÿ™ Acknowledgments


Made with โค๏ธ for developers who want to unlock their Cursor chat history

For detailed technical documentation, see CURSOR-CROSS-SESSION-CONTEXT.md

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/aolshaun/chat-context-mcp'

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