npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@lxp521125/alilog-mcp

v1.0.0

Published

Aliyun SLS (Log Service) MCP Server - query logs via MCP protocol

Readme

aliyun-mcp

Aliyun MCP Server — 提供阿里云日志服务 (SLS) 的 MCP 工具,支持从 Consul 或环境变量加载凭证。

快速开始

npm install
npm run build

凭证配置

通过 CRED_SOURCE 环境变量选择凭证加载方式:

Consul 模式(默认)

从 Consul KV 获取 AK/SK,适合共享开发环境。

CRED_SOURCE=consul
CONSUL_URL=https://your-consul-url
CONSUL_TOKEN=                          # 无 token 留空即可
# 可选:覆盖默认 KV 路径
CONSUL_PATH_ENDPOINT=your/path/ALI_SLS_ENDPOINT
CONSUL_PATH_AK_ID=your/path/ALI_SLS_ACCESS_KEY_ID
CONSUL_PATH_AK_SECRET=your/path/ALI_SLS_ACCESS_KEY_SECRET
CONSUL_PATH_PROJECT=your/path/ALI_SLS_PROJECT
CONSUL_PATH_LOGSTORE=your/path/ALI_SLS_LOGSTORE

Env 模式

直接从环境变量读取,适合 CI/CD 或本地覆盖。

CRED_SOURCE=env
ALI_SLS_ENDPOINT=cn-hangzhou.log.aliyuncs.com
ALI_SLS_ACCESS_KEY_ID=xxx
ALI_SLS_ACCESS_KEY_SECRET=xxx
ALI_SLS_PROJECT=my-project
ALI_SLS_LOGSTORE=my-logstore           # 可选,默认 logstore

Static 模式

与 env 相同,但凭证仅在启动时加载一次。

CRED_SOURCE=static
ALI_SLS_ENDPOINT=cn-hangzhou.log.aliyuncs.com
ALI_SLS_ACCESS_KEY_ID=xxx
ALI_SLS_ACCESS_KEY_SECRET=xxx
ALI_SLS_PROJECT=my-project
ALI_SLS_LOGSTORE=my-logstore

MCP 配置

在 Claude Desktop / Kiro / settings.json 中添加:

{
  "mcpServers": {
    "aliyun": {
      "command": "node",
      "args": ["path/to/aliyun-mcp/dist/index.js"],
      "env": {
        "CRED_SOURCE": "consul",
        "CONSUL_URL": "https://your-consul-url"
      }
    }
  }
}

工具列表

| 工具 | 说明 | 使用场景 | |------|------|----------| | sls_query_logs | 查询日志,支持 SLS 查询语法和 SQL | 搜索错误、关键字、traceId | | sls_tail_logs | 获取最近 N 条日志 | 快速查看当前状态 | | sls_list_projects | 列出 SLS 项目(支持模糊搜索) | 定位服务所属项目 | | sls_list_logstores | 列出项目下的 logstore(支持模糊搜索) | 定位服务的日志存储 | | sls_get_credentials | 显示当前凭证配置(密钥脱敏) | 验证配置是否正确 |

查询优化

  • 默认使用 fast=true — 走 GetLogs 接口,关键字/字段查询速度快很多
  • 仅在需要 SQL 聚合时用 fast=false — 如 * | select count(*) group by level
  • 缩小时间范围fromMinutesAgo 越小扫描量越少,查询越快
  • 使用精确字段过滤level:ERRORtraceId:xxx* 快得多
  • 分页获取 — 单次最多 100 条,用 offset 翻页

项目结构

src/
├── index.ts          # MCP server 入口,注册所有工具
├── sls-client.ts     # SLS HTTP API 签名与请求(无原生依赖)
└── credentials.ts    # 凭证加载(Consul / env / static)

技术说明

  • 不依赖阿里云官方 SDK(避免 lz4 等原生编译依赖)
  • 使用 Node.js 内置 crypto 模块实现 SLS HMAC-SHA1 签名
  • 签名规范:Authorization: LOG <AK>:<Base64(HMAC-SHA1(StringToSign, SK))>
  • CanonicalizedResource 包含排序后的 query params