npm slimcontext-mcp-serverstdioupdated 11mo ago
A Model Context Protocol (MCP) server that wraps the SlimContext library, providing AI chat history compression tools for MCP-compatible clients.
このリポジトリは所有者によってアーカイブされました。動作はしますが、更新はされません。
slimcontext mcp server で何ができる?
SlimContext MCP Server
A Model Context Protocol (MCP) server that wraps the SlimContext library, providing AI chat history compression tools for MCP-compatible clients.
Overview
SlimContext MCP Server exposes two powerful compression strategies as MCP tools:
trim_messages- Token-based compression that removes oldest messages when exceeding token thresholdssummarize_messages- AI-powered compression using OpenAI to create concise summaries
Installation
npm install -g slimcontext-mcp-server
# or
pnpm add -g slimcontext-mcp-server
Development
# Clone and setup
git clone <repository>
cd slimcontext-mcp-server
pnpm install
# Build
pnpm build
# Run in development
pnpm dev
# Type checking
pnpm typecheck
Configuration
MCP Client Setup
Add to your MCP client configuration:
{
"mcpServers": {
"slimcontext": {
"command": "npx",
"args": ["-y", "slimcontext-mcp-server"]
}
}
}
Environment Variables
OPENAI_API_KEY: OpenAI API key for summarization (optional, can be passed as tool parameter)
Tools
trim_messages
Compresses chat history using token-based trimming strategy.
Parameters:
messages(required): Array of chat messagesmaxModelTokens(optional): Maximum model token context window (default: 8192)thresholdPercent(optional): Percentage threshold to trigger compression 0-1 (default: 0.7)minRecentMessages(optional): Minimum recent messages to preserve (default: 2)
Example:
{
"messages": [
{ "role": "system", "content": "You are a helpful assistant." },
{ "role": "user", "content": "Hello!" },
{ "role": "assistant", "content": "Hi there! How can I help you today?" },
{ "role": "user", "content": "Tell me about AI." }
],
"maxModelTokens": 4000,
"thresholdPercent": 0.8,
"minRecentMessages": 2
}
Response:
{
"success": true,
"original_message_count": 4,
"compressed_message_count": 3,
"messages_removed": 1,
"compression_ratio": 0.75,
"compressed_messages": [
{ "role": "system", "content": "You are a helpful assistant." },
{ "role": "assistant", "content": "Hi there! How can I help you today?" },
{ "role": "user", "content": "Tell me about AI." }
]
}
summarize_messages
Compresses chat history using AI-powered summarization strategy.
Parameters:
messages(required): Array of chat messagesmaxModelTokens(optional): Maximum model token context window (default: 8192)thresholdPercent(optional): Percentage threshold to trigger compression 0-1 (default: 0.7)minRecentMessages(optional): Minimum recent messages to preserve (default: 4)openaiApiKey(optional): OpenAI API key (can also use OPENAI_API_KEY env var)openaiModel(optional): OpenAI model for summarization (default: 'gpt-4o-mini')customPrompt(optional): Custom summarization prompt
Example:
{
"messages": [
{ "role": "system", "content": "You are a helpful assistant." },
{ "role": "user", "content": "I want to build a web scraper." },
{
"role": "assistant",
"content": "I can help you build a web scraper! What programming language would you prefer?"
},
{ "role": "user", "content": "Python please." },
{
"role": "assistant",
"content": "Great choice! For Python web scraping, I recommend using requests and BeautifulSoup..."
},
{ "role": "user", "content": "Can you show me a simple example?" }
],
"maxModelTokens": 4000,
"thresholdPercent": 0.6,
"minRecentMessages": 2,
"openaiModel": "gpt-4o-mini"
}
Response:
{
"success": true,
"original_message_count": 6,
"compressed_message_count": 4,
"messages_removed": 2,
"summary_generated": true,
"compression_ratio": 0.67,
"compressed_messages": [
{ "role": "system", "content": "You are a helpful assistant." },
{
"role": "system",
"content": "The user expressed interest in building a web scraper and requested help with Python. The assistant recommended using requests and BeautifulSoup libraries for Python web scraping."
},
{
"role": "assistant",
"content": "Great choice! For Python web scraping, I recommend using requests and BeautifulSoup..."
},
{ "role": "user", "content": "Can you show me a simple example?" }
]
}
Message Format
Both tools expect messages in SlimContext format:
interface SlimContextMessage {
role: 'system' | 'user' | 'assistant' | 'tool' | 'human';
content: string;
}
Error Handling
All tools return structured error responses:
{
"success": false,
"error": "Error message description",
"error_type": "SlimContextError" | "OpenAIError" | "UnknownError"
}
Common error scenarios:
- Missing OpenAI API key for summarization
- Invalid message format
- OpenAI API rate limits or errors
- Invalid parameter values
Token Estimation
SlimContext uses a simple heuristic for token estimation: Math.ceil(content.length / 4) + 2. This provides a reasonable approximation for most use cases. For more accurate token counting, you would need to implement a custom token estimator in your client application.
Compression Strategies
Trimming Strategy
- Preserves all system messages
- Preserves the most recent N messages
- Removes oldest non-system messages until under token threshold
- Fast and deterministic
- No external API dependencies
Summarization Strategy
- Preserves all system messages
- Preserves the most recent N messages
- Summarizes middle portion of conversation using AI
- Creates contextually rich summaries
- Requires OpenAI API access
License
MIT
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Submit a pull request
Related
- SlimContext - The underlying compression library
- Model Context Protocol - The protocol specification
- MCP SDK - TypeScript SDK for MCP
インストール
slimcontext mcp server をクライアントに追加します。お使いのものを選んでください。
claude mcp add slimcontext-mcp-server -- npx -y slimcontext-mcp-servercodex mcp add slimcontext-mcp-server -- npx -y slimcontext-mcp-serveramp mcp add slimcontext-mcp-server -- npx -y slimcontext-mcp-server{
"mcpServers": {
"slimcontext-mcp-server": {
"command": "npx",
"args": [
"-y",
"slimcontext-mcp-server"
]
}
}
}Add to `claude_desktop_config.json`, then restart Claude Desktop.
{
"mcpServers": {
"slimcontext-mcp-server": {
"command": "npx",
"args": [
"-y",
"slimcontext-mcp-server"
]
}
}
}Add to `~/.cursor/mcp.json`, or `.cursor/mcp.json` for a single project.
code --add-mcp '{"name":"slimcontext-mcp-server","command":"npx","args":["-y","slimcontext-mcp-server"]}'Or add the block manually to `.vscode/mcp.json` under `servers`.
{
"mcpServers": {
"slimcontext-mcp-server": {
"command": "npx",
"args": [
"-y",
"slimcontext-mcp-server"
]
}
}
}Add to `~/.codeium/windsurf/mcp_config.json`.
{
"mcpServers": {
"slimcontext-mcp-server": {
"command": "npx",
"args": [
"-y",
"slimcontext-mcp-server"
]
}
}
}Add to `cline_mcp_settings.json` via the MCP Servers panel.
{
"mcpServers": {
"slimcontext-mcp-server": {
"command": "npx",
"args": [
"-y",
"slimcontext-mcp-server"
]
}
}
}Add to `~/.gemini/settings.json`.
{
"mcpServers": {
"slimcontext-mcp-server": {
"type": "local",
"command": "npx",
"args": [
"-y",
"slimcontext-mcp-server"
],
"tools": [
"*"
]
}
}
}Add to `~/.copilot/mcp-config.json`, or run `/mcp add` inside the CLI.
{
"context_servers": {
"slimcontext-mcp-server": {
"command": {
"path": "npx",
"args": [
"-y",
"slimcontext-mcp-server"
]
}
}
}
}Add to your Zed `settings.json`.
npx -y slimcontext-mcp-serverRun `goose configure`, choose **Add Extension → Command-line Extension**, and paste this command.
スコア
39 / 100
情報不足
- ドキュメント25/25
- メンテナンス4/25
- 信頼性9/20
- 機能0/15
- 導入のしやすさ12/15
- Documents what it does and how to connect
- Has a resolvable package or endpoint
- Exposes at least one tool, prompt or resource
- README has substantive content
- Includes a code example
- Documents its configuration
- Mentions credentials or security posture
- Last commit 348 days ago
- Has a release history
- Repository is not archived
- No licence detected
- Namespace verified in the official MCP registry
- Claimed by its owner
- Published under an organisation
- 0 tool(s) documented
- Provides prompt templates
- Provides resources
- 12 documented install method(s)
- Published to a package registry
- Offers a hosted endpoint — no local install
バージョン履歴
| バージョン | 公開日 |
|---|---|
| 0.1.2最新 | 2025年9月16日 |
| 0.1.1 | 2025年9月10日 |