Skip to content

Createitv/wematrix-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

微矩阵 WeMatrix CLI

English | 中文

微矩阵 WeMatrix CLI 是面向 AI Agent 的微信公众号矩阵管理命令行工具。它连接你的微矩阵 WeMatrix 服务,让 Codex、Claude、Cursor、CI 脚本或自定义 Agent 可以通过终端安全地读取公众号矩阵上下文、创建微信公众号草稿、读取账号样式、查询流量主收益,并生成远程 HTTP MCP 配置。

Website / 官网: https://mp.lingxiaoyao.cn/

NPM package: https://www.npmjs.com/package/wematrix-cli

GitHub repository: https://github.com/Createitv/wematrix-cli

中文

产品定位

微矩阵 WeMatrix 是一个面向公众号矩阵运营、AI Agent 内容自动化和微信公众号开放 API 集成的管理平台。wematrix-cli 是微矩阵的独立命令行客户端,适合给 AI Agent、自动化脚本和内部运营工具使用。

核心关键词:

  • 微矩阵
  • WeMatrix
  • 微信公众号矩阵管理
  • 公众号矩阵管理平台
  • 微信公众号草稿 API
  • 微信公众号 MCP
  • 面向 Agent 的公众号管理平台
  • AI Agent 公众号自动化
  • 公众号流量主收益统计

它能做什么

wematrix 命令可以完成:

  • 读取 Agent Context:让 Agent 先理解当前 Token 权限、账号矩阵、能力边界和发布策略。
  • 读取公众号账号列表:获取已授权微信公众号矩阵账号。
  • 读取账号样式:让 AI 生成内容前理解目标账号默认排版风格。
  • 创建微信公众号草稿:把 Markdown 内容创建为微信草稿,不直接群发。
  • 查询流量主收益:读取多公众号累计收益和结算区间汇总。
  • 输出 MCP 配置:生成远程 HTTP MCP 配置片段,方便接入支持 MCP 的 AI 客户端。

安全边界

这个 CLI 是给 AI Agent 用的,但不会让 Agent 直接发布文章。

  • 只创建草稿,不直接群发。
  • 成功结果输出 JSON 到 stdout。
  • 错误输出 JSON 到 stderr。
  • Token 会自动脱敏。
  • 本地保存 Token 时使用 AES-256-GCM 加密。
  • 每个命令都对应明确的 API Token scope。

安装

npm install -g wematrix-cli

验证:

wematrix --version

也可以临时运行:

npm exec --package=wematrix-cli -- wematrix --version

快速开始

推荐给 Agent 使用环境变量,不把 Token 写进命令历史:

export WEMATRIX_BASE_URL="https://mp.lingxiaoyao.cn"
export WEMATRIX_TOKEN="mp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

wematrix context
wematrix accounts
wematrix styles --appid wx123
wematrix draft create post.md --title "每日简报" --appid wx123
wematrix publisher summary --appids wx123,wx456

推荐的 Agent 工作流

# 1. 读取微矩阵 WeMatrix 平台上下文和 Token 权限
wematrix context

# 2. 选择目标公众号
wematrix accounts

# 3. 读取目标公众号默认样式
wematrix styles --appid wx123

# 4. 生成 Markdown 后创建微信草稿
wematrix draft create post.md --title "每日简报" --appid wx123

Agent 创建草稿后应该停止,后续由运营者在微矩阵 WeMatrix 或微信公众平台中审核发布。

命令列表

帮助

wematrix --help
wematrix help draft
wematrix help publisher
wematrix help mcp

登录与本地配置

一次性调用建议使用 WEMATRIX_TOKEN。如果需要保存本地配置:

export WEMATRIX_CONFIG_PASSPHRASE="local-secret-from-your-secret-manager"

wematrix login \
  --base-url https://mp.lingxiaoyao.cn \
  --token "$WEMATRIX_TOKEN"

配置文件位置:

~/.wematrix/config.json

退出并删除本地配置:

wematrix logout

Agent Context

wematrix context

需要 scope:

agent:context

用途:让 AI Agent 读取微矩阵 WeMatrix 当前能力、账号矩阵、Token scope、接口限制和发布策略。

公众号账号列表

wematrix accounts

需要 scope:

accounts:read

用途:读取已授权微信公众号矩阵账号,选择后续草稿创建的 appid

账号样式

wematrix styles
wematrix styles --appid wx123

需要 scope:

styles:read

用途:让 AI Agent 在生成内容前理解目标公众号默认排版样式。

创建微信公众号草稿

wematrix draft create post.md \
  --title "每日简报" \
  --appid wx123 \
  --author "运营团队" \
  --summary "今日重点内容"

从 stdin 读取 Markdown:

cat post.md | wematrix draft create --stdin --title "每日简报" --appid wx123

需要 scope:

drafts:create

注意:该命令只创建微信草稿,不直接发布,不群发,不绕过人工审核。

流量主收益

