context-slim
ContextSlim
在不丢失关键代码语义的情况下,节省 50% 以上的 AI 上下文 token。
代码:github.com/lilite572-cyber/context-slim · 安装:@idmxgne/context-slim(npm 账户 idmxgne)。不是 Jagganu 的 context-slim(CLI 输出修剪器)。
Cursor、Claude 和其他编码代理在每一轮都会重新读取整个文件。其中大部分预算花在 JSDoc、未使用的导入和 DTO 映射器上。ContextSlim 解析 JS/TS(Babel)和 PHP(php-parser),掏空噪音,并保留 try/catch、认证方法、env() / process.env,以及 FIXME / SECURITY / В ПРОД НЕ ГНАТЬ 等标记。
之前 / 之后
在 tests/fixtures/real_world_controller.ts(--signatures-only)中的真实计费控制器上测量:
Token 数 | 保留内容 | |
之前 | 3,522 | 注释、映射器、未使用的导入、每个方法体 |
之后 | 1,408 | 签名 + 关键方法体 + 受保护的注释 |
节省 | 60%(保留 10 个标签) | try/catch、 |
CLI 统计使用 gpt-tokenizer(o200k_base,GPT-4o / GPT-5 系列)并输出到 stderr。精简后的源码输出到 stdout。
npx -y --package=@idmxgne/context-slim context-slim .
# Исходный размер: 3,522 токенов -> Сжатый: 1,408 токенов. Экономия: 60% ...二进制文件是 context-slim,不是 @idmxgne/context-slim。作用域 npx @idmxgne/context-slim . 会失败并显示 command not found。
Related MCP server: cctx-mcp
快速开始
npx -y --package=@idmxgne/context-slim context-slim .
npx -y --package=@idmxgne/context-slim context-slim ./src --signatures-only
npx -y --package=@idmxgne/context-slim context-slim ./src --out slim.txt
npx -y --package=@idmxgne/context-slim context-slim-mcp从克隆开始:
npm i && npm run build
node dist/cli.js ./srcMCP 服务器(Cursor、Windsurf、Claude Code)
二进制:context-slim-mcp → dist/mcp.js。官方 @modelcontextprotocol/sdk Server + StdioServerTransport。不要将日志写入 stdout。
提示 use-slim-context:
读取源代码文件时,始终优先使用
read_slim_file工具以优化上下文窗口。
工具:
工具 | 参数 | 结果 |
|
| 压缩后的源码 |
| 无 | 上次运行:之前/之后的 token、节省的 |
Cursor
合并到 ~/.cursor/mcp.json(现成副本:examples/cursor-mcp.json):
{
"mcpServers": {
"context-slim": {
"command": "node",
"args": ["/ABSOLUTE/PATH/TO/context-slim/dist/mcp.js"]
}
}
}npm publish 之后:
{
"mcpServers": {
"context-slim": {
"command": "npx",
"args": ["-y", "--package=@idmxgne/context-slim", "context-slim-mcp"]
}
}
}重启 Cursor,让代理对臃肿的控制器执行 read_slim_file。
Windsurf
在 Windsurf 的 MCP 配置(~/.codeium/windsurf/mcp_config.json,或设置中的 MCP 面板)中使用相同的 mcpServers 块。将 command 指向 node + dist/mcp.js,或像上面那样指向 npx。
Claude Code / Claude Desktop
Claude Desktop — 将 examples/claude_desktop_config.json 合并到 claude_desktop_config.json:
{
"mcpServers": {
"context-slim": {
"command": "node",
"args": ["/ABSOLUTE/PATH/TO/context-slim/dist/mcp.js"]
}
}
}Claude Code:
claude mcp add context-slim -- node /ABSOLUTE/PATH/TO/context-slim/dist/mcp.js安全标签(.contextslimrc + isCriticalNode)
当 isCriticalNode 如此声明时,节点永远不会被掏空:
匹配 CRITICAL、FIXME、TODO、SECURITY、DONT TOUCH、
В ПРОД НЕ ГНАТЬ、@keep的注释try/catch名称看起来像认证的方法(
authorize、login、jwt、csrf等)env()、getenv()、process.envPHP/Laravel:
$this->hasMany/$this->belongsTo(以及其他 Eloquent 关系)和scope*方法
仓库:https://github.com/lilite572-cyber/context-slim
在项目根目录的 .contextslimrc 中添加额外短语:
{
"keep_patterns": ["HACK", "LEGACY"]
}entry_patterns(默认值:index / cli / main / app / server)即使没有 --signatures-only 也会保留普通函数体。依赖文件会被掏空;传递 --signatures-only(或 MCP signaturesOnly: true)以掏空所有非关键内容。
安装 / 发布
npm i
npm test
npm run build二进制:context-slim → ./dist/cli.js,context-slim-mcp → ./dist/mcp.js。npm:@idmxgne/context-slim。GitHub:lilite572-cyber/context-slim。许可证:MIT。
许可证
MIT
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- AlicenseAqualityCmaintenanceMCP server that reduces token consumption in AI coding assistants by up to 90% via structural reads, PreToolUse hooks, and tp-\* subagents.254254MIT
- AlicenseNot gradedqualityCmaintenanceAn MCP server that provides structure-aware code analysis (symbol trees, dependencies, docs) to reduce AI agent token consumption by up to 99%, along with Git commit intelligence.MIT
- AlicenseAqualityBmaintenanceAn AST-based MCP server that provides token-efficient codebase skeletons to LLM agents, reducing context token usage by 80-95% by exposing structural information instead of full source files.5122MIT
- -licenseNot gradedqualityNot gradedmaintenanceAST-aware code exploration MCP server for AI agents, optimized for token efficiency.
Related MCP Connectors
An MCP server that gives your AI access to the source code and docs of all public github repos
A comprehensive Model Context Protocol (MCP) server that enables AI assistants to interact with yo…
MCP server for AI agents to plan, verify, and deploy Cloudflare-native apps.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/lilite572-cyber/context-slim'
If you have feedback or need assistance with the MCP directory API, please join our Discord server