有關構建、組織和提交 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,且插件名稱唯一