mcpField
S
SumoLogic MCP Server

SumoLogic MCP Server

本地服务
github.com/greyaperez数据与分析055 周前更新

关于 SumoLogic MCP Server

SumoLogic MCP Server 将 SumoLogic 的日志分析与管理操作提供给 MCP 客户端,适用于需要查询和维护监控环境的团队。它可利用 sumologic-context.json 中的环境、资源和查询信息辅助自然语言交互。

主要功能

  1. 01自然语言执行搜索分析
  2. 02管理采集器与数据源
  3. 03查看和管理监控器
  4. 04创建及更新仪表板
  5. 05按环境配置上下文与查询快捷方式

适用场景

  1. 01查询生产服务的错误与性能
  2. 02比较不同环境的日志指标
  3. 03检查采集器和告警状态
  4. 04跨服务排查应用故障

MCP 相关

作为 MCP 服务,它向 MCP 客户端提供 SumoLogic 连接检查、采集器和数据源管理、搜索作业及监控器查询等工具。

配置

本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。

mcp.json · 通用配置
{
"mcpServers": {
"sumologic-greyaperez": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"\\"
]
}
}
}
启动命令docker run -i --rm '\'

本地服务需要在你的电脑上安装运行环境(如 Node.js 18+)。各客户端的配置文件位置不同,请参考客户端文档。

安装包
oci\

工具

还没有获取到工具列表

本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。

详细介绍

SumoLogic MCP Server

用自然语言改进 SumoLogic 交互体验 — 一个模型上下文协议(MCP)服务,让你只需用日常语言提问,就能轻松执行 SumoLogic 操作。

License: MIT Node.js MCP

🚀 特别之处

这不只是又一个 API 封装。借助 sumologic-context.json 提供的上下文感知能力,你可以使用自然语言与 SumoLogic 交互,而且它能理解你的特定环境、资源和常见查询。

前后对比

之前(传统 API):

# Complex API calls with exact syntax
curl -X POST "https://api.sumologic.com/api/v1/search/jobs" \
  -H "Authorization: Basic <encoded>" \
  -d '{"query":"_sourceCategory=webapp | count by _sourceHost", "from":"2024-01-01T00:00:00", "to":"2024-01-01T23:59:59"}'

之后(结合上下文的自然语言):

"Show me error counts from our production web servers yesterday"
"Which collectors are having ingestion issues?"
"Create a dashboard for our new microservice deployment"

🎯 主要功能

🧠 上下文智能

sumologic-context.json 配置将基础 API 访问转变为智能助手,让它了解:

  • 你的特定收集器及其用途
  • 常见查询及其业务含义
  • 资源关系和依赖项
  • 团队专用术语和工作流
🔧 全面的 SumoLogic 操作
  • 连接管理:验证连接和运行状况
  • 收集器和来源:创建、管理并监控数据采集
  • 搜索和分析:使用自然语言执行复杂查询
  • 监视器和告警:管理监控配置
  • 仪表板:创建和更新可视化内容
💬 自然语言界面

你可以这样提问:

  • “本周支付服务的错误率是多少?”
  • “显示过去一小时内的慢速数据库查询”
  • “为新的 Kubernetes 集群创建一个收集器”
  • “有没有我应该注意的严重告警?”

🌟 sumologic-context.json 的强大之处

什么是上下文感知?

sumologic-context.json 文件是你的秘密武器。它能让 MCP 服务了解你的特定 SumoLogic 环境,使交互变得非常直观。

