Context Persistence MCP Server

Context Persistence MCP Server

Enables cross-window context sharing in VS Code by persisting Copilot conversations to SQLite, allowing code discussions from one repository to be accessible in other VS Code windows through smart entity matching and search.

Category
访问服务器

README

Context Persistence MCP Server

A Model Context Protocol (MCP) server that enables cross-window context sharing in VS Code. This solves the problem of losing conversation context when working across multiple VS Code windows with different repositories.

Problem Statement

When working with multiple repositories in separate VS Code windows:

  • Conversations with Copilot in Window A are not available in Window B
  • Analyzing code dependencies across repos requires repeating context
  • No shared memory of previous discussions when switching windows

Example: You analyze SparkJobX.java usage in Repo B, then switch to Repo A to modify the implementation - but Copilot doesn't know about your analysis from Window B.

Solution

This MCP server provides:

  • Persistent Storage: All conversations saved to SQLite
  • Cross-Window Access: Context available across all VS Code windows
  • Smart Matching: Automatically links related discussions by code entities (classes, files, methods)
  • Hybrid Approach: Both automatic resources and explicit tools for querying context

Features

Tools (Explicit Queries)

  • save_conversation - Store conversation messages
  • get_related_context - Find discussions mentioning same classes/files
  • search_conversations - Full-text search across all workspaces
  • get_workspace_summary - Overview of all tracked repositories

Resources (Automatic Context)

  • context://recent - Last 50 messages across all workspaces
  • context://workspace/{path} - History for specific repository

Installation

  1. Install dependencies:
npm install
  1. Build the server:
npm run build
  1. Configure in VS Code:

Add to your Copilot settings (~/Library/Application Support/Code/User/globalStorage/github.copilot-chat/mcpServers.json on macOS):

{
  "mcpServers": {
    "context-persistence": {
      "command": "node",
      "args": [
        "/Users/j0k0h1v/Documents/AI/McpServerPoc/dist/index.js"
      ]
    }
  }
}
  1. Restart VS Code

Usage

Automatic Context Sharing

When you open any VS Code window, Copilot can access:

  • Recent conversations from all windows via context://recent resource
  • Workspace-specific history via context://workspace/{path} resource

Manual Context Queries

Ask Copilot to use the tools:

"Check if we discussed SparkJobX in other repositories"
→ Copilot will call get_related_context with entities: ["SparkJobX"]

"Search our previous conversations about performance optimization"
→ Copilot will call search_conversations with query: "performance optimization"

"What repositories have we analyzed?"
→ Copilot will call get_workspace_summary

Example Workflow

Window A (ETL-core repo):

You: "Analyze SparkJobX.java performance"
Copilot: [analyzes code] "The job processes 1M records..."
[Context automatically saved]

Window B (Consumer repo):

You: "Why is SparkJobX slow when imported here?"
Copilot: [checks context://recent resource]
         "Based on our previous analysis in ETL-core, SparkJobX processes 1M records..."

Architecture

┌─────────────────────────────────┐
│  VS Code Window A (Repo A)      │
│  ├─ Copilot Chat                │
│  └─ MCP Client                  │
└─────────────┬───────────────────┘
              │
              ├─── Tools ──────┐
              │                 │
              ├─── Resources ──┤
              │                 │
        ┌─────▼─────────────────▼───┐
        │  MCP Server                │
        │  ├─ Save conversations     │
        │  ├─ Extract entities       │
        │  └─ Match context          │
        └─────┬──────────────────────┘
              │
        ┌─────▼──────────────────────┐
        │  SQLite Database           │
        │  ~/.context-persistence-mcp│
        │  ├─ messages               │
        │  ├─ code_entities          │
        │  └─ workspace_metadata     │
        └─────┬──────────────────────┘
              │
┌─────────────┴───────────────────┐
│  VS Code Window B (Repo B)      │
│  ├─ Copilot Chat                │
│  └─ MCP Client                  │
└─────────────────────────────────┘

Database Schema

messages table:

  • id: Primary key
  • workspace_path: Repository path
  • role: "user" or "assistant"
  • content: Message text
  • timestamp: When saved

code_entities table:

  • message_id: Links to message
  • entity_type: "class", "file", or "method"
  • entity_name: Name of the entity

workspace_metadata table:

  • workspace_path: Primary key
  • message_count: Total messages
  • last_active: Last update timestamp

How It Works

  1. Entity Extraction: Automatically detects Java classes, files, and methods in conversations
  2. Smart Storage: Saves messages with extracted entities for later matching
  3. Context Matching: When querying, finds messages mentioning same entities
  4. Cross-Window Sync: All VS Code windows access same SQLite database

Development

# Watch mode for development
npm run dev

# Build for production
npm run build

# Run directly
npm start

Database Location

The SQLite database is stored at:

~/.context-persistence-mcp/context.db

You can inspect it with any SQLite browser or CLI:

sqlite3 ~/.context-persistence-mcp/context.db

Limitations & Future Enhancements

Current (MVP):

  • Simple keyword matching for entities
  • Single-user local storage
  • Manual tool invocation by Copilot

Planned:

  • Semantic similarity using embeddings
  • Automatic dependency detection from pom.xml/build.gradle
  • Repository relationship mapping
  • Multi-user support with authentication
  • Automatic context injection based on relevance
  • Time-based context pruning

Troubleshooting

Server not starting?

  • Check the path in mcpServers.json is correct
  • Verify dist/index.js exists after building
  • Check VS Code output panel for MCP logs

No context appearing?

  • Ensure conversations are being saved (ask Copilot to save explicitly first)
  • Check database: sqlite3 ~/.context-persistence-mcp/context.db "SELECT COUNT(*) FROM messages;"
  • Restart VS Code after configuration changes

Related context not found?

  • Entity extraction is pattern-based - use clear class/file names
  • Try explicit search: "search for [keyword] in our conversations"

Contributing

This is a POC. Feedback and improvements welcome!

License

MIT

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选