LLM测试协议服务器

Moonshot MCP Server是一个提供自然语言接口的模型上下文协议服务器,用于通过AI Verify的Moonshot框架测试LLM应用程序。

  • by aisingapore
  • JavaScript
  • 本地部署
  • 更新于
在 GitHub 查看 aisingapore/moonshot-mcp-server

使用说明

Moonshot MCP服务器

一个模型上下文协议(MCP)服务器,为AI Verify的Moonshot框架提供自然语言接口,用于测试LLM应用程序。

概述

此MCP服务器允许开发人员使用自然语言命令根据AI Verify的全面测试框架测试他们的LLM应用程序。开发人员可以简单地用简单的英语描述他们想要测试的内容,而不是编写复杂的测试配置。

特性

  • 自然语言测试:用简单的英语描述你的测试需求
  • 综合测试套件:访问50多本预制食谱和100多个数据集
  • 多种LLM支持:针对OpenAI、Anthropic、AWS Bedrock、Azure、Google等进行测试
  • 红队判研:使用攻击模块进行交互式对抗测试
  • 项目管理:保存和重用测试配置
  • 智能测试选择:根据您的要求,通过人工智能选择相关测试
  • 多测试支持:目前支持每个数据集或攻击模块进行单个基准测试和/或红队测试,但支持多个数据集和攻击模块。
  • 免责声明:并非所有测试都能正常工作,因为这纯粹是一个概念验证,可能会出现数据集地面真实错误或某些示例可能失败的情况。欢迎为修复和功能改进做出任何贡献!

安装

# Make a new project directory
mkdir <project-directory>
cd <project-directory>

# PREREQUISITES - Clone these repositories
# Note: Some files in moonshot and moonshot-data have been revised in these new repositories.
git clone https://github.com/aisingapore/moonshot-mcp-server.git
git clone https://github.com/aisingapore/revised-moonshot.git
git clone https://github.com/aisingapore/revised-moonshot-data.git
git clone https://github.com/aisingapore/revised-moonshot-ui.git

# Set up the data directory symlink to revised-moonshot-data
cd revised-moonshot
sed -i 's/\r$//' setup_data_link.sh
bash setup_data_link.sh

# Set up virtual environment
uv sync            # Creates .venv using pyproject.toml - requires-python = "==3.12.3"
source .venv/bin/activate   # Activates virtual environment aiverify-moonshot

通过Google Cloud Vertex AI使用Claude Sonnet 4的配置指南

完整的安装说明

本指南提供了使用Claude Sonnet 4设置Moonshot MCP服务器以进行智能自然语言查询处理的分步说明。

先决条件

  1. 谷歌云项目 已启用计费
  2. Vertex AI API 在GCP项目中启用
  3. 应用程序默认凭据 (ADC)已配置
  4. 登月计划框架 已安装并配置

步骤1:LLM端点配置-例如,设置Claude 4 Sonnet

注意:此版本中尚未测试其他LLM终结点的配置。 服务器与通过Google Vertex AI配置的Claude 4 Sonnet配合使用效果最佳。在以下位置创建一个新文件以配置端点: ../revised-moonshot-data/connectors-endpoints/google-vertexai-claude-sonnet-4.json

{
    "name": "claude-sonnet-4-vertex",
    "connector_type": "google-vertexai-claude-connector",
    "uri": "DEFAULT",
    "token": "your-gcp-project-api-key",
    "max_calls_per_second": 2,
    "max_concurrency": 1,
    "model": "claude-sonnet-4@20250514",
    "params": {
        "timeout": 300,
        "max_attempts": 3,
        "temperature": 0.5,
        "max_tokens": 4096,
        "project_id": "your-gcp-project-id",
        "region": "us-east5"
    }
}

步骤2:环境设置

配置您的 moonshot-mcp-server/.env 具有以下设置的文件:

# Edit .env with your API keys - Currently works for Option 1: Use Claude via Google Cloud Vertex AI
cd ../moonshot-mcp-server
cp .env.example .env

# Query Processor Configuration - Claude Sonnet 4 via Vertex AI
QUERY_PROCESSOR_PROVIDER=vertex-ai
QUERY_PROCESSOR_MODEL=claude-sonnet-4@20250514
GCP_PROJECT_ID=your-gcp-project-id
GCP_REGION=us-east5
GCP_SERVICE_ACCOUNT_KEY_PATH=
# Leave empty to use Application Default Credentials

# Moonshot API Configuration  
MOONSHOT_API_URL=http://localhost:5000
MOONSHOT_DATA_PATH=../revised-moonshot-data

# Moonshot Data Directory Configuration
MOONSHOT_DATA_ROOT=<project-directory>/revised-moonshot-data    # Update to your project directory path

第三步:谷歌云身份验证

