内容
# Brex MCP Server
一个用于 Brex API 的模型上下文协议(MCP)服务器。针对安全、小型、只读响应进行了优化,具有投影和批处理功能。
## 安装
### Claude Code
```bash
# 安装包
npm install -g mcp-brex
# 使用您的 API 密钥添加到 Claude Code
claude mcp add brex --env BREX_API_KEY=your_brex_api_key -- npx mcp-brex
```
### Claude Desktop
添加到你的 `claude_desktop_config.json`:
```json
{
"mcpServers": {
"brex": {
"command": "npx",
"args": ["mcp-brex"],
"env": {
"BREX_API_KEY": "your_brex_api_key"
}
}
}
}
```
### 手动设置 (开发)
```bash
git clone https://github.com/dennisonbertram/mcp-brex.git
cd mcp-brex
npm install
npm run build
claude mcp add brex --env BREX_API_KEY=your_key -- node build/index.js
```
## 资源
- `brex://expenses` | `brex://expenses/{id}` | `brex://expenses/card` | `brex://expenses/card/{id}`
- `brex://budgets` | `brex://budgets/{id}`
- `brex://spend_limits` | `brex://spend_limits/{id}`
- `brex://budget_programs` | `brex://budget_programs/{id}`
- `brex://transactions/card/primary` | `brex://transactions/cash/{id}`
- `brex://docs/usage` (代理的简明使用指南)
注意:
- 资源接受 `?summary_only=true&fields=id,status,...` 来控制有效负载大小。
- Expenses 资源自动展开 `merchant` 和 `budget` 以提高可读性。
## 工具 (只读,除非另有说明)
- Budgets: `get_budgets`, `get_budget`
- Spend Limits: `get_spend_limits`, `get_spend_limit`
- Budget Programs: `get_budget_programs`, `get_budget_program`
- Expenses (单页): `get_expenses`
- Expenses (分页): `get_all_expenses`, `get_all_card_expenses`
- Expense by ID: `get_expense`, `get_card_expense`
- Card Statements: `get_card_statements_primary`
- Transactions: `get_card_transactions`, `get_cash_transactions`
- Cash Statements: `get_cash_account_statements`
- Accounts: `get_all_accounts`, `get_account_details`
- Receipts (写入): `match_receipt`, `upload_receipt`
- Updates (写入): `update_expense`
## 如何调用工具
始终在 `arguments` (而不是 `input`) 下发送参数。通过分页和过滤保持有效负载小。
常用参数:
- 分页: `page_size` (<=50), `max_items` (建议 <=200)
- 日期过滤: `start_date`, `end_date`, `window_days`
- 状态过滤: expenses/transactions 的 `status` 数组
- 金额过滤: expenses 的 `min_amount`, `max_amount`
- 展开控制: `expand` 数组以包含嵌套对象 (例如, `["merchant", "budget"]`)
推荐示例:
```json
{
"name": "get_all_card_expenses",
"arguments": {
"page_size": 10,
"max_items": 20,
"start_date": "2025-08-25T00:00:00Z",
"end_date": "2025-08-26T00:00:00Z",
"status": ["APPROVED"],
"min_amount": 100
}
}
```
```json
{
"name": "get_expenses",
"arguments": {
"limit": 5,
"status": "APPROVED"
}
}
```
```json
{
"name": "get_card_transactions",
"arguments": {
"limit": 10,
"posted_at_start": "2025-08-25T00:00:00Z"
}
}
```
```json
{
"name": "get_all_accounts",
"arguments": {
"page_size": 10,
"max_items": 20,
"status": "ACTIVE"
}
}
```
```json
{
"name": "get_transactions",
"arguments": {
"accountId": "acc_123456789",
"limit": 10
}
}
```
```json
{
"name": "get_expenses",
"arguments": {
"limit": 5,
"expand": ["merchant", "user"]
}
}
```
## 分页和过滤最佳实践
**重要**: 使用分页、过滤和排序来控制响应大小,而不是依赖摘要。
### 用于数据控制的关键参数:
- **`page_size: number`** — 每页的项目数 (建议: ≤50)
- **`max_items: number`** — 所有页面中的最大总项目数 (建议: ≤200)
- **`start_date/end_date: string`** — ISO 日期范围过滤
- **`window_days: number`** — 将大的日期范围拆分为较小的批次
- **`status: string[]`** — 按状态过滤 (例如, ["APPROVED", "PENDING"])
- **`min_amount/max_amount: number`** — 基于金额的 expenses 过滤
### 最佳实践:
- **始终对批量请求使用日期范围**,以避免巨大的响应
- **使用小的页面大小** (≤50) 和合理的 max_items (≤200)
- **应用状态过滤器**以仅获取所需的数据
- **使用 window_days** (例如, 7) 批量处理大的日期范围
- **使用 `expand` 参数控制嵌套对象的展开**:
- **默认**: `expand: []` 返回精简对象 (每个约 500-1000 个 tokens)
- **展开后**: `expand: ["merchant", "budget"]` 返回完整对象 (每个约 15K+ 个 tokens)
- **可用的展开选项**: `merchant`, `budget`, `user`, `department`, `location`, `receipts`
- **先用小限制进行测试**,然后再扩大规模
- Cash 端点需要额外的 Brex 范围;优雅地处理 403 错误
## 发布
仅发布 `build/`、`README.md` 和 `LICENSE`。
## 许可证
MIT — 参见 `LICENSE`。