wematrix publisher summary
wematrix publisher summary --appids wx123,wx456

wematrix publisher settlement \
  --start 2026-05-01 \
  --end 2026-05-19 \
  --group-by appid

需要 scope:

publisher:read

用途:让运营脚本或 AI Agent 读取公众号流量主累计收益、结算区间汇总,用于日报、周报和矩阵账号分析。

MCP 配置

wematrix mcp config --base-url https://mp.lingxiaoyao.cn

输出示例:

{
  "mcpServers": {
    "wematrix": {
      "type": "http",
      "url": "https://mp.lingxiaoyao.cn/api/mcp",
      "headers": {
        "Authorization": "Bearer ${WEMATRIX_TOKEN}"
      }
    }
  }
}

不要把真实 Token 写进共享的 MCP 配置文件。建议使用环境变量或 AI 工具的 Secret 管理能力。

环境变量

变量 说明
WEMATRIX_BASE_URL 微矩阵 WeMatrix 服务地址,例如 https://mp.lingxiaoyao.cn
WEMATRIX_TOKEN 微矩阵 API Token
WEMATRIX_CONFIG_PASSPHRASE 本地加密配置的口令

权限 Scope

命令 Scope
context, whoami agent:context
accounts accounts:read
styles styles:read
draft create drafts:create
publisher summary publisher:read
publisher settlement publisher:read

错误输出格式

错误统一输出到 stderr:

{
  "success": false,
  "code": "TOKEN_MISSING",
  "message": "Missing token. Set WEMATRIX_TOKEN, pass --token, or run login with WEMATRIX_CONFIG_PASSPHRASE."
}

给 AI Agent 的安全建议

  • 先运行 wematrix context,让 Agent 理解平台边界。
  • 给不同 Agent 创建不同的最小权限 Token。
  • 不要把生产 Token 写进 prompt、仓库或共享文档。
  • 用短期 Token 做实验。
  • 创建草稿后必须人工审核再发布。

English

Overview

微矩阵 WeMatrix CLI is an agent-native command line client for the WeMatrix WeChat public-account matrix management platform. It is designed for Codex, Claude, Cursor, CI jobs, internal scripts, and custom AI agents that need a deterministic way to work with WeChat official account operations.

The CLI talks to your own WeMatrix deployment at:

https://mp.lingxiaoyao.cn/

It does not ship the private WeMatrix web application. It only ships the public CLI client for API and MCP access.

Features

  • Read Agent Context before taking action.
  • List authorized WeChat public accounts.
  • Read default account style configuration.
  • Create WeChat drafts from Markdown.
  • Read publisher revenue summaries and settlement data.
  • Generate remote HTTP MCP config for AI clients.
  • Emit JSON stdout and structured JSON stderr.
  • Redact mp_* tokens in output.

Install

npm install -g wematrix-cli

Check:

wematrix --version

Temporary run:

npm exec --package=wematrix-cli -- wematrix --help

Agent Quick Start

export WEMATRIX_BASE_URL="https://mp.lingxiaoyao.cn"
export WEMATRIX_TOKEN="mp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

wematrix context
wematrix accounts
wematrix styles --appid wx123
wematrix draft create post.md --title "Daily Brief" --appid wx123

Recommended sequence for AI agents:

  1. Run wematrix context.
  2. Run wematrix accounts.
  3. Run wematrix styles --appid <appid>.
  4. Generate Markdown.
  5. Run wematrix draft create.
  6. Stop and let a human review the draft before publishing.

Commands

wematrix --help
wematrix context
wematrix accounts
wematrix styles --appid wx123
wematrix draft create post.md --title "Daily Brief" --appid wx123
wematrix publisher summary --appids wx123,wx456
wematrix publisher settlement --start 2026-05-01 --end 2026-05-19
wematrix mcp config --base-url https://mp.lingxiaoyao.cn

Output Contract

Successful commands:

  • stdout only
  • JSON object
  • token redaction applied

Failed commands:

  • stderr only
  • JSON object
  • non-zero exit code
  • token redaction applied

Security Model

This CLI is intentionally conservative:

  • It creates WeChat drafts only.
  • It does not publish or mass-send articles.
  • It maps commands to explicit API Token scopes.
  • It supports encrypted local config using AES-256-GCM.
  • It is safe to use in agent workflows when paired with least-privilege tokens.

MCP

wematrix mcp config --base-url https://mp.lingxiaoyao.cn

The output can be used by AI clients that support remote HTTP MCP:

{
  "mcpServers": {
    "wematrix": {
      "type": "http",
      "url": "https://mp.lingxiaoyao.cn/api/mcp",
      "headers": {
        "Authorization": "Bearer ${WEMATRIX_TOKEN}"
      }
    }
  }
}

Development

pnpm install
pnpm run build
pnpm run test
node dist/index.js --help
npm pack --dry-run

License

MIT

About

微矩阵 WeMatrix CLI for AI Agent powered WeChat public-account matrix management

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors