APIエンドポイントの追加・変更で、DTO、入力検証、OpenAPI仕様、MCPツールの説明や公開範囲を揃え、エージェントからも扱いやすいAPIに整えます。
- APIエンドポイントを追加したいとき
- DTOと入力検証を整えたいとき
- MCPツールとしてAPIを公開したいとき
Cursorの`.mdc`ルールの書き方や適用範囲の設定、手動呼び出し、競合の確認方法を、具体例とともに案内します。
How to write and manage Cursor rules - invoke with @cursor-usage
実行スコア 未検証
インストール方法を見るCursorのルールを.cursor/rules/に.mdcファイルとして作成・管理する方法を案内します。YAML形式のfrontmatterに記述するdescription、対象ファイルを指定するglobs、自動適用の有無を決めるalwaysApplyの役割を説明し、TypeScriptやReactなどに使えるパターン例を示します。ルール本文を見出しや具体的なコード例、例外、チェックリストで整理する方法も扱います。対象ファイルを開いたときの自動適用と、プロンプトで@ルール名を指定する手動適用の違いを確認できます。ルールが適用されない場合や、複数ルールが競合する場合の確認手順も含まれます。
プロジェクト固有のコード規約や実装方針をCursorに伝えたいときに役立ちます。ルールを用途別に整理したい人や、意図したファイルにだけ適用されるよう調整したい人にも向いています。
ルールファイルは.cursor/rules/内の.mdc形式で管理します。
この紹介文は、公開されている SKILL.md をもとに AI(OpenAI Codex)が作成しました。正確な仕様は下の原文を確認してください。
インストールする前に、エージェントに与えられる指示の中身を確認できます。
Source Cursor rule: .cursor/rules/cursor-usage.mdc.
Original file scope: .cursor/rules/*.mdc.
Original Cursor alwaysApply: false.
Cursor rules provide system-level instructions to the AI to maintain code consistency, quality, and adherence to project standards. They are stored in the .cursor/rules/ directory as .mdc (Markdown with frontmatter) files.
Each .mdc rule file consists of two parts:
---
description: Brief overview of what this rule enforces
globs: **/*.{ts,tsx}
alwaysApply: true
---
Frontmatter Fields:
description: A clear, concise explanation of the rule's purposeglobs: Glob pattern to match files where this rule should apply (plain string, no quotes or arrays)
**/*.tsx - All TSX files**/*.{ts,tsx} - All TS and TSX filesapps/*/components/**/*.tsx - All TSX files in any app's components directory**/trigger/**/*.ts - All TS files in trigger directoriesalwaysApply: Boolean indicating if the rule should always be active
true: Rule is always active when working on matching filesfalse: Rule can be selectively invoked with @rule-nameThe body of the rule file contains the actual guidelines, examples, and instructions written in Markdown format.
Rules with alwaysApply: true are automatically loaded when:
globs patternYou can reference specific rules in your prompts:
@design-system create a new button component
This explicitly tells Cursor to apply the design-system rule.
Always include:
// ✅ Good: Use semantic tokens
<div className="bg-background text-foreground">Content</div>
// ❌ Bad: Hardcoded colors
<div className="bg-white text-black">Content</div>
Organize content with descriptive headers:
## Core Principles
## Rules
## Examples
## Exceptions
## Common Mistakes
If there are cases where rules don't apply, state them clearly:
## Exceptions
The ONLY time you can pass className to a design system component is for:
1. Width utilities: `w-full`, `max-w-md`
2. Responsive display: `hidden`, `md:block`
Provide actionable checklists for validation:
## Code Review Checklist
Before committing:
- [ ] Uses semantic color tokens
- [ ] Works in both light and dark mode
- [ ] Fully responsive
.mdc file in .cursor/rules/.mdc fileRecommended structure:
.cursor/rules/
├── design-system.mdc # Component usage, variants, composition
├── code-standards.mdc # General code quality rules
├── typescript-rules.mdc # TypeScript type safety
├── react-code.mdc # React patterns and conventions
├── data-fetching.mdc # Server/client data patterns
└── cursor-usage.mdc # This file - how to use rules
# All TypeScript/TSX files
globs: **/*.{ts,tsx}
# Only TSX files (React components)
globs: **/*.tsx
# Only trigger task files
globs: **/trigger/**/*.ts
# Prisma schema files
globs: **/*.prisma
# All JSON and TypeScript files
globs: **/*.{ts,tsx,json}
** for recursive directory matching* for single-level wildcard{ts,tsx} for multiple extensionsglobs pattern matches your filealwaysApply is set appropriately@ruleNameglobsUse alwaysApply: false for rules that should only apply in specific contexts:
---
description: Performance optimization guidelines
globs: **/*.ts
alwaysApply: false
---
Invoke with: @performance-optimization refactor this component
More specific globs take precedence:
design-system.mdc with globs: **/*.tsx (broad)trigger.basic.mdc with globs: **/trigger/**/*.ts (specific)The specific rule will have more weight for trigger files.
touch .cursor/rules/my-new-rule.mdc
---
description: What this rule enforces
globs: **/*.{ts,tsx}
alwaysApply: true
---
# Rule Title
## Guidelines
- Point 1
- Point 2
globs pattern@my-new-rule in your promptglobs patternRemember: Rules are here to help, not hinder. If a rule doesn't make sense for a specific case, discuss with the team and update the rule accordingly.
まだレビューはありません。使ってみた感想をお寄せください。
ログインなしで書き込めます。使ってみた感想、質問、動かなかった環境などを気軽にどうぞ。
まだコメントはありません。最初のコメントを書いてみませんか。
APIエンドポイントの追加・変更で、DTO、入力検証、OpenAPI仕様、MCPツールの説明や公開範囲を揃え、エージェントからも扱いやすいAPIに整えます。
既存コードのデザインシステム利用状況を調べ、旧UI部品やlucide-reactのアイコンを@trycompai/design-systemの部品・Carbonアイコンへ置き換えるスキルです。
指定されたファイルのフックやAPI利用を点検し、禁止パターンをSWRやapiClientなどの指定方式へ修正するための監査手順と実装規約をまとめています。
NestJSのAPIとフロントエンドを調べ、権限チェックや監査ログのルール違反を修正するための確認項目を示します。
権限で表示や操作が変わるコンポーネントの単体テストを点検し、不足分の追加や失敗の修正を行って、管理者と閲覧専用ユーザーの動作を確かめます。
Better Authを使ったTypeScript認証の設定を支援し、データベース接続、セッション管理、メール認証、OAuth、プラグインやセキュリティ項目を整理します。