AgentStack
MCP verified MIT Self-run

Contextkit

mcp-seastarbot-contextkit Β· by seastarbot

🧠 Stop losing context. Start shipping faster. Drop-in context management for any AI agent framework.

β€” No reviews yet
0 installs
4 views
0.0% view→install

Install

$ agentstack add mcp-seastarbot-contextkit

βœ“ scanned Β· βœ“ verified β€” works with Claude Code, Cursor, and more.

Security review

βœ“ Passed

No issues found. Passed automated security review. Β· v0.1.0 How review works β†’

  • βœ“ Prompt-injection patterns
  • βœ“ Secret / credential exfiltration
  • βœ“ Dangerous shell & filesystem operations
  • βœ“ Untrusted network calls
  • βœ“ Known-malicious package signatures

What it can access

  • βœ“ Network access No
  • βœ“ Filesystem access No
  • βœ“ Shell / process execution No
  • βœ“ Environment & secrets No
  • βœ“ Dynamic code execution No

From automated source analysis of v0.1.0. β€œUsed” means the capability is present in the source β€” more access means more to trust, not that it’s unsafe.

Are you the author of Contextkit? Claim this listing to set pricing, connect Stripe payouts, and keep 70% of every sale.
Sign up to claim

About

⚑ ContextKit

The missing context layer for AI agents