设置应用程序默认凭据:

# Install Google Cloud SDK if not already installed
gcloud auth application-default login

# Verify authentication
gcloud auth list                 # ensure correct GCP account
gcloud config get-value project  # ensure correct GCP Project ID 

第四步:连接克劳德十四行诗4

cd ./scripts
chmod +x setup-claude-endpoint.sh
sed -i 's/\r$//' setup-claude-endpoint.sh
bash setup-claude-endpoint.sh

步骤5:启动Moonshot API服务器

端子1 -使用所有必需的环境变量启动Moonshot web API:

cd ../../revised-moonshot
python -m moonshot web-api

等待消息: ✓ Moonshot API is running on http://localhost:5000

步骤6:构建和测试MCP服务器

2号航站楼 -构建并测试MCP服务器:

# activate the same virtual environment for running MCP server
cd <project-directory>/revised-moonshot
source .venv/bin/activate
cd ../moonshot-mcp-server

# Install dependencies (if not already done)
npm install

# Build the project
npm run build

# Test the server
node test-client.js

步骤7:可用工具

在测试客户端中尝试以下命令:

  1. 列出可用的食谱和LLM端点:

    list_cookbooks
    

    预期:18本以上可用烹饪书的列表,并将描述保存到markdown文件中 注意:这可能需要一些时间。

    list_endpoints
    

    预期:已注册的LLM端点列表,其描述已保存到markdown文件中

    clear_sessions
    

    预期:清除所有活动的登月任务并重置测试环境。对于不同测试运行之间的清理或遇到会话冲突时非常有用。

  2. 分析项目以进行基准测试和重新分组:

    这 analyze_project 该工具对您的LLM项目进行全面分析,以确定潜在的测试领域和安全问题。然后,这种自动化分析将指导有针对性的基准测试和红队工作。

    步骤2a:项目分析

    analyze_project
    

    输入项目路径和提示时要忽略的文件:

    Enter project path: /path/to/your/llm-project
    Enter files/patterns to ignore (comma-separated, or press Enter to skip): .env,logs
    

    预期产出包括:

    • 项目概述:检测到的框架、LLM集成和关键组件
    • 安全问题:已识别的潜在漏洞(快速注入、越狱等)
    • 测试建议:基于项目分析的建议食谱和指标
    • 风险评估:总体风险评分和测试优先领域
    • 端点兼容性:可用于测试的可用LLM端点

    步骤2b:基准测试(性能和能力测试)

    项目分析后,运行综合基准测试:

    benchmarking
    

    输入您配置的LLM端点和烹饪书,以便在系统提示时运行:

    Enter target endpoints (comma-separated): google-vertexai-claude-sonnet-4
    Enter specific cookbooks to run (comma-separated, or press Enter to use recommendations) (Recommended: <this will show based on your most recent project analysis outcome>): <Enter>
    

    或者根据您的项目类型从推荐的食谱中选择:

    • 通用: mmlu-all, hellaswag, gsm8k 用于广泛能力评估
    • 安全焦点: common-risk-easy, mlc-ai-safety 用于基本安全评估
    • 特定领域: medical-llm-leaderboard (医学), singapore-context (当地知识)
    • 偏见与公平: bbq-lite, cbbq-lite, winobias 用于偏差检测

    基准执行示例:

    Cookbook name: mlc-ai-safety
    Endpoints: google-vertexai-claude-sonnet-4
    Number of workers: 1
    

    步骤2c:安全红队(对抗测试)

    对于以安全为重点的测试,请使用自动化红队工具:

    security_red_team
    

    提供所需参数:

    Target endpoints: google-vertexai-claude-sonnet-4
    Enter specific attack modules (comma-separated, or presss Enter to use recommendations) (Recommended: <this will show based on your most recent project analysis outcome>): <Enter>
    

    或者根据您的项目类型从推荐的安全红队攻击模块中选择:

    • 将安全问题映射到攻击模块:
      • 快速注射→ payload_mask_attack, malicious_question_generator
      • 越狱企图→ malicious_question_generator, textfooler_attack
      • 输入验证→ homoglyph_attack, charswap_attack, insert_punctuation_attack
      • 对抗性输入→ textbugger_attack, textfooler_attack, homoglyph_v2_attack
      • 社会工程学→ job_role_generator, malicious_question_generator
    • 执行攻击模块:对LLM终结点运行选定的攻击
    • 提供安全评估:总体安全评分、漏洞评级和建议

    预期综合产出:

    • 基准结果:跨能力领域(推理、知识、安全)的绩效得分
    • 安全评估:漏洞评分、攻击成功率、关键发现
    • 风险的优先级:安全和性能问题排名表
    • 可采取行动的建议:提高模型稳健性的具体步骤
    • 合规洞察:符合人工智能安全标准和法规
  3. 自定义自然语言查询: 这 custom 命令允许您用自然语言描述您的测试需求。以下是有效查询的示例: 注意:您必须包含一个项目文件夹位置和一些测试标准,才能使其按预期工作。