实际上下文配置
{
  "version": "1.0",
  "organization": "acme-corp",
  "environments": {
    "production": {
      "applications": {
        "web-frontend": {
          "sourceCategory": "prod/web/frontend",
          "sourceName": "nginx-*",
          "description": "Production web frontend servers (Nginx)",
          "commonFilters": ["_sourceHost=web-prod-*"],
          "sampleQueries": [
            "_sourceCategory=\"prod/web/frontend\" | where status_code >= 400",
            "_sourceCategory=\"prod/web/frontend\" | timeslice 1m | count by status_code",
            "_sourceCategory=\"prod/web/frontend\" | json field=response_time | avg(response_time)"
          ]
        },
        "api-backend": {
          "sourceCategory": "prod/api/backend", 
          "sourceName": "api-server-*",
          "description": "Production API backend services",
          "commonFilters": ["_sourceHost=api-prod-*"],
          "sampleQueries": [
            "_sourceCategory=\"prod/api/backend\" error OR exception",
            "_sourceCategory=\"prod/api/backend\" | json field=response_time | avg(response_time) by endpoint",
            "_sourceCategory=\"prod/api/backend\" | where status_code = 500"
          ]
        },
        "mobile-app": {
          "sourceCategory": "prod/mobile/app",
          "sourceName": "mobile-api-*",
          "description": "Production mobile application backend",
          "commonFilters": ["_sourceHost=mobile-prod-*"],
          "sampleQueries": [
            "_sourceCategory=\"prod/mobile/app\" crash OR exception",
            "_sourceCategory=\"prod/mobile/app\" | json field=user_id | count by user_id"
          ]
        }
      },
      "infrastructure": {
        "database": {
          "sourceCategory": "prod/database/postgresql",
          "sourceName": "postgres-*",
          "description": "Production PostgreSQL database logs",
          "commonFilters": ["_sourceHost=db-prod-*"],
          "sampleQueries": [
            "_sourceCategory=\"prod/database/postgresql\" slow query",
            "_sourceCategory=\"prod/database/postgresql\" | where duration > 1000"
          ]
        },
        "kubernetes": {
          "sourceCategory": "prod/k8s/containers",
          "sourceName": "k8s-*",
          "description": "Production Kubernetes cluster logs",
          "commonFilters": ["_sourceHost=k8s-*"],
          "namespaces": ["default", "production", "monitoring", "ingress-nginx"]
        }
      }
    },
    "staging": {
      "applications": {
        "web-frontend": {
          "sourceCategory": "staging/web/frontend",
          "sourceName": "nginx-staging-*",
          "description": "Staging web frontend servers"
        },
        "api-backend": {
          "sourceCategory": "staging/api/backend", 
          "sourceName": "api-staging-*",
          "description": "Staging API backend services"
        }
      }
    }
  },
  "shortcuts": {
    "errors": {
      "description": "Find error messages and exceptions",
      "queryTemplate": "error OR exception OR fatal OR \"stack trace\" OR \"internal server error\"",
      "timeRange": "-15m"
    },
    "performance": {
      "description": "Performance monitoring with configurable threshold",
      "queryTemplate": "response_time OR duration OR latency | where ${metric} > ${threshold}",
      "defaultParams": {
        "metric": "response_time", 
        "threshold": "1000"
      },
      "timeRange": "-1h"
    },
    "security": {
      "description": "Security-related events and authentication failures",
      "queryTemplate": "authentication OR authorization OR \"access denied\" OR \"unauthorized\"",
      "timeRange": "-1h"
    },
    "database-slow": {
      "description": "Slow database queries",
      "queryTemplate": "\"slow query\" OR (duration > ${threshold}) OR \"query timeout\"",
      "defaultParams": {
        "threshold": "5000"
      },
      "timeRange": "-30m"
    }
  },
  "commonFields": {
    "timestamp_field": "@timestamp",
    "host_field": "_sourceHost",
    "service_field": "service_name",
    "environment_field": "environment",
    "log_level_field": "level"
  }
}
上下文应用示例

借助这套完善的上下文配置,看看这些交互会变得多么自然而强大:

示例 1:多环境错误分析

你提问: “比较生产环境和预发布环境 Web 前端的错误率”

AI 会智能地:

  1. 在 production 和 staging 环境中识别 web-frontend
  2. 使用上下文感知查询:
    • 生产环境:_sourceCategory="prod/web/frontend" | where status_code >= 400
    • 预发布环境:_sourceCategory="staging/web/frontend" | where status_code >= 400
  3. 应用适当的时间范围并提供对比分析
  4. 报告:“生产环境 Web 前端:错误率为 0.2%(正常);预发布环境:错误率为 1.1%(偏高,可能是近期部署测试导致的)”
示例 2:基础设施运行状况检查

你提问: “我们的 Kubernetes 集群运行情况如何?”

AI 会自动:

  1. 将“Kubernetes 集群”映射到 prod/k8s/containers 来源类别
  2. 检查已配置的命名空间:default、production、monitoring、ingress-nginx
  3. 应用针对基础设施的筛选条件:_sourceHost=k8s-*
  4. 使用容器运行状况和资源使用情况的示例查询
  5. 回复:“K8s 集群运行正常:4 个命名空间中共有 247 个 Pod 正在运行。生产命名空间未检测到资源限制。”
示例 3:智能快捷方式的使用

你询问: "显示过去一小时内的慢速数据库查询"

AI 借助快捷方式:

  1. 识别出“慢速数据库查询”对应 database-slow 快捷方式
  2. 应用模板:"slow query" OR (duration > 5000) OR "query timeout"
  3. 定位 PostgreSQL 日志:_sourceCategory="prod/database/postgresql"
  4. 使用默认阈值(5000ms)和自定义时间范围(-1h)
  5. 结果:"过去一小时内找到 12 条慢速查询。平均耗时:7.2s。最常见的查询:用户身份验证查询。"