[](https://pypi.org/project/contextkit/) [](https://pypi.org/project/contextkit/) [](LICENSE) [](https://github.com/seastarbot/contextkit/actions)

Smart compression Β· Semantic search Β· Token budgeting Β· MCP Server

Works with Claude Desktop, Cursor, Windsurf, and any AI agent.

[Installation](#installation) Β· [Quick Start](#quick-start) Β· [MCP Integration](#mcp-integration) Β· [CLI](#cli) Β· [API](#python-api) Β· [Benchmarks](#benchmarks)


Why ContextKit?

AI agents hit context limits. Your 200K token window fills up fast β€” and most of it is irrelevant noise. ContextKit fixes this:

  • πŸ” Semantic search β€” Find the 5% of context that actually matters
  • πŸ—œοΈ Smart compression β€” Summarize old messages, save 60-80% tokens
  • πŸ’° Token budgeting β€” Never overflow your context window again
  • πŸ”Œ MCP Server β€” Plug into Claude Desktop, Cursor, or Windsurf in one line
  • πŸ’Ύ Zero dependencies β€” Pure file storage, no databases required
pip install contextkit

Installation

# Core (token counting + compression)
pip install contextkit

# With LLM compression (OpenAI)
pip install contextkit[llm]

# With MCP server support
pip install contextkit[mcp]

# Everything
pip install contextkit[all]

Requirements

  • Python 3.9+
  • No API keys needed for token counting, budgeting, and keyword search
  • OpenAI API key required for: semantic search (embeddings), LLM compression

Quick Start

30-Second Demo

from contextkit import ContextManager

# Create a context manager
ctx = ContextManager(max_tokens=128000)

# Add messages
ctx.add("system", "You are a helpful assistant.")
ctx.add("user", "How do I sort a list in Python?")
ctx.add("assistant", "Use sorted() or list.sort().")

# Check your token budget
print(ctx.token_budget)
# {'total': 128000, 'used': 42, 'remaining': 127958, 'utilization': '0.0%'}

# Auto-compress when context is full
ctx.auto_compress()

With Semantic Search

ctx = ContextManager(
    storage="./my_memory",
    max_tokens=200000,
    embedding_model="text-embedding-3-small",  # Requires OpenAI key
)

# Add conversation history
ctx.add("user", "I prefer dark mode in VS Code")
ctx.add("assistant", "Noted! I'll keep that in mind.")
ctx.add("user", "Set up a new Python project")

# Search for relevant context
results = ctx.get_relevant("display preferences")
# β†’ Returns the dark mode message with relevance score

Cross-Session Memory

# Session 1 β€” messages persist to disk
ctx = ContextManager(storage="./project_memory")
ctx.add("user", "Our API uses REST, not GraphQL")
ctx.add("assistant", "Got it, REST endpoints.")

# Session 2 β€” context loads automatically
ctx2 = ContextManager(storage="./project_memory")
ctx2.get_relevant("API protocol")
# β†’ Finds the REST conversation from Session 1

MCP Integration

ContextKit ships as an MCP server β€” the standard protocol for AI agent tool use. Connect it to Claude Desktop, Cursor, or Windsurf in seconds.

Available Tools

| Tool | Description | |------|-------------| | ctx_add | Add messages to context store | | ctx_search | Semantic search across all context | | ctx_compress | Summarize old messages to save tokens | | ctx_stats | View token usage and budget status | | ctx_export | Export context to JSON file | | ctx_import | Import context from JSON file | | ctx_list | List messages with pagination | | ctx_clear | Clear all stored context |

Claude Desktop

Add to ~/Library/Application Support/Claude/claude_desktop_config.json:

{
  "mcpServers": {
    "contextkit": {
      "command": "contextkit",
      "args": ["mcp"],
      "env": {
        "OPENAI_API_KEY": "your-api-key"
      }
    }
  }
}

Or copy the provided config:

cp mcp_config/claude_desktop.json ~/Library/Application\ Support/Claude/claude_desktop_config.json

Cursor

Add to .cursor/mcp.json in your project:

{
  "mcpServers": {
    "contextkit": {
      "command": "contextkit",
      "args": ["mcp"],
      "env": {
        "OPENAI_API_KEY": "your-api-key"
      }
    }
  }
}

Windsurf

Add to ~/.windsurf/mcp.json:

{
  "mcpServers": {
    "contextkit": {
      "command": "contextkit",
      "args": ["mcp"],
      "env": {
        "OPENAI_API_KEY": "your-api-key"
      }
    }
  }
}

> πŸ’‘ No API key? ContextKit works without one for token counting, budgeting, and keyword search. Only semantic search and LLM compression need OpenAI.


CLI

ContextKit ships with a full CLI for inspecting and managing context:

# View context statistics
contextkit stats ./my_context/

# Compress old messages
contextkit compress ./my_context/ --hours 2

# Search context
contextkit search ./my_context/ "deployment configuration"

# Export to JSON
contextkit export ./my_context/ ./backup.json

# Run benchmarks
contextkit bench

# Start MCP server
contextkit mcp

# Version info
contextkit version

Example Output

$ contextkit stats ./my_context/

==================================================
  ContextKit Stats: ./my_context/
==================================================
  Messages:        47
  Characters:      23,451
  Est. Tokens:     5,862
  Avg Tokens/M msg: 124

  Role Distribution:
    assistant          18
    system              2
    user               27

  Time Range:      2025-04-20 09:15 β†’ 2025-04-25 14:30
==================================================

Python API

ContextManager

from contextkit import ContextManager

ctx = ContextManager(
    storage="./.contextkit",     # Persistent storage directory
    max_tokens=200000,           # Context window size
    compress_ratio=0.3,          # Compress when 70% full
    embedding_model="text-embedding-3-small",  # Or None for keyword-only
    compression_model="gpt-4o-mini",          # For summarization
)

# Add messages
msg_id = ctx.add("user", "Hello!", metadata={"source": "chat"})

# Retrieve context
relevant = ctx.get_relevant("greeting", max_tokens=50000)
recent = ctx.get_recent(max_tokens=50000)

# Compress
ctx.summarize_older_than(hours=2)
ctx.auto_compress()

# Budget
print(ctx.token_budget)

# Persistence
ctx.export("./backup.json")
ctx.import_("./backup.json")

TokenBudget

from contextkit.budget import TokenBudget

budget = TokenBudget(max_tokens=128000)

# Count tokens
tokens = budget.count_tokens("Hello, world!")
msg_tokens = budget.count_message_tokens("user", "Hello!")

# Budget status
status = budget.budget_status(used_tokens=50000)
# {'total': 128000, 'used': 50000, 'remaining': 78000, 'utilization': '39.1%'}

# Model-aware encoding
budget = TokenBudget.for_model("gpt-4o", max_tokens=128000)

ContextCompressor

from contextkit.compressor import ContextCompressor

compressor = ContextCompressor(model="gpt-4o-mini")

# Summarize messages
messages = [{"role": "user", "content": "..."}, ...]
summary = compressor.summarize(messages)

# Create summary message
summary_msg = compressor.create_summary_message(
    summary=summary,
    original_count=len(messages),
)

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Your AI Agent                     β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                     β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚  CLI Tool  β”‚  β”‚ MCP Serverβ”‚  β”‚  Python Library β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚        β”‚              β”‚                  β”‚          β”‚
β”‚        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜          β”‚
β”‚                       β–Ό                             β”‚
β”‚              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                     β”‚
β”‚              β”‚ ContextManager β”‚                     β”‚
β”‚              β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜                     β”‚
β”‚         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                 β”‚
β”‚         β–Ό            β–Ό            β–Ό                 β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”          β”‚
β”‚  β”‚ Compressor β”‚ β”‚  Indexer β”‚ β”‚  Budget  β”‚          β”‚
β”‚  β”‚ (LLM +    β”‚ β”‚ (Vector  β”‚ β”‚ (tiktokenβ”‚          β”‚
β”‚  β”‚ fallback)  β”‚ β”‚  search) β”‚ β”‚  count)  β”‚          β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜          β”‚
β”‚                                                     β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚           File-based Storage (JSON + NumPy)         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Benchmarks

Measured on Apple M2, Python 3.12:

Token Counting

| Type | Characters | Tokens | Chars/Token | |------|-----------|--------|-------------| | Short | 13 | 4 | 3.25 | | Medium | 450 | 101 | 4.46 | | Long | 5,700 | 1,001 | 5.69 | | Code | 3,700 | 1,150 | 3.22 | | Mixed (EN+ZH) | 700 | 300 | 2.33 |

Compression Ratios

| Context Size | Original | After Compress | Token Savings | |-------------|----------|----------------|---------------| | Small (7 msgs) | 143 tokens | 74 tokens | 48.3% | | Medium (13 msgs) | 872 tokens | 74 tokens | 91.5% | | Large (11 msgs) | 1,506 tokens | 98 tokens | 93.5% |

Search Accuracy (Keyword-based, no embeddings)

| Query | Expected Topic | Found? | Score | |-------|---------------|--------|-------| | "sorting dictionaries python" | pythonsorting | ❌ | 0.000 | | "Promise.all JavaScript" | javascriptasync | ❌ | 0.500 | | "Docker multi-stage build" | dockerdeploy | βœ… | 0.667 | | "SQL query optimization" | sqloptimization | βœ… | 0.667 | | "React state management" | react_state | βœ… | 0.333 |

Keyword search: 60% accuracy β€” semantic search with OpenAI embeddings achieves near-perfect accuracy (95%+)

Index Performance

| Size | Add (per msg) | Search | Save | Load | |------|--------------|--------|------|------| | 100 msgs | 0.04ms |

Built with ❀️ for AI agents everywhere

[⬆ Back to top](#-contextkit)

Source & license

This open-source MCP server is cataloged on AgentStack and links to its original source β€” we do not rehost the code.

Install and usage instructions live in the source repository linked above.

Reviews

No reviews yet β€” be the first.

Versions

  • v0.1.0 Imported from the upstream source.