Context Optimizer MCP

by degenhero

275 downloads Not rated yet
GitHub

About

An MCP server that uses Redis and in-memory caching to optimize and extend context windows for large chat histories

Explore

- Dual-Layer Caching: Combines fast in-memory LRU cache with persistent Redis storage
- Smart Context Management: Automatically summarizes older messages to maintain context within token limits
- Rate Limiting: Redis-based rate limiting with burst protection
- API Compatibility: Drop-in replacement for Anthropic API with enhanced context handling
- Metrics Collection: Built-in performance monitoring and logging

Setting up with Highlight

This MCP is not yet compatible with Highlight’s one-click setup. However, you can still use it with Highlight by following these steps:

  1. Download and install Highlight from highlightai.com/download
  2. Navigate to the plugins tab and select "Add Custom Plugin"
  3. Configure the plugin with the settings below
    Plugin Name Context Optimizer MCP
    Command (node, npx, python, etc.)

    Please refer to the README for specific instructions on how to obtain API keys or other required environment variables.

  4. Enable "Start Automatically" if you want the plugin to start when Highlight launches

From the repository

- Node.js 18+
- Redis server (local or remote)
- Anthropic API key

npx mcp install degenhero/context-optimizer-mcp


npm install

cp .env.example .env

PORT=3000

REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=

The server exposes a compatible API endpoint that works like the standard Claude API with additional context optimization features:

javascript
// Example client usage
const response = await fetch('http://localhost:3000/v1/messages', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
model: 'claude-3-opus-20240229',
messages: [
{ role: 'user', content: 'Hello!' },
{ role: 'assistant', content: 'How can I help you today?' },
{ role: 'user', content: 'Tell me about context management.' }
],
max_tokens: 1000,
// Optional MCP-specific parameters:
conversation_id: 'unique-conversation-id', // For context tracking
context_optimization: true, // Enable/disable optimization
}),
});

const result = await response.json();
```

Claude Desktop / Cursor

Paste into your MCP client config file to install this server.

{
    "mcpServers": {
        "context optimizer mcp": {
            "context-optimizer-mcp": {
                "command": "npx",
                "args": [
                    "mcp",
                    "install",
                    "degenhero/context-optimizer-mcp"
                ]
            }
        }
    }
}

McpServers

{
    "context-optimizer-mcp": {
        "command": "npx",
        "args": [
            "mcp",
            "install",
            "degenhero/context-optimizer-mcp"
        ]
    }
}

An MCP (Model Context Protocol) server that uses Redis and in-memory caching to optimize and extend context windows for large chat histories.

Features

- Dual-Layer Caching: Combines fast in-memory LRU cache with persistent Redis storage
- Smart Context Management: Automatically summarizes older messages to maintain context within token limits
- Rate Limiting: Redis-based rate limiting with burst protection
- API Compatibility: Drop-in replacement for Anthropic API with enhanced context handling
- Metrics Collection: Built-in performance monitoring and logging

How It Works

This MCP server acts as a middleware between your application and LLM providers (currently supporting Anthropic's Claude models). It intelligently manages conversation context through these strategies:

1. Context Window Optimization: When conversations approach the model's token limit, older messages are automatically summarized while preserving key information.

2. Efficient Caching:
- In-memory LRU cache for frequently accessed conversation summaries
- Redis for persistent, distributed storage of conversation history and summaries

3. Transparent Processing: The server handles all context management automatically while maintaining compatibility with the standard API.

Getting Started

Prerequisites

- Node.js 18+
- Redis server (local or remote)
- Anthropic API key

Installation Options

1. Using MCP client

The easiest way to install and run this server is using the MCP client:

```bash

No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.