有关构建、组织和提交 Cursor 插件的参考文档。插件将规则、技能、agents、命令、MCP 服务器和钩子打包成可在 Cursor IDE 中使用的可分发套件。
如果从头开始,请使用插件模板代码仓库。
支持的插件格式¶
Cursor 支持加载两种插件格式,按清单文件的位置区分:
| 格式 | 清单位置 | 组件 |
|---|---|---|
| Agent Plugins (开放标准) | 插件根目录中的 plugin.json |
技能、MCP 服务器 |
| Cursor 插件 | .cursor-plugin/plugin.json |
技能、MCP 服务器、规则、agents、命令、钩子、变量 |
符合 Agent Plugins specification 的插件无需修改即可在 Cursor 中加载。本参考文档的其余部分介绍 Cursor 插件格式。该格式与该标准并行开发,支持完整的 Cursor 组件集。
插件结构¶
插件是一个包含清单文件及插件资源的目录:
Agent Plugin¶
my-plugin/
├── plugin.json # 必需:Agent Plugins 清单
├── skills/ # 智能体技能
│ └── code-reviewer/
│ └── SKILL.md
└── mcp.json # MCP 服务器定义
Agent Plugins 标准定义了可移植的技能和 MCP 服务器。完整的软件包和 schema 参考,请参阅
Agent Plugins 编写指南。
Cursor 插件¶
my-plugin/
├── .cursor-plugin/
│ └── plugin.json # 必需:Cursor 插件清单
├── rules/ # Cursor 规则(.mdc 文件)
│ ├── coding-standards.mdc
│ └── review-checklist.mdc
├── skills/ # 智能体技能
│ └── code-reviewer/
│ └── SKILL.md
├── agents/ # 自定义智能体配置
│ └── security-reviewer.md
├── commands/ # 可由智能体执行的命令
│ └── deploy.md
├── hooks/ # 钩子定义
│ └── hooks.json
├── mcp.json # MCP 服务器定义
├── assets/ # 徽标和静态资源
│ └── logo.svg
├── scripts/ # 钩子和实用脚本
│ └── format-code.py
└── README.md
Cursor 插件清单¶
每个 Cursor 插件都需要一个 .cursor-plugin/plugin.json 清单文件。以下
章节介绍 Cursor 插件的字段、组件和插件市场功能。有关根 Agent Plugins 清单,请参阅
标准清单参考。
必填字段¶
| 字段 | 类型 | 描述 |
|---|---|---|
name |
string | 插件标识符。仅限小写 kebab-case (字母数字、连字符和句点) 。必须以字母或数字开头和结尾。示例:my-plugin、prompts.chat |
可选字段¶
| 字段 | 类型 | 描述 |
|---|---|---|
description |
string | 插件的简要描述 |
version |
string | 语义化版本 (例如 1.0.0) |
author |
object | 作者信息:name (必填) 、email (可选) |
homepage |
string | 插件主页 URL |
repository |
string | 插件代码仓库 URL |
license |
string | 许可证标识符 (例如 MIT) |
keywords |
array | 用于发现和分类的标签 |
logo |
string | 仓库中 logo 文件的相对路径 (例如 assets/logo.svg) ,或绝对 URL。相对路径会解析为 raw.githubusercontent.com URL。建议将 logo 提交到仓库中,并使用相对路径。 |
rules |
string or array | 规则文件或目录的路径 |
agents |
string or array | agents 文件或目录的路径 |
skills |
string or array | 技能目录的路径 |
commands |
string or array | 命令文件或目录的路径 |
hooks |
string or object | 钩子配置文件的路径,或内联钩子配置 |
mcpServers |
string, object, or array | MCP 配置文件的路径、内联 MCP 服务器配置,或两者组成的数组。会覆盖默认的 mcp.json 发现机制。 |
variables |
object | 声明变量名称 (token、连接字符串) 的 JSON Schema。插件不存储机密值;用户可在仪表盘中设置这些值 (插件 → 配置) 。这些值会替换 ${VAR} 占位符。参阅变量。 |
清单示例¶
{
"name": "enterprise-plugin",
"version": "1.2.0",
"description": "Enterprise development tools with security scanning and compliance checks",
"author": {
"name": "ACME DevTools",
"email": "devtools@acme.com"
},
"keywords": ["enterprise", "security", "compliance"],
"logo": "assets/logo.svg"
}
变量¶
使用 variables 声明用户提供的配置项的名称 (以及类型/描述) ,例如 HTTP MCP 服务器的 API 令牌。插件仅定义 schema,不包含机密信息的实际值。
团队管理员可在仪表盘的 插件 中设置实际值 (安装时设置,或之后通过插件的 配置 设置) 。
请勿将机密信息的实际值放入插件仓库。在 mcp.json 和其他插件配置中,仅包含与 schema 中属性名称相匹配的 ${VAR} 占位符。
```json title=”.cursor-plugin/plugin.json”
{
“name”: “example-plugin”,
“variables”: {
“type”: “object”,
“properties”: {
“API_TOKEN”: {
“type”: “string”,
“title”: “API token”,
“description”: “Bearer token for the example HTTP MCP”
}
},
“required”: [“API_TOKEN”]
}
}
```json title="mcp.json"
{
"mcpServers": {
"example-api": {
"url": "https://mcp.example.com/mcp",
"headers": {
"Authorization": "Bearer ${API_TOKEN}"
}
}
}
}
顶层必须为 { "type": "object", "properties": { ... } }。仅支持一组固定的 JSON Schema 关键字 (type、title、description、default、enum、const、properties、required、items 以及常见的长度和数值约束) 。
Cursor 插件组件发现¶
当清单未为某类组件指定显式路径时,解析器会使用自动基于文件夹发现:
| 组件 | 默认位置 | 发现方式 |
|---|---|---|
| 技能 | skills/ |
每个包含 SKILL.md 文件的子目录 |
| 规则 | rules/ |
所有 .md、.mdc 或 .markdown 文件 |
| 代理 | agents/ |
所有 .md、.mdc 或 .markdown 文件 |
| 命令 | commands/ |
所有 .md、.mdc、.markdown 或 .txt 文件 |
| 钩子 | hooks/hooks.json |
解析以获取钩子事件名称 |
| MCP 服务器 | mcp.json |
解析以获取服务器条目 |
| 根技能 | 插件根目录中的 SKILL.md |
视为单技能插件 (仅当不存在 skills/ 目录且清单中没有 skills 字段时) |
如果指定了清单字段** (例如 "skills": "./my-skills/") ,则会替代该组件的文件夹发现方式,不再扫描默认文件夹。
规则格式¶
规则是为 AI 提供持久指引的 .mdc 文件。请将其放在 rules/ 目录中。
规则需要包含带有元数据的 YAML frontmatter:
```markdown title=”rules/prefer-const.mdc”
description: Prefer const over let for variables that are never reassigned
alwaysApply: true
prefer-const: Always use const for variables that are never reassigned.
Only use let when the variable needs to be reassigned. Never use var.
### 规则 frontmatter 字段
| 字段 | 类型 | 描述 |
| :------------ | :------------- | :---------------------------------------- |
| `description` | string | 规则功能的简要描述 |
| `alwaysApply` | boolean | 如为 `true`,规则将应用于所有文件;如为 `false`,可按需调用该规则。 |
| `globs` | string 或 array | 规则适用的文件模式 (例如 `"**/*.ts"`) |
完整文档请参阅 [Rules](https://cursor.com/docs/rules)。
## 技能格式
技能是在 `SKILL.md` 文件中定义的专门能力。每个技能在 `skills/` 下都有自己的目录。
技能需要包含带元数据的 YAML frontmatter:
```markdown title="skills/api-designer/SKILL.md"
---
name: api-designer
description: Design RESTful APIs following OpenAPI 3.0 specification.
Use when designing new API endpoints, reviewing API contracts,
or generating API documentation.
---
# API 设计器技能
## 何时使用
- 设计新的 API 端点
- 评审 API 合约
- 生成 API 文档
## 说明
1. 资源命名遵循 REST 约定
2. 使用恰当的 HTTP 方法(GET、POST、PUT、DELETE、PATCH)
3. 使用标准 HTTP 状态码返回合适的错误响应
4. 使用 OpenAPI 3.0 规范为所有端点编写文档
5. 使用一致的命名约定(URL 用 kebab-case,JSON 用 camelCase)
技能 frontmatter 字段¶
| 字段 | 类型 | 描述 |
|---|---|---|
name |
string | 技能标识符 (小写,kebab-case) |
description |
string | 技能的功能及适用场景 |
完整文档请参阅技能。
Agents 格式¶
Agents 是用于定义自定义智能体行为和提示词的 Markdown 文件。请将其放在 agents/ 目录中。
Agents 需要包含元数据的 YAML frontmatter:
```markdown title=”agents/security-reviewer.md”
name: security-reviewer
description: Security-focused code reviewer that checks for
vulnerabilities and proven approaches
安全审阅器¶
你是一位专注于安全的代码审阅人。审阅代码时:
- 检查注入类漏洞(SQL、XSS、命令注入)
- 验证身份验证与授权是否正确
- 排查敏感数据泄露(API 密钥、密码、个人身份信息)
- 确保加密实践安全可靠
- 评审依赖项安全性及已知漏洞
- 检查输入校验与清洗是否到位
### 智能体 frontmatter 字段
| 字段 | 类型 | 描述 |
| :------------ | :----- | :----------------------- |
| `name` | string | 智能体标识符 (小写字母,kebab-case) |
| `description` | string | 智能体用途的简要说明 |
## 命令格式
命令是定义智能体可执行操作的 Markdown 或文本文件。请将其放在 `commands/` 目录中。
命令支持 `.md`、`.mdc`、`.markdown` 和 `.txt` 扩展名,也可包含 YAML frontmatter:
```markdown title="commands/deploy-staging.md"
---
name: deploy-staging
description: Deploy the current branch to the staging environment
---
# Deploy to staging
Steps to deploy to staging:
1. Run tests
2. Build the project
3. Push to staging branch
Command frontmatter 字段¶
| 字段 | 类型 | 描述 |
|---|---|---|
name |
string | Command 标识符 (小写、kebab-case) |
description |
string | Command 功能简介 |
钩子格式¶
钩子是由智能体、Tab 或工作区事件触发的自动化脚本。请在 hooks/hooks.json 中定义:
```json title=”hooks/hooks.json”
{
“hooks”: {
“afterFileEdit”: [
{
“command”: “./scripts/format-code.sh”
}
],
“beforeShellExecution”: [
{
“command”: “./scripts/validate-shell.sh”,
“matcher”: “rm|curl|wget”
}
],
“sessionEnd”: [
{
“command”: “./scripts/audit.sh”
}
]
}
}
### 可用钩子事件
- **智能体钩子**:`sessionStart`、`sessionEnd`、`preToolUse`、`postToolUse`、`postToolUseFailure`、`subagentStart`、`subagentStop`、`beforeShellExecution`、`afterShellExecution`、`beforeMCPExecution`、`afterMCPExecution`、`beforeReadFile`、`afterFileEdit`、`beforeSubmitPrompt`、`preCompact`、`stop`、`afterAgentResponse`、`afterAgentThought`
- **Tab 钩子**:`beforeTabFileRead`、`afterTabFileEdit`
- **应用生命周期钩子**:`workspaceOpen`
完整文档请参阅 [Hooks](https://cursor.com/docs/hooks)。
## MCP 服务器
两种格式都将 `mcp.json` 放在插件根目录。Agent Plugins 使用该标准的
schema,并声明每个服务器的传输协议。Cursor 插件可以使用
Cursor 变量,并根据 `command` 或 `url` 推断传输协议。
### Agent Plugin
```json title="mcp.json"
{
"$schema": "https://agent-plugins.org/schemas/1.0.0/mcp.schema.json",
"mcpServers": {
"code-review": {
"type": "stdio",
"command": "./bin/code-review",
"cwd": "${PLUGIN_ROOT}"
}
}
}
有关支持的传输协议、路径和数据目录,请参阅 Agent Plugins MCP 参考。
Cursor 插件¶
Cursor 插件会自动发现 mcp.json。仅在使用自定义路径或内联配置时,才需在
.cursor-plugin/plugin.json 中指定 mcpServers。
```json title=”mcp.json”
{
“mcpServers”: {
“postgres”: {
“command”: “npx”,
“args”: [“-y”, “@modelcontextprotocol/server-postgres”],
“env”: {
“POSTGRES_CONNECTION_STRING”: “${POSTGRES_URL}”
}
}
}
}
`${POSTGRES_URL}` 是[插件变量](https://cursor.com/cn/docs/reference/plugins.md#variables)占位符 (不是 shell `${env:...}`) 。请在 `plugin.json` 的 `variables` 下声明变量名;插件配置中仅保留占位符,并在仪表盘的 **插件** → **配置** 中设置其值。由插件管理的 MCP 配置在仪表盘中为只读。
完整文档请参阅 [MCP](https://cursor.com/docs/mcp)。
## 徽标
将徽标文件提交到代码仓库,并通过相对路径引用:
```json
{
"name": "my-plugin",
"logo": "assets/logo.svg"
}
相对路径会根据代码仓库和提交 SHA 解析为 raw.githubusercontent.com URL。例如,acme/plugins 仓库中提交 abc123 的 assets/logo.svg 会解析为:
https://raw.githubusercontent.com/acme/plugins/abc123/my-plugin/assets/logo.svg
也支持绝对 GitHub 用户内容 URL (以 http:// 或 https:// 开头) 。
Cursor 多插件代码仓库¶
一个 Git 代码仓库可通过 插件市场清单 包含多个插件。请将其置于代码仓库根目录的 .cursor-plugin/marketplace.json。
插件市场 清单格式¶
{
"name": "my-marketplace",
"owner": {
"name": "Your Org",
"email": "plugins@yourorg.com"
},
"metadata": {
"description": "A collection of developer tool plugins"
},
"plugins": [
{
"name": "plugin-one",
"source": "plugin-one",
"description": "First plugin"
},
{
"name": "plugin-two",
"source": "plugin-two",
"description": "Second plugin"
}
]
}
插件市场 清单字段¶
| 字段 | 类型 | 描述 |
|---|---|---|
name |
string | ** (必填) **插件市场 标识符 (kebab-case) |
owner |
object | (必填) name (必填) 、email (可选) |
plugins |
array | ** (必填) **插件条目数组 (最多 500 项) |
metadata |
object | 可选。description、version、pluginRoot (所有插件源的路径前缀) |
插件条目字段¶
plugins 数组中的每个条目支持以下字段:
| 字段 | 类型 | 描述 |
|---|---|---|
name |
string | ** (必填) **插件标识符 (kebab-case) |
source |
string 或 object | 插件目录的路径,或包含 path 和选项的对象 |
description |
string | 插件描述 |
version |
string | 语义化版本 |
author |
object | 作者信息 |
homepage |
string | URL |
repository |
string | URL |
license |
string | 许可证标识符 |
keywords |
array | 搜索标签 |
logo |
string | logo 的相对路径或 URL |
category |
string | 插件类别 |
tags |
array | 附加标签 |
skills, rules, agents, commands |
string 或 array | 组件文件路径 |
hooks |
string 或 object | 钩子配置的路径或内联配置 |
mcpServers |
string 或 object | MCP 配置的路径或内联配置 |
variables |
object | 用于声明变量名称的 JSON Schema (值在仪表盘的 插件 → 配置 中设置) 。建议使用 plugin.json;如果两者都已设置,以清单中的值为准。请参阅变量。 |
解析规则¶
对于 "source": "my-plugin" 的 插件市场 条目:
- 解析器会查找
my-plugin/.cursor-plugin/plugin.json - 如果找到,会将该 plugin 的清单与 插件市场 条目合并 (清单中的值优先)
- 会在
my-plugin/目录中发现组件:如清单中指定了路径则使用该路径,否则采用基于文件夹的发现机制
多插件仓库示例¶
my-plugins/
├── .cursor-plugin/
│ └── marketplace.json # 列出所有插件
├── eslint-rules/
│ ├── .cursor-plugin/
│ │ └── plugin.json # 单个插件的清单
│ └── rules/
│ ├── prefer-const.mdc
│ └── no-any.mdc
├── docker/
│ ├── .cursor-plugin/
│ │ └── plugin.json
│ ├── skills/
│ │ ├── containerize-app/
│ │ │ └── SKILL.md
│ │ └── setup-docker-compose/
│ │ └── SKILL.md
│ └── mcp.json
└── README.md
提交插件¶
插件需经 Cursor 团队审核。提交方式如下:
创建插件¶
为 Agent Plugin 在根目录添加有效的 plugin.json,或为 Cursor 插件添加
.cursor-plugin/plugin.json。
托管在 Git 代码仓库中¶
将插件推送到公开的 Git 代码仓库。将 logo 提交到仓库 (可选,但建议提供) 。
提交插件¶
前往 cursor.com/marketplace/publish,提交代码仓库链接。
提交检查清单¶
- 插件根目录下存在有效的
plugin.json或.cursor-plugin/plugin.json清单 name唯一,且采用小写短横线命名法 (例如my-awesome-plugin)description清晰说明插件用途- 所有包含的组件都有有效的文件和 frontmatter
- 如提供 Logo,须将其提交到仓库,并通过相对路径引用
README.md说明用法及所有配置- Agent Plugins 符合 Agent Plugins schemas
- 使用变量的 Cursor 插件会在清单 schema 中声明
mcp.json内的每个${VAR} - 清单中的所有路径均为有效的相对路径 (不含
..或绝对路径) - 插件已在本地完成测试
- Cursor 多插件仓库的根目录中包含
.cursor-plugin/marketplace.json,且插件名称唯一