示例 4:跨服务性能分析

你询问: "是什么导致了移动应用的性能问题?"

AI 执行全面分析:

  1. 识别 mobile-app 应用上下文
  2. 运行移动应用专用查询:_sourceCategory="prod/mobile/app" crash OR exception
  3. 交叉参照 api-backend 性能:avg(response_time) by endpoint
  4. 检查 database 日志中的相关慢速查询
  5. 综合分析结果:"移动应用的崩溃率上升了 15%。根本原因:由于数据库连接池耗尽,API 端点 /user/profile 的平均响应时间达到 3.2s。"
示例 5:安全事件响应

你询问: "检查过去一小时内是否存在任何安全问题"

AI 使用安全快捷方式:

  1. 在所有生产应用中应用 security 快捷方式模板
  2. 搜索:authentication OR authorization OR "access denied" OR "unauthorized"
  3. 同时扫描 web-frontend、api-backend 和 mobile-app
  4. 关联各服务中的发现
  5. 报告:"安全警报:在 API 后端检测到来自 IP 192.168.1.100 的 47 次未授权访问尝试。Web 前端显示了相应的 403 响应。"

📋 前置条件

  • Node.js 20+(推荐使用 LTS)
  • SumoLogic 账户,并具有 API 访问权限
  • API 凭据(Access ID 和 Key)
  • Docker(可选,用于容器化部署)

⚡ 快速开始

1. 安装
git clone https://github.com/greyaperez/mcp-sumologic.git
cd mcp-sumologic
npm install
2. 配置
# Copy environment template
cp .env.example .env

使用你的 SumoLogic 凭据编辑 .env:

SUMOLOGIC_ACCESS_ID=your_access_id
SUMOLOGIC_ACCESS_KEY=your_access_key
SUMOLOGIC_API_ENDPOINT=https://api.us2.sumologic.com/api
SUMOLOGIC_CONTEXT_CONFIG=./sumologic-context.json
SUMOLOGIC_DEFAULT_TIMEZONE=UTC
3. 创建上下文文件

根据你的环境详情创建 sumologic-context.json:

{
  "version": "1.0",
  "organization": "your-org",
  "environments": {
    "production": {
      "applications": {
        "web-frontend": {
          "sourceCategory": "prod/web/frontend",
          "sourceName": "nginx-*",
          "description": "Production web frontend servers",
          "commonFilters": ["_sourceHost=web-prod-*"],
          "sampleQueries": [
            "_sourceCategory=\"prod/web/frontend\" | where status_code >= 400"
          ]
        }
      },
      "infrastructure": {
        "database": {
          "sourceCategory": "prod/database/postgresql",
          "sourceName": "postgres-*", 
          "description": "Production PostgreSQL database logs",
          "commonFilters": ["_sourceHost=db-prod-*"]
        }
      }
    }
  },
  "shortcuts": {
    "errors": {
      "description": "Find error messages and exceptions",
      "queryTemplate": "error OR exception OR fatal",
      "timeRange": "-15m"
    }
  },
  "commonFields": {
    "timestamp_field": "@timestamp",
    "host_field": "_sourceHost",
    "service_field": "service_name"
  }
}
4. 运行服务
# Development mode
npm run dev

# Production mode
npm run build && npm start

🐳 Docker 部署

构建并运行
# Build image
docker build -t mcp/sumologic .

# Run with environment variables
docker run -i --rm \
  -e SUMOLOGIC_ACCESS_ID="your_access_id" \
  -e SUMOLOGIC_ACCESS_KEY="your_access_key" \
  -e SUMOLOGIC_API_ENDPOINT="https://api.us2.sumologic.com/api" \
  -e SUMOLOGIC_CONTEXT_CONFIG="./sumologic-context.json" \
  -e SUMOLOGIC_DEFAULT_TIMEZONE="UTC" \
  mcp/sumologic

🔧 Claude Desktop 集成

添加到 Claude Desktop 配置中:

