context-slicer
ContextSlicer
Cut AI token usage without deleting a single message.
Normally, AI chats re-send and re-read the entire conversation history on every turn—wasting thousands of tokens on unrelated turns and dead-end brainstorming. ContextSlicer is a non-destructive context filter that keeps your full chat history archived while sending the AI only the specific context it needs to complete the active task.
Zero npm dependencies. Built with pure Node.js CommonJS, stdio JSON-RPC 2.0, and a single-file Cloudflare Worker.
Why ContextSlicer?
Sends only what the task needs: Instead of replaying the entire chat on every request, ContextSlicer filters the history down to only the relevant context and key decisions required for the current task.
Non-destructive by design: All raw turns remain safely archived in
this.archive(or local JSON storage)—nothing is ever deleted from your chat.Auto-switches on build triggers: During brainstorming (
chatmode), it includes compact working memory, keyword-recalled turns, and the recent window. When you trigger execution ("build it","build the app","write the code","start coding"), it drops the brainstorm window and sends only the distilled task essentials ([WORKING_MEMORY] + current_message).
Related MCP server: genpark-agent-context-dynamic-compressor-skill
Architecture
SDK (
src/core.js):ContextSlicerkeeps all raw turns inthis.archiveand maintains a compactspecCard(goal,decisions,constraints,rejected, plus custom categories likenote) via<spec cat="...">...</spec>tags.Chat mode:
[WORKING_MEMORY] + keyword-recalled turns + last N turns + userMsgExecute mode: Triggered automatically on build phrases — drops brainstorm clutter and sends only the essential spec +
userMsg.
Proxy (
src/proxy.js&bin/cli.js): OpenAI-compatible streaming proxy withGET /health,GET /stats,GET /v1/models,OPTIONSCORS,POST /v1/chat/completions(stream: trueSSE passthrough),X-Context-Savedheader, 100-session LRU RAM cap, and optionalSLICER_KEYauth.MCP (
src/mcp.js): Zero-dependency stdio JSON-RPC 2.0 server exposingslice_and_retrieve,save_slice,get_slice,list_slices, anddelete_slicebacked by a local JSON file.Cloudflare Worker (
worker.js) & Product Site (index.html): Free-tier single-file Cloudflare Worker proxy + dark-mode 1-page site.
Quick Start
Proxy
npm start
# or
npx context-slicer serve --port 8787 --upstream https://api.openai.comMCP Server
npm run mcp
# or
node src/mcp.jsSDK
const { ContextSlicer } = require('./src/core');
const slicer = new ContextSlicer({ windowSize: 6 });
slicer.addTurn('user', 'Build a CLI <spec cat="goal">Zero-dep CLI</spec>');
const messages = slicer.buildMessages('build it'); // switches to execute modeCloudflare Worker
Deploy worker.js directly with Wrangler or paste into the Cloudflare Workers dashboard (no KV or credit card required).
License
MIT
Available Tools
5 toolsdelete_sliceB
Delete a saved ContextSlicer slice by ID from local JSON storage.
Inputs: id (required).
get_sliceC
Retrieve a saved ContextSlicer working-memory slice by ID.
Inputs: id (required).
list_slicesA
List all saved ContextSlicer slices from local JSON storage.
Inputs: limit.
save_sliceB
Save or update a non-destructive ContextSlicer working-memory slice (goal, decisions, constraints, rejected, or tagged turn content) in local JSON storage.
Inputs: id (required), goal, role, content, +3 more.
slice_and_retrieveC
Non-destructively archive previous_context, update working_summary, and retrieve only the context needed for current_message so the AI can execute immediately with minimal tokens.
Inputs: current_message (required), previous_context (required), id.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 5 tools
The CRUD tools (get_slice, save_slice, list_slices, delete_slice) have clearly distinct targets. The main confusion risk is between slice_and_retrieve and get_slice (both 'retrieve'), plus slice_and_retrieve's 'update working_summary' overlapping save_slice's update behavior, but the descriptions make the composite orchestration role reasonably clear.
Four tools follow a clean verb_noun snake_case pattern (get_slice, save_slice, list_slices, delete_slice) with consistent pluralization on the collection tools. slice_and_retrieve breaks the pattern as a verb_and_verb compound with no object noun, though it remains readable and snake_case.
Five tools is well-scoped: a complete CRUD surface over slices plus one orchestration entry point. Nothing feels padded or missing for the stated purpose.
Full lifecycle coverage exists (create/update via save_slice, read via get_slice, enumerate via list_slices, remove via delete_slice) plus the main workflow tool. Minor gaps: no way to filter/search slices beyond listing all, and no standalone way to read the current working_summary without invoking the full slice_and_retrieve flow.
Maintenance
Related MCP Connectors
Persistent memory, hybrid search and a goal graph for AI agents, over stdio or remote HTTP.
Your portable context layer — load it into any AI.
Share one project context across ChatGPT, Claude, Telegram and any MCP client.
Persistent memory layer for AI clients: store, recall, and correct context across tools.
Related MCP Servers
- AlicenseBqualityDmaintenanceEnables AI tools to query context from a local JSON data source via stdio, demonstrating the Model Context Protocol.28MIT
- FlicenseNot gradedqualityBmaintenanceEnables AI agents and MCP-compliant clients to dynamically shrink long-horizon context windows, pruning verbose tool outputs, HTML boilerplate, and semantic redundancy by roughly 40-70% without frontier LLM round-trips. Runs deterministically as a zero-dependency Python stdio server, accepting a payload plus optional compression and risk-bound options.7-
- AlicenseNot gradedqualityNot gradedmaintenanceEnables agents to deterministically shrink multi-turn conversation history and prompts by stripping verbose boilerplate and filler tokens while preserving critical tool parameters and named entities. This lets users cut inference costs by roughly 40-60% without losing essential context, running either as a native MCP server over JSON-RPC stdio or as an importable zero-dependency Python module.MIT
- AlicenseNot gradedqualityCmaintenanceEnables AI agents to search and manage a local Markdown memory vault over stdio, including hybrid search, note retrieval and addition, session handoff claiming, and status checks without holding a model in memory.MIT