使用说明
Bruno MCP服务器
一个模型上下文协议(MCP)服务器,集成了Bruno CLI用于API测试和收集管理。执行API测试,验证集合,并通过模型上下文协议生成报告。
特性
- 🚀 运行API测试 -执行单个请求或整个集合
- 🔍 请求反思 -在不执行的情况下检查请求详细信息
- ✅ 验证 -验证集合和环境
- 📊 报告生成 -JSON、JUnitXML和HTML报告
- 🌍 环境管理 -列出、验证和切换环境
- 🔎 收藏发现 -递归搜索Bruno收藏
- 🧪 干运行模式 -在不进行HTTP调用的情况下进行验证
- 🔒 安全 -路径验证、输入净化、秘密屏蔽
- ⚡ 演出 -请求缓存和执行指标
- 🏥 健康监测 -具有详细诊断的服务器健康检查
快速开始
先决条件
- Node.js 20或更高版本
- 布鲁诺系列(
.bru文件)
📝 什么是Bruno MCP服务器?
这 Bruno MCP服务器 整合 Bruno CLI (开源API客户端),具有模型上下文协议(MCP),以启用 API直接测试、收集管理和报告 通过克劳德。
Bruno将其收藏存储为人类可读 .bru 文件系统中的文件,允许与版本控制(Git)无缝集成。
🚀 关键能力
- API执行 -快跑 个人请求 或 完整的测试集合
- 验证 -执行 模式和环境验证 (包括a) 干运行模式 不进行HTTP调用)
- 发现 -递归 查找Bruno系列 跨指定目录
- 环境管理 - 列出并验证 集合内的特定环境(例如。,
dev,staging,production) - 报告 -生成综合报告 JSON、JUnitXML或HTML 格式
💡 示例提示
| 目标 | 示例提示 |
|---|---|
| 发现 | “在我的项目目录中查找所有Bruno收藏,网址为 /Users/user-name/projects" |
| 请求执行 | “从以下位置运行“获取用户”请求 /path/to/collection 使用“dev”环境 |
| 验证(试运行) | “验证来自的“创建用户”请求 /path/to/collection 不进行HTTP调用” |
| 完整运行和报告 | “在上运行API集合中的所有测试 /path/to/collection 并在中生成HTML和JSON报告 ./reports" |
| 环境检查 | “列出中的所有环境 /path/to/collection 并验证“生产”环境” |
📥 安装(Claude CLI)
选项1:使用Claude MCP Add(推荐)
最简单的方法是使用 claude mcp add 命令,它自动安装服务器并配置MCP传输。
| 范围 | 命令 |
|---|---|
| 全球 (个人使用) | claude mcp add --transport stdio bruno -- npx -y bruno-mcp-server |
| 项目范围 (团队项目) | claude mcp add --transport stdio bruno --scope project -- npx -y bruno-mcp-server |
注: 这
--transport stdio旗和--分离器是 必需的The-yflag自动接受npx提示。
选项2:手动安装
- 全局安装软件包:
npm install -g bruno-mcp-server
- 添加到您的Claude CLI配置文件中:
- 全局配置:
~/.claude.json - 项目配置:
.claude.json(在项目根目录中)
- 全局配置:
{
"mcpServers": {
"bruno": {
"command": "npx",
"args": ["bruno-mcp-server"]
}
}
}
- 重新启动Claude CLI会话
✅ 验证
要确认服务器安装正确,请检查相应的配置文件:
# For global installation
cat ~/.claude.json
# For project-scoped installation
cat .claude.json
你应该看看 "bruno" 以下列出的服务器 mcpServers.
测试安装 通过启动新的Claude CLI会话并尝试:
"Check if the bruno MCP server is available and list its tools"
可用工具
1. bruno_run_request -执行单个请求
bruno_run_request({
collectionPath: "/path/to/collection",
requestName: "Get User",
environment: "dev", // optional
envVariables: { // optional
"API_KEY": "your-key"
},
reporterJson: "./report.json", // optional
reporterJunit: "./report.xml", // optional
reporterHtml: "./report.html", // optional
dryRun: false // optional - validate only
})
2. bruno_run_collection -执行集合
bruno_run_collection({
collectionPath: "/path/to/collection",
environment: "dev", // optional
folderPath: "auth", // optional - run specific folder
envVariables: { }, // optional
reporterJson: "./report.json", // optional
dryRun: false // optional
})
3. bruno_list_requests -列出所有请求
bruno_list_requests({
collectionPath: "/path/to/collection"
})
4. bruno_discover_collections -查找收藏
bruno_discover_collections({
searchPath: "/path/to/workspace",
maxDepth: 5 // optional (default: 5, max: 10)
})
5. bruno_list_environments -列出环境
bruno_list_environments({
collectionPath: "/path/to/collection"
})
6. bruno_validate_environment -验证环境
bruno_validate_environment({
collectionPath: "/path/to/collection",
environmentName: "dev"
})
7. bruno_get_request_details -检查请求
bruno_get_request_details({
collectionPath: "/path/to/collection",
requestName: "Create User"
})
8. bruno_validate_collection -验证集合
bruno_validate_collection({
collectionPath: "/path/to/collection"
})
9. bruno_health_check -健康诊断
bruno_health_check({
includeMetrics: true, // optional
includeCacheStats: true // optional
})
干运行模式
在不执行HTTP调用的情况下验证请求配置:
bruno_run_request({
collectionPath: "/path/to/collection",
requestName: "Create User",
dryRun: true
})
输出:
=== DRY RUN: Request Validation ===
✅ Request validated successfully (HTTP call not executed)
Request: Create User
Method: POST
URL: {{baseUrl}}/api/users
Configuration Summary:
Headers: 2
Body: json
Auth: bearer
Tests: 3
ℹ️ This was a dry run - no HTTP request was sent.
报告生成
生成多种格式的测试报告:
bruno_run_collection({
collectionPath: "./my-api-tests",
environment: "production",
reporterJson: "./reports/results.json",
reporterJunit: "./reports/results.xml",
reporterHtml: "./reports/results.html"
})
- JSON:程序化处理的详细结果
- JUnit XML:CI/CD集成(Jenkins、GitHub Actions、GitLab CI)
- 超文本标记语言:使用Vue.js界面的交互式报告
配置
创建 bruno-mcp.config.json 在项目根目录或主目录中:
{
"timeout": {
"request": 30000,
"collection": 120000
},
"retry": {
"enabled": true,
"maxAttempts": 3,
"backoff": "exponential"
},
"security": {
"allowedPaths": ["/path/to/collections"],
"maskSecrets": true,
"secretPatterns": ["password", "api[_-]?key", "token"]
},
"logging": {
"level": "info",
"format": "json"
},
"performance": {
"cacheEnabled": true,
"cacheTTL": 300000
}
}
看 bruno-mcp.config.example.json 对于所有选项。
发展
# Clone repository
git clone https://github.com/jcr82/bruno-mcp-server.git
cd bruno-mcp-server
# Install dependencies
npm install
# Run tests
npm test
# Build
npm run build
# Run in development
npm run dev
项目结构
bruno-mcp-server/
├── src/
│ ├── index.ts # Main MCP server
│ ├── bruno-cli.ts # Bruno CLI wrapper
│ ├── config.ts # Configuration management
│ ├── security.ts # Security utilities
│ ├── performance.ts # Caching and metrics
│ ├── logger.ts # Logging system
│ ├── di/ # Dependency injection
│ ├── services/ # Business logic services
│ ├── tools/
│ │ ├── handlers/ # MCP tool handlers (9 tools)
│ │ └── formatters/ # Output formatters
│ └── __tests__/ # Test suites
│ ├── unit/ # Unit tests (100% handler coverage)
│ ├── integration/ # Integration tests
│ └── e2e/ # End-to-end workflow tests
├── dist/ # Compiled output
└── bruno-mcp.config.json # Configuration file
测试覆盖率
- 总体覆盖范围: 91.04%
- 处理程序覆盖范围:99.72%(9/9名处理人员)
- 格式化程序覆盖范围: 98.74%
- 总测试:362次通过
- 测试类型:单元、集成、E2E
安全特性
- 路径验证:防止目录遍历攻击
- 输入消毒:防止命令注入
- 秘密面具:自动屏蔽日志中的敏感数据
- 环境验证:验证变量的安全字符
故障排除
安装问题
错误:“缺少必需的参数'commandOrUrl'”
- 确保你包括
--transport stdio和--分隔符 - 对的:
claude mcp add --transport stdio bruno -- npx -y bruno-mcp-server - 错误:
claude mcp add bruno-mcp-server
MCP服务器未在Claude中显示
- 验证安装:
cat ~/.claude.json(或项目.claude.json如果使用--scope project) - 安装后重新启动Claude Desktop/CLI
- 检查JSON文件中的服务器配置是否正确
安装过程中npx提示
- 始终使用
-y标志:npx -y bruno-mcp-server - 此自动接受安装提示
未找到Bruno CLI
# Verify Bruno CLI installation
npx bru --version
# Server uses local installation in node_modules/.bin/bru
未找到集合
- 使用绝对路径
- 验证
bruno.json存在于收藏目录中 - 检查文件权限
权限问题
- 确保Bruno收藏的读取权限
- 验证服务器是否可以执行Bruno CLI
文档
贡献
欢迎投稿!请提交问题或拉取请求。
许可证
麻省理工学院©Juan Ruiz
