Slimcontext Mcp Server

io.github.agentailor由 GitHub 账号 agentailor 发布v0.1.2更新于 Oct 24, 2026

MCP Server for SlimContext - AI chat history compression tools

已验证STDIO仅桌面开发者工具AI 与机器学习

概览

AI 生成的概览

封装 SlimContext 库的本地 MCP 服务器,为助手提供两个工具,通过裁剪或摘要来压缩 AI 聊天历史。

可以做什么
  • 按 token 裁剪压缩聊天历史,删除最旧的非系统消息直到低于阈值
  • 通过 AI 摘要压缩聊天历史,把对话中段浓缩为一条摘要消息
  • 可调整模型 token 窗口、阈值百分比、保留的最近消息数、OpenAI 模型和自定义摘要提示词
  • 返回包含原始与压缩后消息数、删除条数和压缩比的结构化结果,或结构化错误响应
适用场景
当对话超出模型上下文窗口、需要在继续之前压缩时适用,可选择不依赖外部调用的确定性裁剪,或用 AI 生成旧对话的摘要。
运行要求
以 stdio 在本地运行,通常通过 npx 启动 npm 包 slimcontext-mcp-server(需要 Node.js)。摘要工具需要 OpenAI API 密钥,可通过 OPENAI_API_KEY 环境变量或 openaiApiKey 工具参数提供,并需要访问 OpenAI 的网络连接。
安装前请注意
摘要工具会把对话中段发送给 OpenAI,聊天内容会离开本机;API 密钥可作为工具参数或环境变量传入。裁剪会从返回的历史中永久删除较早消息,且 token 计数只是粗略估算。

安装

在 SourceWeft 中

  1. 打开 控制台中的 Slimcontext Mcp Server,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

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:

  1. trim_messages - Token-based compression that removes oldest messages when exceeding token thresholds
  2. summarize_messages - AI-powered compression using OpenAI to create concise summaries

Installation

bash
npm install -g slimcontext-mcp-server# orpnpm add -g slimcontext-mcp-server

Development

bash
# Clone and setupgit clone <repository>cd slimcontext-mcp-serverpnpm install
# Buildpnpm build
# Run in developmentpnpm dev
# Type checkingpnpm typecheck

Configuration

MCP Client Setup

Add to your MCP client configuration:

json
{  "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 messages
  • maxModelTokens (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:

json
{  "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:

json
{  "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 messages
  • maxModelTokens (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:

json
{  "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:

json
{  "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:

typescript
interface SlimContextMessage {  role: 'system' | 'user' | 'assistant' | 'tool' | 'human';  content: string;}

Error Handling

All tools return structured error responses:

json
{  "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

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Submit a pull request

Related

来源:README.md,提交 e269b85

工具

0
SourceWeft 尚未在沙箱中启动过该软件包,因此其工具未知。

版本历史

1
  1. v0.1.2最新Sep 16, 2026

评分

已满足适用检查项的 40%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分

    请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。

  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具15 分

    请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。

  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分

    请在仓库或注册中心条目中声明许可证。