Skip to content

Power 是 Kiro 的可插拔能力包,将工具、工作流和最佳实践封装成可按需激活的模块。每个 Power 至少包含一个 POWER.md 文件,可选附加 mcp.json 和 steering 目录。通过 frontmatter 中的关键词机制,Kiro 能在对话中自动识别并加载对应 Power。本文介绍从创建 POWER.md、配置 MCP Server、组织 steering 文件,到本地测试与 GitHub 发布的完整流程。

前置知识

Power 社区已有来自 Datadog、Figma、Neon、Netlify、Postman、Supabase、Stripe 等合作伙伴的精选 Power。你也可以构建并分享自己的 Power。

浏览精选 Power:github.com/kirodotdev/powers

必需文件

每个 Power 至少需要一个 POWER.md 文件。可选附加:

  • mcp.json — MCP Server 配置,用于工具集成
  • steering/ — 工作流专属指导文件目录

编写 POWER.md

POWER.md 由两部分组成:frontmatter(元数据)和给 Agent 的指令。建议将指令结构化为上手步骤(如安装 CLI、配置 hooks)和steering 指令(包含工作流与最佳实践)。复杂 Power 可拆分为多个 steering 文件。

Frontmatter:激活时机

frontmatter 告诉 Kiro 何时加载该 Power。关键词应贴近开发者的实际表达习惯。

yaml
---
name: "supabase"
displayName: "Supabase with local CLI"
description: "Build fullstack applications with Supabase's Postgres database, authentication, storage, and real-time subscriptions"
keywords: ["database", "postgres", "auth", "storage", "realtime", "backend", "supabase", "rls"]
author: "Supabase"
---

当用户说"帮我配置数据库",Kiro 匹配到 database 关键词后会自动激活 Supabase Power,将对应 MCP 工具和文档加载进上下文。

上手指令

上手部分在用户首次使用该 Power 时执行,用于验证依赖、说明配置步骤或创建工作区 hooks。

markdown
# Onboarding

## Step 1: 验证工具是否可用
使用 Supabase Local MCP 前,确保以下工具已安装并运行:
- **Docker Desktop**:Supabase CLI 依赖 Docker 运行本地开发栈
  - 验证命令:`docker --version`
  - **重要**:Docker 未安装或未运行时,禁止继续 Supabase 配置。
- **Supabase CLI**:通过 npm、Homebrew 等方式安装
  - 验证命令:`supabase --version`

## Step 2: 添加 hooks
`.kiro/hooks/review-advisors.kiro.hook` 写入以下内容

\`\`\`json
{
  "enabled": true,
  "name": "Review Database Performance & Security",
  "description": "Verify database follows performance/security best practices",
  "version": "1",
  "when": { "type": "userTriggered" },
  "then": {
    "type": "askAgent",
    "prompt": "Execute `get_advisors` via MCP to check for performance and security concerns"
  }
}
\`\`\`

Kiro 会自动执行这些指令:检查 Docker 是否运行、验证 CLI 安装,并在工作区创建性能审查 hook。

Steering 指令

steering 文件是可选的。简单 Power 可将所有指导直接写在 POWER.md 中;工作流复杂的工具建议拆分为独立 steering 文件。

简单写法(无独立 steering 文件)

markdown
# Best Practices

## 数据库 Schema 设计
- 主键使用 UUID
- 始终添加时间戳字段(created_at、updated_at)
- 为所有包含用户数据的表启用 RLS

## 示例:创建数据表
\`\`\`sql
create table profiles (
  id uuid primary key default gen_random_uuid(),
  username text unique not null,
  created_at timestamptz default now()
);
\`\`\`

进阶写法(多个 steering 文件)

markdown
# 何时加载 Steering 文件
- 配置数据库 → `database-setup-workflow.md`
- 编写或格式化 SQL → `supabase-code-format-sql.md`
- 创建或修改 RLS 策略 → `supabase-database-rls-policies.md`
- 创建 PostgreSQL 函数 → `supabase-database-functions.md`
- 使用声明式 schema(`supabase/schemas/` 目录)→ `supabase-declarative-database-schema.md`
- 配置 Next.js + Supabase SSR 认证 → `supabase-nextjs-supabase-auth.md`
- 实现实时功能(广播、presence、频道、订阅)→ `supabase-use-realtime.md`

处理 RLS 策略时,Kiro 加载 supabase-database-rls-policies.md;切换到认证时,改为加载 supabase-nextjs-supabase-auth.md,避免一次性注入所有上下文。

配置 MCP Server

如果 Power 使用 MCP 工具,创建 mcp.json 文件。POWER.md 中引用的 Server 名称必须与 mcp.jsonmcpServers 的 key 一致。

json
{
  "mcpServers": {
    "supabase-local": {
      "command": "npx",
      "args": ["-y", "@supabase/mcp-server-supabase"],
      "env": {
        "SUPABASE_URL": "${SUPABASE_URL}",
        "SUPABASE_ANON_KEY": "${SUPABASE_ANON_KEY}"
      }
    }
  }
}

API Key 和密钥使用环境变量。安装时 Kiro 会自动为 Server 名称加命名空间前缀以避免冲突(如 supabase-local 变为 power-supabase-supabase-local)。

目录结构

完整 Power 的参考结构:

power-supabase/
├── POWER.md                              # 元数据、上手指令、steering 映射
├── mcp.json                              # MCP Server 配置
└── steering/                             # 工作流专属指导
    ├── database-setup-workflow.md
    ├── supabase-code-format-sql.md
    ├── supabase-database-rls-policies.md
    └── supabase-edge-functions.md

本地测试

  1. 按上述结构创建 Power 目录
  2. 打开 Kiro → Powers 面板 → 从本地路径添加 Power
  3. 选择 Power 目录
  4. 在对话中使用 Power 的关键词,测试是否自动激活

发布到 GitHub

将 Power 推送到公开 GitHub 仓库:

bash
git init
git add POWER.md mcp.json steering/
git commit -m "Initial release"
git push origin main

仓库必须为公开状态,否则其他用户需要有访问权限才能安装。其他人通过"从 GitHub 添加 Power"输入仓库 URL 即可安装。

典型示例

场景结构
简单 Power(无 steering)POWER.md + 可选 mcp.json
单工具 + steeringPOWER.md + mcp.json + steering/schema-patterns.md
多工具全栈POWER.md + mcp.json + steering/(多文件)
纯文档 Power(无 MCP)POWER.md + steering/(组件模式等)

常见问题

Q:POWER.md 的 keywords 如何选择才能让 Kiro 准确激活?

A:关键词应贴近开发者在对话中的自然表达,而非技术文档术语。例如用 "database" 而非 "relational database management system"。建议覆盖该工具的核心操作词、官方名称和常见缩写,通常 5~10 个关键词足够。

Q:steering 文件和直接写在 POWER.md 里有什么区别?

A:功能上等价,区别在于上下文管理效率。所有内容放在 POWER.md 会在每次对话时全量注入;拆分为 steering 文件后,Kiro 只在触发对应工作流时加载相关文件,减少无关上下文占用。建议超过 3 个独立工作流时拆分。

Q:mcp.json 中的环境变量怎么设置?

A:使用 ${VAR_NAME} 语法引用,Kiro 在安装时会从用户的系统环境变量中读取对应值。不要在 mcp.json 中硬编码任何密钥,仓库公开后密钥会泄露。