示例1:

custom

然后输入:

Test my project at <folder location> for basic safety and toxicity issues. ignore all other files like .env, logs.

接下来是配置的模型端点:

google-vertexai-claude-sonnet-4

预期:人工智能分析建议进行适当的安全性和毒性测试

示例2:

custom
Enter your natural language query: test my project at <folder location> for singapore data

预期:针对新加坡特定测试的智能建议

示例3: 安全性和毒性测试:

custom
Enter your natural language query: Test my chatbot at <folder location> for harmful content and toxicity issues

预期的人工智能建议: challenging-toxicity-prompts, mlc-ai-safety, toxicity-classifier 指标

示例4: 偏见和公平性评估:

custom
Enter your natural language query: Check if my model at <folder location> shows gender or racial bias in responses

预期的人工智能建议: bbq-lite, cbbq-lite, winobias, genderbias_metric 指标

示例5: 医学领域测试:

custom
Enter your natural language query: Evaluate my medical AI at <folder location> for accuracy and hallucinations

预期的人工智能建议: medical-llm-leaderboard, medmcqa, faithfulness, answerrelevance 指标

示例6: 新加坡环境评估:

custom
Enter your natural language query: Test understanding of Singapore culture and local knowledge for project at <folder location>

预期的人工智能建议: singapore-context, singapore-pofma-statements, bertscore 指标

示例7: 安全和快速注射:

custom
Enter your natural language query: Check for jailbreak vulnerabilities and prompt injection attacks in <folder location>

预期的人工智能建议: cyberseceval-cookbook, jailbreak-dan, cybersecevalannotator 指标

示例8: 多语言能力:

custom
Enter your natural language query: Test my model's performance with Chinese language safety at <folder location>

预期的人工智能建议: chinese-safety-cookbook, cvalues, toxicity-classifier 指标

示例9: 综合风险评估:

custom
Enter your natural language query: Run a full safety audit covering bias, toxicity, and security for <folder location>

预期的人工智能建议: common-risk-hard, mlc-ai-safety多指标综合评价

示例10: 性能和精度测试:

custom
Enter your natural language query: Evaluate general knowledge and reasoning capabilities on <folder location>

预期的人工智能建议: mmlu-all, hellaswag, gsm8k, exactstrmatch, bertscore 指标

预期输出格式

使用自然语言查询时,系统会返回结构化建议:

✅ Successfully parsed your testing request!

🎯 **Query**: "test for singapore data"
🔍 **Focus Areas**: singapore, capability  
📋 **Test Types**: benchmark, comprehensive
🎪 **Confidence**: 95%

📚 **Recommended Cookbooks**:
  • singapore-context
  • singapore-pofma-statements
  
📊 **Recommended Metrics**:
  • bertscore
  • exactstrmatch
  
⚠️ **Specific Concerns**:
  • Local knowledge evaluation
  • Singapore context understanding

🤖 *Powered by Claude Sonnet 4 via Google Cloud Vertex AI*

文件结构

moonshot-mcp-server/
├── src/
│   ├── index.ts              # MCP server with improved test intent formatting
│   ├── moonshot-client.ts    # API client with 150s timeout for large responses  
│   ├── query-processor.ts    # Claude Sonnet 4 integration with robust JSON parsing
│   └── config-manager.ts     # Project configuration management
├── test-client.js            # Fixed terminal interface (no character doubling)
├── .env                      # Vertex AI configuration
└── README.md

故障排除

克劳德·十四行诗4期:

  • 确保GCP项目已启用计费
  • 确认Claude Sonnet 4在您所在的地区可用(尝试 us-east5)
  • 检查应用程序默认凭据是否配置正确

Moonshot API问题:

  • 验证所有环境变量是否设置正确
  • 检查API是否可访问 http://localhost:5000/health
  • 检查LLM端点是否可用 http://localhost:5000/api/v1/llm-endpoints
  • 查看Moonshot食谱,网址为 http://localhost:5000/api/v1/cookbooks
  • 确保大型烹饪书响应有足够的超时时间(150秒)

终端接口问题:

  • 使用单读线接口修复字符加倍问题
  • 键入“Custom”后立即显示自定义查询提示

支持

对于问题和疑问:

  • GitHub问题:[报告问题]
  • 文档:[AI验证登月文档]
  • 社区:[AI验证基金会]

贡献

欢迎投稿!请随时提交pull请求或打开bug和功能请求的问题。

许可证

MIT许可证-有关详细信息,请参阅许可证文件

致谢