上下文智能中间件

一个模型无关的中间件,通过模型上下文协议(MCP)为大型语言模型提供持久记忆和可重用技能库。

  • by myselfvivek17
  • Python
  • 本地部署
  • 2 星标
  • 更新于
在 GitHub 查看 myselfvivek17/context-intelligence

使用说明

上下文智能层

一种与模型无关的中间件,通过以下方式为LLM提供持久内存和可重用技能 模型上下文协议(MCP).

为什么存在

每次你与法学硕士开始新的对话时,它都会忘记一切——你的偏好、过去的决定、项目背景和你已经解释过的工作流程。你最终会在整个会话中重复自己。

这个项目解决了这个问题。它为任何兼容MCP的型号提供了 长期记忆 和一个 技能库 由矢量数据库支持。记忆是语义存储的,因此模型通过意义而不是精确的关键字来检索它们。技能允许您一次性保存多步骤过程,并让模型在未来的会话中自动遵循它们。

关键设计选择: 模型不可知。此未锁定到Claude或GPT。任何使用MCP(Claude Desktop、Claude Code、Codex、LiteLLM或明天构建的任何东西)的客户端都可以插入并立即获得持久上下文。更换型号,保留记忆。

它能做什么

  • 记住你是谁,你在做什么,你喜欢做什么
  • 在不重复的情况下回忆几周前对话中的决定
  • 将部署检查表、调试工作流或审查流程存储为可重用技能
  • 同时跨多个AI客户端工作——相同的内存,不同的模型

特性

  • 持久内存 --在对话中存储事实、偏好、决策和目标
  • 语义搜索 --通过意义而不仅仅是关键字检索记忆
  • 可重复使用的技能 --保存任何LLM都能找到并遵循的分步说明
  • 域范围存储 --记忆组织成 identity, projects, code, general
  • 承载令牌身份验证 -API对每个工具调用的密钥保护
  • 模型无关 --适用于任何MCP客户端(克劳德桌面、克劳德代码、Codex等)

建筑

MCP Client (Claude / Codex / etc.)
        │
        │  MCP (Streamable HTTP)
        ▼
 context-mcp server  ←─── FastMCP 3.x + Python
        │
        │  Qdrant client
        ▼
   Qdrant (vector DB)

项目结构

context-intelligence/
│
├── server/                        # ── Core Server ──
│   ├── main.py                    # MCP server entry point, tool definitions, auth setup
│   ├── qdrant_store.py            # Qdrant CRUD — store, search, delete operations
│   ├── schemas.py                 # Pydantic models (MemoryEntry, SkillEntry)
│   └── embeddings.py              # FastEmbed wrapper (all-MiniLM-L6-v2, 384 dims)
│
├── setup/                         # ── Setup & Config ──
│   └── init_collections.py        # One-time script to create Qdrant collections
│
├── docs/                          # ── Documentation ──
│   └── SYSTEM_PROMPT.md           # Drop-in system prompt for LLM clients
│
├── Dockerfile                     # Container build for the MCP server
├── requirements.txt               # Python dependencies
├── README.md                      # You are here
├── LICENSE                        # MIT
└── .gitignore

MCP工具

工具 说明
store_memory_tool 在域集合中存储内存
search_memory_tool 跨记忆的语义搜索
delete_memory_tool 按ID删除内存
store_skill_tool 用说明保存可重复使用的技能
find_skill_tool 根据意图找到相关技能
list_skills_tool 列出所有存储的技能

快速开始

先决条件

  • Docker+Docker组合

1.克隆并构建映像

git clone https://github.com/myselfvivek17/context-intelligence.git
cd context-intelligence
docker build -t context-mcp:latest .

2.创建 docker-compose.yml

services:
  qdrant:
    image: qdrant/qdrant
    network_mode: host
    volumes:
      - /data/qdrant:/qdrant/storage
    environment:
      - QDRANT__SERVICE__API_KEY=your-qdrant-key
    restart: unless-stopped

  context-mcp:
    image: context-mcp:latest
    network_mode: host
    environment:
      - QDRANT_URL=http://localhost:6333
      - QDRANT_API_KEY=your-qdrant-key
      - FASTMCP_HOST=0.0.0.0
      - FASTMCP_PORT=8083
      - MCP_API_KEY=your-mcp-api-key
      - MAX_SEARCH_LIMIT=50
    restart: unless-stopped

注: 替换 your-qdrant-key 和 your-mcp-api-key 使用您自己的随机字符串——这些是您创建的秘密,而不是您从任何地方获得的值。使用密码生成器或类似工具 openssl rand -base64 24.

3.启动堆栈

docker compose up -d

4.初始化Qdrant集合(运行一次)

等待几秒钟让Qdrant启动,然后:

使用Docker:

docker run --rm --network host \
  -e QDRANT_URL=http://localhost:6333 \
  -e QDRANT_API_KEY=your-qdrant-key \
  context-mcp:latest \
  python setup/init_collections.py

使用Python(如果本地安装):

pip install qdrant-client
QDRANT_URL=http://your-server:6333 QDRANT_API_KEY=your-qdrant-key python init_collections.py

这将创建5个必需的Qdrant集合:

收集 目的
memory_identity 用户偏好、个人事实、用户是谁
memory_projects 正在进行的工作、目标、决策、项目背景
memory_code 语言、框架、编码模式、惯例
memory_general 其他不适合上面的东西
skills LLM要遵循的可重复使用的分步说明

配置

环境变量 默认值 描述
QDRANT_URL http://localhost:6333 Qdrant服务器URL
QDRANT_API_KEY (无) Qdrant API密钥
MCP_API_KEY (无) MCP身份验证的承载令牌
FASTMCP_HOST 0.0.0.0 服务器绑定主机
FASTMCP_PORT 8083 服务器端口
MAX_SEARCH_LIMIT 50 每次搜索查询的最大结果数

连接MCP客户端

克劳德代码(.mcp.json)

{
  "mcpServers": {
    "context-intelligence": {
      "command": "npx",
      "args": [
        "--yes", "mcp-remote",
        "http://your-server:8083/mcp",
        "--allow-http",
        "--header", "Authorization: Bearer your-mcp-api-key"
      ]
    }
  }
}

克劳德桌面-Windows(claude_desktop_config.json)

{
  "mcpServers": {
    "context-intelligence": {
      "command": "cmd",
      "args": [
        "/c", "npx", "--yes", "mcp-remote",
        "http://your-server:8083/mcp",
        "--allow-http",
        "--header", "Authorization: Bearer your-mcp-api-key"
      ]
    }
  }
}

食品法典委员会(~/.codex/config.toml)

[[mcp_servers]]
name = "context-intelligence"
command = "npx"
args = ["--yes", "mcp-remote", "http://your-server:8083/mcp", "--allow-http", "--header", "Authorization: Bearer your-mcp-api-key"]

系统提示

要在AI客户端中启用自动内存行为,请参阅 SYSTEM_PROMPT.md它指示模型在没有被询问的情况下主动搜索和存储内存。


内存域

域 用于
identity 用户偏好、个人事实
projects 正在进行的工作、目标、决策
code 语言、模式、工具、惯例
general 其他一切

技术栈


许可证

麻省理工学院