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 分

    請在儲存庫或註冊中心條目中宣告授權條款。