内容
# sumologic-mcp
本地MCP服务器,允许AI助手通过HTTP运行Sumo Logic日志搜索。
## 前提条件
- Node.js 18+
- 具有搜索作业API访问权限的Sumo Logic **企业**账户
- Sumo Logic API访问密钥和ID([在此处创建](https://help.sumologic.com/docs/manage/security/access-keys/))
## 安装配置
1. 安装依赖项:
```bash
npm install
```
2. 复制示例.env文件并填写您的凭证:
```bash
cp .env.example .env
```
3. 在`.env`中设置您的部署端点。示例:
| 部署环境 | 端点地址 |
| ---------- | -------------------------------------- |
| US1 | `https://api.sumologic.com/api/v1` |
| US2 | `https://api.us2.sumologic.com/api/v1` |
| EU | `https://api.eu.sumologic.com/api/v1` |
4. 编译:
```bash
npm run build
```
### 选项A:Cursor 自动启动服务器(推荐)
Cursor 可以为您启动MCP进程,无需手动运行 `npm start`。
将以下内容添加到您的Cursor MCP配置(`~/.cursor/mcp.json`):
```json
{
"mcpServers": {
"sumologic": {
"command": "node",
"args": ["/绝对路径/to/sumologic-mcp/dist/index.js", "--stdio"],
"env": {
"ENDPOINT": "https://api.sumologic.com/api/v1",
"SUMO_API_ID": "您的访问ID",
"SUMO_API_KEY": "您的访问密钥"
}
}
}
}
```
将 `/绝对路径/to/sumologic-mcp` 替换为此仓库的实际路径。凭证也可以存储在项目的 `.env` 文件中(从项目根目录自动加载)。
对于开发环境,无需编译,可使用 `npx tsx`:
```json
{
"mcpServers": {
"sumologic": {
"command": "npx",
"args": ["tsx", "/绝对路径/to/sumologic-mcp/src/index.ts", "--stdio"]
}
}
}
```
在更改配置后,请重启或重新加载Cursor中的MCP服务器。
### 选项B:HTTP服务器(用于远程托管)
手动启动服务器:
```bash
npm start
```
在开发环境中使用自动重新加载:
```bash
npm run dev
```
服务器默认监听 `http://localhost:3006`。
将以下内容添加到您的Cursor MCP配置:
```json
{
"mcpServers": {
"sumologic": {
"url": "http://localhost:3006/mcp"
}
}
}
```
在启动本地服务器后,请重启Cursor中的MCP服务器。
## 可用工具
### `search_sumologic`
运行Sumo Logic搜索并返回结果。
| 参数名 | 类型 | 默认值 | 描述 |
| ------------ | ------ | ---------- | -------------------------------- |
| `query` | 字符串 | 必需 | Sumo Logic搜索查询 |
| `from` | 字符串 | 24小时前 | ISO 8601起始时间 |
| `to` | 字符串 | 现在 | ISO 8601结束时间 |
| `limit` | 数字 | 100 | 最大结果数(1-10000) |
| `offset` | 数字 | 0 | 分页偏移量 |
| `resultType` | 字符串 | `messages` | `messages`, `records`, 或 `both` |
**示例查询:**
- 原始日志:`* | where severity = "error" | limit 20`
- 按服务计数:`* | count by _sourceCategory`
- 时间范围:使用 `from` 和 `to` 参数,配合ISO 8601时间戳
使用 `resultType: "messages"` 获取原始日志行,使用 `records` 获取聚合/表格结果,使用 `both` 时不确定。
## 环境变量
| 变量名 | 是否必需 | 默认值 | 描述 |
| ------------------- | -------- | -------- | ------------------------------------------- |
| `ENDPOINT` | 是 | — | Sumo Logic API基准URL |
| `SUMO_API_ID` | 是 | — | 访问ID |
| `SUMO_API_KEY` | 是 | — | 访问密钥 |
| `PORT` | 否 | `3006` | HTTP服务器端口 |
| `TIMEZONE` | 否 | `UTC` | 搜索作业时区 |
| `SEARCH_TIMEOUT_MS` | 否 | `300000` | 搜索完成的最大等待时间(5分钟) |
## 健康检查
```bash
curl http://localhost:3006/health
```
## 注意事项
- 搜索结果中的PII字段( `_raw`, `response` )在返回给AI之前会自动编辑。
- 搜索作业API需要跨请求会话cookie;此服务器自动处理。
- 如果您收到403错误,您的账户可能没有企业搜索作业API访问权限。