Skip to main content
Glama

Test Runner MCP

by privsim

测试运行器 MCP

模型上下文协议 (MCP) 服务器,用于运行和解析来自多个测试框架的测试结果。该服务器提供统一的接口来执行测试并处理其输出,支持:

  • Bats(Bash 自动测试系统)
  • Pytest(Python测试框架)
  • Flutter 测试
  • Jest(JavaScript 测试框架)
  • Go 测试
  • 防锈测试(货物测试)
  • 通用(用于任意命令执行)

安装

npm install test-runner-mcp

先决条件

需要针对各自的测试类型安装以下测试框架:

用法

配置

将测试运行器添加到您的 MCP 设置中(例如,在claude_desktop_config.jsoncline_mcp_settings.json中):

{ "mcpServers": { "test-runner": { "command": "node", "args": ["/path/to/test-runner-mcp/build/index.js"], "env": { "NODE_PATH": "/path/to/test-runner-mcp/node_modules", // Flutter-specific environment (required for Flutter tests) "FLUTTER_ROOT": "/opt/homebrew/Caskroom/flutter/3.27.2/flutter", "PUB_CACHE": "/Users/username/.pub-cache", "PATH": "/opt/homebrew/Caskroom/flutter/3.27.2/flutter/bin:/usr/local/bin:/usr/bin:/bin" } } } }

注意:对于 Flutter 测试,请确保替换:

  • /opt/homebrew/Caskroom/flutter/3.27.2/flutter替换为你的实际 Flutter 安装路径
  • /Users/username/.pub-cache替换为你的实际 pub 缓存路径
  • 更新 PATH 以包含系统的实际路径

您可以通过运行以下命令找到这些值:

# Get Flutter root flutter --version # Get pub cache path echo $PUB_CACHE # or default to $HOME/.pub-cache # Get Flutter binary path which flutter

运行测试

使用具有以下参数的run_tests工具:

{ "command": "test command to execute", "workingDir": "working directory for test execution", "framework": "bats|pytest|flutter|jest|go|rust|generic", "outputDir": "directory for test results", "timeout": "test execution timeout in milliseconds (default: 300000)", "env": "optional environment variables", "securityOptions": "optional security options for command execution" }

每个框架的示例:

// Bats { "command": "bats test/*.bats", "workingDir": "/path/to/project", "framework": "bats", "outputDir": "test_reports" } // Pytest { "command": "pytest test_file.py -v", "workingDir": "/path/to/project", "framework": "pytest", "outputDir": "test_reports" } // Flutter { "command": "flutter test test/widget_test.dart", "workingDir": "/path/to/project", "framework": "flutter", "outputDir": "test_reports", "FLUTTER_ROOT": "/opt/homebrew/Caskroom/flutter/3.27.2/flutter", "PUB_CACHE": "/Users/username/.pub-cache", "PATH": "/opt/homebrew/Caskroom/flutter/3.27.2/flutter/bin:/usr/local/bin:/usr/bin:/bin" } // Jest { "command": "jest test/*.test.js", "workingDir": "/path/to/project", "framework": "jest", "outputDir": "test_reports" } // Go { "command": "go test ./...", "workingDir": "/path/to/project", "framework": "go", "outputDir": "test_reports" } // Rust { "command": "cargo test", "workingDir": "/path/to/project", "framework": "rust", "outputDir": "test_reports" } // Generic (for arbitrary commands, CI/CD tools, etc.) { "command": "act -j build", "workingDir": "/path/to/project", "framework": "generic", "outputDir": "test_reports" } // Generic with security overrides { "command": "sudo docker-compose -f docker-compose.test.yml up", "workingDir": "/path/to/project", "framework": "generic", "outputDir": "test_reports", "securityOptions": { "allowSudo": true } }

安全功能

测试运行器包含内置的安全功能,以防止执行潜在的有害命令,特别是对于generic框架:

  1. 命令验证
    • 默认阻止sudosu
    • 防止危险命令,如rm -rf /
    • 阻止在安全位置之外进行文件系统写入操作
  2. 环境变量清理
    • 过滤掉潜在的危险环境变量
    • 防止覆盖关键系统变量
    • 确保安全路径处理
  3. 可配置的安全性
    • 必要时通过securityOptions覆盖安全限制
    • 对安全功能的细粒度控制
    • 标准测试使用的默认安全设置

您可以配置的安全选项:

{ "securityOptions": { "allowSudo": false, // Allow sudo commands "allowSu": false, // Allow su commands "allowShellExpansion": true, // Allow shell expansion like $() or backticks "allowPipeToFile": false // Allow pipe to file operations (> or >>) } }

Flutter 测试支持

测试运行器包括对 Flutter 测试的增强支持:

  1. 环境设置
    • 自动 Flutter 环境配置
    • PATH 和 PUB_CACHE 设置
    • Flutter 安装验证
  2. 错误处理
    • 堆栈跟踪收集
    • 断言错误处理
    • 异常捕获
    • 测试失败检测
  3. 输出处理
    • 完成测试输出捕获
    • 堆栈跟踪保存
    • 详细的错误报告
    • 原始输出保存

Rust 测试支持

测试运行器为 Rust 的cargo test提供了特定的支持:

  1. 环境设置
    • 自动设置 RUST_BACKTRACE=1 以获得更好的错误消息
  2. 输出解析
    • 解析单个测试结果
    • 捕获失败测试的详细错误消息
    • 识别被忽略的测试
    • 提取摘要信息

通用测试支持

对于 CI/CD 管道、通过act执行的 GitHub Actions 或任何其他命令执行,通用框架提供:

  1. 自动输出分析
    • 尝试将输出分割成逻辑块
    • 标识节标题
    • 检测通过/失败指标
    • 即使对于未知格式也能提供合理的输出结构
  2. 灵活集成
    • 可与任意 shell 命令配合使用
    • 无特定格式要求
    • 非常适合与act 、Docker 和自定义脚本等工具集成
  3. 安全功能
    • 命令验证以防止有害操作
    • 必要时可配置为允许特定的提升权限

输出格式

测试运行器生成结构化输出,同时保留完整的测试输出:

interface TestResult { name: string; passed: boolean; output: string[]; rawOutput?: string; // Complete unprocessed output } interface TestSummary { total: number; passed: number; failed: number; duration?: number; } interface ParsedResults { framework: string; tests: TestResult[]; summary: TestSummary; rawOutput: string; // Complete command output }

结果保存在指定的输出目录中:

  • test_output.log :原始测试输出
  • test_errors.log :错误消息(如果有)
  • test_results.json :结构化测试结果
  • summary.txt :人类可读的摘要

发展

设置

  1. 克隆存储库
  2. 安装依赖项:
    npm install
  3. 构建项目:
    npm run build

运行测试

npm test

该测试套件包括所有受支持框架的测试,并验证成功和失败的测试场景。

持续集成/持续交付

该项目使用 GitHub Actions 进行持续集成:

  • 在 Node.js 18.x 和 20.x 上进行自动化测试
  • 测试结果已上传为工件
  • Dependabot 配置为自动依赖项更新

贡献

  1. 分叉存储库
  2. 创建你的功能分支
  3. 提交你的更改
  4. 推送到分支
  5. 创建拉取请求

执照

该项目根据 MIT 许可证获得许可 - 有关详细信息,请参阅LICENSE文件。

Install Server
A
security – no known vulnerabilities
A
license - permissive license
A
quality - confirmed to work

hybrid server

The server is able to function both locally and remotely, depending on the configuration or use case.

通过模型上下文协议接口,方便Bats、Pytest、Flutter、Jest、Go等各种测试框架统一执行和结果解析。

  1. 安装
    1. 先决条件
      1. 用法
        1. 配置
        2. 运行测试
        3. 安全功能
        4. Flutter 测试支持
        5. Rust 测试支持
        6. 通用测试支持
      2. 输出格式
        1. 发展
          1. 设置
          2. 运行测试
          3. 持续集成/持续交付
        2. 贡献
          1. 执照

            Related MCP Servers

            • -
              security
              F
              license
              -
              quality
              A Model Context Protocol server that integrates with the Qase test management platform, allowing users to create and retrieve test cases, manage test runs, and interact with Qase projects.
              Last updated -
              1
              JavaScript
            • -
              security
              A
              license
              -
              quality
              A Model Context Protocol (MCP) server implementation that allows AI assistants to run k6 load tests through natural language commands, supporting custom test durations and virtual users.
              Last updated -
              1
              Python
              MIT License
            • A
              security
              F
              license
              A
              quality
              A Model Context Protocol server that allows AI assistants to execute and manage JMeter performance tests through natural language commands.
              Last updated -
              2
              27
              Python
            • A
              security
              A
              license
              A
              quality
              A Model Context Protocol server that integrates essential penetration testing tools (Nmap, Gobuster, Nikto, John the Ripper) into a unified natural language interface, allowing security professionals to execute and chain multiple tools through conversational commands.
              Last updated -
              8
              36
              42
              JavaScript
              MIT License
              • Linux
              • Apple

            View all related MCP servers

            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/privsim/mcp-test-runner'

            If you have feedback or need assistance with the MCP directory API, please join our Discord server