安静的外壳
MCP服务器,执行带有智能输出过滤的shell命令,以减少AI代理上下文消耗。
问题
当AI编码助手执行shell命令(特别是测试和构建)时,他们会收到数千行详细的输出,这些输出:
- 消耗有价值的上下文窗口令牌
- 在噪音中隐藏重要信息(错误、故障)
- 难以专注于可操作的反馈
示例:运行50个通过和2个失败的测试会生成2000多行输出,但代理只需要显示失败和摘要的约20行。
解决方案
quiet shell使用可配置模板执行命令并智能过滤输出:
- 正则表达式过滤:仅保留与错误模式匹配的行
- 尾部段落:始终包括摘要部分
- 结果解释:快速成功/失败状态
- 内置模板:为常用工具(tsc、vitest、maven、pulumi)预配置
- 自定义模板:为每个存储库定义自己的筛选器
安装
npm install -g @codemcp/quiet-shell或者使用pnpm:
pnpm add -g @codemcp/quiet-shellMCP客户端配置
克劳德桌面版
添加 ~/Library/Application Support/Claude/claude_desktop_config.json:
{
"mcpServers": {
"quiet-shell": {
"command": "npx",
"args": ["-y", "@codemcp/quiet-shell"]
}
}
}其他MCP客户端
使用以下命令: npx @codemcp/quiet-shell
服务器按照模型上下文协议规范通过stdio进行通信。
用法
可用工具
execute_command
执行带有可选输出过滤的shell命令。
参数:
command(必需):要执行的Shell命令template(可选):筛选器模板名称(使用list_templates查看可用)suppress_output_on_success(可选,默认值:true):命令成功时抑制输出(退出代码0)。吃起来false即使成功,也要始终展示成果
答复:
{
"result": "success",
"exit_code": 0,
"output": "filtered output here",
"template_used": "vitest"
}示例:
// Run tests with filtering
execute_command("npm test", "vitest");
// Returns: only failed tests + summary (~20 lines instead of 2000+)
// If tests pass: output suppressed (default behavior)
// TypeScript compilation
execute_command("tsc --noEmit", "tsc");
// Returns: only type errors + summary
// If compilation succeeds: output suppressed (default behavior)
// Always show output even on success
execute_command("npm test", null, false); // suppress_output_on_success = false
// Returns: complete output regardless of exit code
// Raw output with default suppression
execute_command("echo hello");
// If successful: "Command completed successfully (output suppressed - exit code 0)"list_templates
列出所有可用的过滤模板及其说明。
答复:
{
"templates": [
{
"name": "vitest",
"description": "Use when running tests with Vitest - returns failed tests and test summary",
"include_regex": "(FAIL|ERROR|✖|❯.*failed)",
"tail_paragraphs": 2
},
...
],
"count": 4
}内置模板
- tsc:TypeScript编译器-返回类型错误和摘要
- 请柬:Vitest测试-返回测试失败和总结
- maven构建:Maven build-返回构建错误和摘要
- maven测试:Maven测试-返回测试失败和摘要
- 膨胀:Pulumi部署-抑制详细的资源进度,仅显示错误、警告、失败和最终摘要
自定义模板
创建 .quiet-shell/config.yaml 在您的存储库中:
templates:
jest:
description: "Use when running tests with Jest - returns failed tests and test summary"
include_regex: "(FAIL|●|✕)"
tail_paragraphs: 2
eslint:
description: "Use when running ESLint - returns linting errors and summary"
include_regex: "(error|warning|✖)"
tail_paragraphs: 1
# Template that always shows success output
build-with-stats:
description: "Build command that shows statistics even on success"
include_regex: "(error|warning|built|compiled)"
tail_paragraphs: 2
suppress_output_on_success: false # Override default suppression特征:
- 自定义模板扩展了内置模板
- 自定义模板可以覆盖内置模板(同名)
- 配置受版本控制,并与团队共享
- 服务器通过从当前目录向上搜索来发现配置
运作原理
模板结构
每个模板定义:
include_regex:匹配重要行的模式(错误、失败)tail_paragraphs:从末尾开始包括的段落数(摘要)description:何时使用此模板(用于代理发现)
过滤算法
- 解析 输出为段落(用空行分隔的行组)
- 过滤器 线条匹配
include_regex - 提取 最后N段(摘要)
- 合并 重复数据删除(保持顺序)
- 返回 滤波输出
示例
输入 (2000行):
✓ test 1 passed
✓ test 2 passed
... (48 more passing tests)
✖ test 51 failed
Expected: true
Received: false
✖ test 52 failed
Error: timeout
Tests: 50 passed, 2 failed, 52 total
Time: 5.2s输出与 vitest 模板 (约10行):
✖ test 51 failed
Expected: true
Received: false
✖ test 52 failed
Error: timeout
Tests: 50 passed, 2 failed, 52 total
Time: 5.2s发展
Monorepo结构
packages/
core/ # @codemcp/quiet-shell-core
# Reusable filtering logic
mcp-server/ # @codemcp/quiet-shell
# MCP protocol implementation构建
pnpm install
pnpm build测试
pnpm test使用MCP检查员进行测试
npx @modelcontextprotocol/inspector npx @codemcp/quiet-shell建筑
- 日志记录器:依赖注入记录器(仅stderr,从不stdout)
- 模板管理器:使用60s缓存TTL加载配置
- 令执行器:生成命令,捕获stdout/stderr
- 输出滤波器:基于段落的正则表达式过滤
- MCP 服务器:stdio传输,结构化JSON响应
需求
- Node.js>=18
- pnpm>=9(用于开发)
许可证
麻省理工学院
贡献
欢迎投稿!本项目使用:
- 具有严格模式的TypeScript
- Vitest用于测试
- ESLint+代码质量预处理
- 用于monorepo构建的Turbo
学分
与 模型上下文协议 SDK。
