寻呼Cmd MCP服务器
一种模型上下文协议(MCP)服务器,在处理大型命令输出时防止输出截断。非常适合确保AI代理可以访问和分析完整的命令结果,而不会达到上下文限制。
为什么使用这个?
当运行产生大量输出的shell命令时(如 git diff, git log, cat large_file.txt,或测试结果),Claude和其他AI代理经常截断输出或无法处理整个内容。这会导致分析不完整和信息缺失。
Paginate MCP通过以下方式解决了这个问题:
- 防止截断 -自动处理超过5000个令牌的输出
- 保留完整的上下文 -确保代理可以通过分页访问所有输出
- 无缝集成 -与现有工作流透明地协同工作
设置
克劳德代码
使用一个命令将此MCP服务器添加到Claude Code中:
claude mcp add paginate_mcp npx paginate-mcp@latest克劳德桌面
直接与npx一起使用,无需任何安装:
npx paginate-mcp或者添加到您的Claude桌面或配置中:
MacOS: ~/Library/Application Support/Claude/claude_desktop_config.json 视窗: %APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"paginate-mcp": {
"command": "npx",
"args": ["-y", "paginate-mcp@latest"]
}
}
}其他MCP客户端
直接与npx一起使用,无需任何安装:
npx paginate-mcp示例用法
配置后,您可以向Claude提出通常会导致输出截断的问题:
Read git diff against origin/main using paginate-mcp and present me some suggestions to improve it其他有用的例子:
- “使用分页mcp运行完整的测试套件并分析所有故障”
- “使用分页mcp读取昨天的整个应用程序日志并识别错误模式”
- “使用分页mcp显示最近100次提交的完整git日志”
工具
run_paginated_cmd
执行shell命令并捕获其输出。
参数:
command(必填):要执行的shell命令working_directory(可选):命令执行的工作目录timeout(可选):超时秒数(默认值:30)
退货:
- 如果输出\5000个令牌:分页响应
output_id用于检索
示例(小输出):
{
"status": "complete",
"output": "=== STDOUT ===\nHello World\n\n=== STDERR ===\n\n=== Return Code: 0 ===",
"estimated_tokens": 25,
"command": "echo 'Hello World'",
"return_code": 0
}示例(大输出):
{
"status": "paginated",
"output_id": "uuid-here",
"message": "Output too large (25000 estimated tokens). Use 'read_output_page' tool to retrieve all 5 pages sequentially.",
"instruction": "IMPORTANT: You must paginate through ALL 5 pages...",
"command": "cat large_file.txt",
"return_code": 0,
"total_pages": 5,
"total_lines": 3421,
"estimated_tokens": 25000
}read_output_page
检索存储的命令输出的特定页面。
参数:
output_id(必填):分页响应中的IDpage(必填):要检索的页码(1-索引)
退货:
{
"output_id": "uuid-here",
"command": "cat large_file.txt",
"page": 2,
"total_pages": 5,
"pages_read": [1, 2],
"all_pages_read": false,
"content": "page content here...",
"has_next": true,
"has_previous": true
}令牌估计
服务器估计令牌为 text.length * 0.25这是一个保守的估计,以确保输出符合克劳德的上下文窗口。
分页行为
- 页面大小:每页700行
- 字符限制:每页30000个字符(硬限制)
- 自动清理:读取所有页面后,输出存储将自动清理
依赖项
生产
@modelcontextprotocol/sdk-MCP协议实现
发展
typescript-TypeScript编译器@types/node-Node.js类型定义
内置模块(无需安装)
child_process-命令执行crypto-UUID生成util-Promise实用程序
运作原理
sequenceDiagram
participant Agent as AI Agent
participant MCP as Paginate-MCP Server
participant Shell as Shell Command
participant Storage as In-Memory Storage
Agent->>MCP: run_paginated_cmd("git log --all")
MCP->>Shell: Execute command
Shell-->>MCP: Full output (stdout/stderr)
alt Output >Agent: Return complete output immediately
else Output > 10,000 tokens
MCP->>Storage: Store full output with UUID
MCP-->>Agent: Return {status: "paginated", output_id, total_pages}
loop For each page
Agent->>MCP: read_output_page(output_id, page_num)
MCP->>Storage: Retrieve page (700 lines)
Storage-->>MCP: Page content
MCP->>Storage: Mark page as read
MCP-->>Agent: Page content + metadata
end
Note over MCP,Storage: After all pages read
MCP->>Storage: Auto-cleanup output
end服务器维护两个内存中的数据结构:
outputStorage:存储分页的完整命令输出pagesRead:跟踪已检索到的页面
当输出的所有页面都已读取时,存储会自动清理。
特性
- 使用完整的stdout/stderr捕获执行shell命令
- 超过10000个令牌的输出自动分页
- 基于页面的大输出检索(每页700行或30KB)
- MCP SDK之外没有外部依赖关系
- 具有完全类型安全的TypeScript实现
许可证
麻省理工学院