选项 1:直接使用 Node.js
{
  "mcpServers": {
    "sumologic": {
      "command": "node",
      "args": ["/path/to/mcp-sumologic/dist/index.js"],
      "env": {
        "SUMOLOGIC_ACCESS_ID": "your_access_id",
        "SUMOLOGIC_ACCESS_KEY": "your_access_key",
        "SUMOLOGIC_API_ENDPOINT": "https://api.us2.sumologic.com/api",
        "SUMOLOGIC_CONTEXT_CONFIG": "./sumologic-context.json",
        "SUMOLOGIC_DEFAULT_TIMEZONE": "UTC"
      }
    }
  }
}
选项 2:Docker
{
  "mcpServers": {
    "sumologic": {
      "command": "docker",
      "args": [
        "run", "-i", "--rm",
        "-e", "SUMOLOGIC_ACCESS_ID",
        "-e", "SUMOLOGIC_ACCESS_KEY",
        "-e", "SUMOLOGIC_API_ENDPOINT",
        "-e", "SUMOLOGIC_CONTEXT_CONFIG",
        "-e", "SUMOLOGIC_DEFAULT_TIMEZONE",
        "mcp/sumologic"
      ],
      "env": {
        "SUMOLOGIC_ACCESS_ID": "your_access_id",
        "SUMOLOGIC_ACCESS_KEY": "your_access_key",
        "SUMOLOGIC_API_ENDPOINT": "https://api.us2.sumologic.com/api",
        "SUMOLOGIC_CONTEXT_CONFIG": "./sumologic-context.json",
        "SUMOLOGIC_DEFAULT_TIMEZONE": "UTC"
      }
    }
  }
}

🛠️ 可用工具

工具描述感知上下文
check_connection验证 API 连接✅
list_collectors列出所有采集器及其业务上下文✅
get_collector获取采集器详情及关系信息✅
create_hosted_collector使用智能默认值创建采集器✅
update_collector更新采集器属性✅
delete_collector删除采集器并分析影响✅
list_sources列出来源及其用途说明✅
get_source获取来源详情及上下文✅
create_http_source使用模板创建 HTTP 来源✅
start_search_job使用查询建议执行搜索✅
check_search_job_status检查搜索状态✅
get_search_job_results获取结果并提供业务解读✅
list_monitors列出监视器及其业务影响✅
get_monitor获取监视器详情及上下文✅

💡 上下文配置最佳实践

1. 按环境和服务类型组织
{
  "environments": {
    "production": {
      "applications": {
        "web-frontend": {
          "sourceCategory": "prod/web/frontend",
          "description": "Production web frontend servers (Nginx)",
          "commonFilters": ["_sourceHost=web-prod-*"]
        }
      },
      "infrastructure": {
        "database": {
          "sourceCategory": "prod/database/postgresql", 
          "description": "Production PostgreSQL database logs"
        }
      }
    }
  }
}
2. 包含真实的 SumoLogic 查询
{
  "sampleQueries": [
    "_sourceCategory=\"prod/web/frontend\" | where status_code >= 400",
    "_sourceCategory=\"prod/api/backend\" | json field=response_time | avg(response_time) by endpoint"
  ]
}
3. 创建可复用的查询快捷方式
{
  "shortcuts": {
    "performance": {
      "description": "Performance monitoring with configurable threshold",
      "queryTemplate": "response_time OR duration OR latency | where ${metric} > ${threshold}",
      "defaultParams": {
        "metric": "response_time", 
        "threshold": "1000"
      },
      "timeRange": "-1h"
    }
  }
}
4. 规范字段映射
{
  "commonFields": {
    "timestamp_field": "@timestamp",
    "host_field": "_sourceHost", 
    "service_field": "service_name",
    "environment_field": "environment",
    "log_level_field": "level"
  }
}
5. 使用一致的命名模式
  • 来源类别:{env}/{service-type}/{service-name}
  • 来源名称:{service}-{env}-*(例如,nginx-prod-*)
  • 主机筛选条件:_sourceHost={service}-{env}-*

🔍 使用示例

感知环境的查询
"Show me errors in production web frontend"
"Compare API performance between staging and production"  
"Check database health in all environments"
借助快捷方式进行分析
"Run security check for the last hour"
"Find slow database queries with default threshold"
"Show performance issues with response time over 2000ms"
基础设施智能
"How is our Kubernetes cluster doing?"
"Check Redis cache hit rates in production"
"Show load balancer health across all environments"
跨服务关联
"Is the mobile app backend causing the database slowdown?"
"Compare error rates between web frontend and API backend"
"Show the full request flow from load balancer to database"
主动管理
"Create a monitor for API response times over 1 second"
"Set up alerting for Kubernetes pod crashes"
"Monitor database connection pool exhaustion"

🤝 贡献

  1. Fork 此仓库
  2. 创建功能分支(git checkout -b feature/amazing-feature)
  3. 提交更改(git commit -m 'Add amazing feature')
  4. 推送到分支(git push origin feature/amazing-feature)
  5. 发起 Pull Request

📄 许可证

本项目采用 MIT 许可证,详情请参阅 LICENSE 文件。


准备好提升你的 SumoLogic 使用体验了吗? 从一个简单的上下文文件开始,见证复杂操作如何变得像提问一样简单!🚀

评论

支持 Markdown

第一次接触 MCP?

从协议是什么,到在客户端里装上第一个服务,这几条回答覆盖了大多数入门问题。

一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。