Summarization Functions

Summarization Functions

提供来自各种可能消耗大量令牌并导致AI代理崩溃的操作的摘要输出。

MCP 智能摘要功能快速指南

npm版本

概述

MCP摘要功能提供智能文本摘要服务,用于解决AI代理上下文窗口管理问题,防止因大量输出导致的上下文溢出。

安装

npm i mcp-summarization-functions

配置

.env文件或环境变量中设置:

# 必需
PROVIDER=ANTHROPIC|OPENAI|OPENAI-COMPATIBLE|GOOGLE
API_KEY=your-api-key

# 可选
MODEL_ID=claude-3-5-sonnet-20241022  # 默认为提供商标准模型
PROVIDER_BASE_URL=custom-url         # 用于OPENAI-COMPATIBLE
MCP_WORKING_DIR=default_directory    # 文件操作回退目录

MCP服务器配置

{
  "mcpServers": {
    "MUST_USE_summarization": {
      "command": "node",
      "args": ["path/to/summarization-functions/build/index.js"],
      "env": {
        "PROVIDER": "ANTHROPIC",
        "API_KEY": "your-api-key",
        "MODEL_ID": "claude-3-5-sonnet-20241022"
      }
    }
  }
}

功能用法

命令摘要

// 执行并摘要命令
{
  command: "npm list",
  cwd: "/path/to/project",
  hint: "dependencies",     // 可选
  output_format: "markdown" // 可选
}

文件摘要

// 摘要一个或多个文件
{
  paths: ["package.json", "README.md"],
  cwd: "/path/to/project",
  hint: "api_surface",      // 可选
  output_format: "json"     // 可选
}

目录摘要

// 获取目录结构概览
{
  path: "src",
  cwd: "/path/to/project",
  recursive: true,         // 可选
  output_format: "outline" // 可选
}

文本摘要

// 摘要任意文本
{
  content: "大量文本内容...",
  type: "log output",
  hint: "error_handling",  // 可选
  output_format: "text"    // 可选
}

AI代理集成提示

在AI代理指令中添加:

您必须对所有可能的大型输出使用摘要功能以防止上下文溢出:
• 命令输出:summarize_command
• 文件内容:summarize_files
• 目录结构:summarize_directory
• 其他文本:summarize_text

始终优先选择摘要内容,而不是处理完整输出。

支持的输出格式

  • text: 纯文本摘要
  • markdown: 带格式的Markdown
  • json: 结构化JSON对象
  • outline: 分层概述格式

分析提示选项

  • security_analysis: 安全相关问题
  • api_surface: API定义和接口
  • error_handling: 错误处理模式
  • dependencies: 依赖关系分析
  • type_definitions: 类型系统和定义