codingbuddy-rules 4.5.0 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. package/.ai-rules/adapters/antigravity.md +6 -6
  2. package/.ai-rules/adapters/claude-code.md +68 -4
  3. package/.ai-rules/adapters/codex.md +5 -5
  4. package/.ai-rules/adapters/cursor.md +2 -2
  5. package/.ai-rules/adapters/kiro.md +8 -8
  6. package/.ai-rules/adapters/opencode.md +7 -7
  7. package/.ai-rules/adapters/q.md +2 -2
  8. package/.ai-rules/agents/README.md +66 -16
  9. package/.ai-rules/agents/accessibility-specialist.json +2 -1
  10. package/.ai-rules/agents/act-mode.json +2 -1
  11. package/.ai-rules/agents/agent-architect.json +8 -7
  12. package/.ai-rules/agents/ai-ml-engineer.json +1 -0
  13. package/.ai-rules/agents/architecture-specialist.json +1 -0
  14. package/.ai-rules/agents/auto-mode.json +4 -2
  15. package/.ai-rules/agents/backend-developer.json +1 -0
  16. package/.ai-rules/agents/code-quality-specialist.json +1 -0
  17. package/.ai-rules/agents/code-reviewer.json +65 -64
  18. package/.ai-rules/agents/data-engineer.json +8 -7
  19. package/.ai-rules/agents/data-scientist.json +10 -9
  20. package/.ai-rules/agents/devops-engineer.json +1 -0
  21. package/.ai-rules/agents/documentation-specialist.json +1 -0
  22. package/.ai-rules/agents/eval-mode.json +20 -19
  23. package/.ai-rules/agents/event-architecture-specialist.json +1 -0
  24. package/.ai-rules/agents/frontend-developer.json +1 -0
  25. package/.ai-rules/agents/i18n-specialist.json +2 -1
  26. package/.ai-rules/agents/integration-specialist.json +1 -0
  27. package/.ai-rules/agents/migration-specialist.json +1 -0
  28. package/.ai-rules/agents/mobile-developer.json +8 -7
  29. package/.ai-rules/agents/observability-specialist.json +1 -0
  30. package/.ai-rules/agents/parallel-orchestrator.json +346 -0
  31. package/.ai-rules/agents/performance-specialist.json +1 -0
  32. package/.ai-rules/agents/plan-mode.json +3 -1
  33. package/.ai-rules/agents/plan-reviewer.json +208 -0
  34. package/.ai-rules/agents/platform-engineer.json +1 -0
  35. package/.ai-rules/agents/security-engineer.json +9 -8
  36. package/.ai-rules/agents/security-specialist.json +2 -1
  37. package/.ai-rules/agents/seo-specialist.json +1 -0
  38. package/.ai-rules/agents/software-engineer.json +1 -0
  39. package/.ai-rules/agents/solution-architect.json +11 -10
  40. package/.ai-rules/agents/systems-developer.json +9 -8
  41. package/.ai-rules/agents/technical-planner.json +11 -10
  42. package/.ai-rules/agents/test-engineer.json +7 -6
  43. package/.ai-rules/agents/test-strategy-specialist.json +1 -0
  44. package/.ai-rules/agents/tooling-engineer.json +4 -3
  45. package/.ai-rules/agents/ui-ux-designer.json +1 -0
  46. package/.ai-rules/keyword-modes.json +4 -4
  47. package/.ai-rules/rules/clarification-guide.md +14 -14
  48. package/.ai-rules/rules/core.md +73 -0
  49. package/.ai-rules/rules/parallel-execution.md +217 -0
  50. package/.ai-rules/skills/README.md +23 -1
  51. package/.ai-rules/skills/agent-design/SKILL.md +5 -0
  52. package/.ai-rules/skills/agent-design/examples/agent-template.json +58 -0
  53. package/.ai-rules/skills/agent-design/references/expertise-guidelines.md +112 -0
  54. package/.ai-rules/skills/agent-discussion/SKILL.md +199 -0
  55. package/.ai-rules/skills/agent-discussion-panel/SKILL.md +448 -0
  56. package/.ai-rules/skills/api-design/SKILL.md +5 -0
  57. package/.ai-rules/skills/api-design/examples/error-response.json +159 -0
  58. package/.ai-rules/skills/api-design/examples/openapi-template.yaml +393 -0
  59. package/.ai-rules/skills/build-fix/SKILL.md +234 -0
  60. package/.ai-rules/skills/code-explanation/SKILL.md +4 -0
  61. package/.ai-rules/skills/context-management/SKILL.md +1 -0
  62. package/.ai-rules/skills/cost-budget/SKILL.md +348 -0
  63. package/.ai-rules/skills/cross-repo-issues/SKILL.md +257 -0
  64. package/.ai-rules/skills/database-migration/SKILL.md +1 -0
  65. package/.ai-rules/skills/deepsearch/SKILL.md +214 -0
  66. package/.ai-rules/skills/deployment-checklist/SKILL.md +1 -0
  67. package/.ai-rules/skills/error-analysis/SKILL.md +1 -0
  68. package/.ai-rules/skills/finishing-a-development-branch/SKILL.md +281 -0
  69. package/.ai-rules/skills/frontend-design/SKILL.md +5 -0
  70. package/.ai-rules/skills/frontend-design/examples/component-template.tsx +203 -0
  71. package/.ai-rules/skills/frontend-design/references/css-patterns.md +243 -0
  72. package/.ai-rules/skills/git-master/SKILL.md +358 -0
  73. package/.ai-rules/skills/incident-response/SKILL.md +1 -0
  74. package/.ai-rules/skills/legacy-modernization/SKILL.md +1 -0
  75. package/.ai-rules/skills/mcp-builder/SKILL.md +7 -0
  76. package/.ai-rules/skills/mcp-builder/examples/resource-example.ts +233 -0
  77. package/.ai-rules/skills/mcp-builder/examples/tool-example.ts +203 -0
  78. package/.ai-rules/skills/mcp-builder/references/protocol-spec.md +215 -0
  79. package/.ai-rules/skills/performance-optimization/SKILL.md +3 -0
  80. package/.ai-rules/skills/plan-and-review/SKILL.md +115 -0
  81. package/.ai-rules/skills/pr-all-in-one/SKILL.md +15 -13
  82. package/.ai-rules/skills/pr-all-in-one/configuration-guide.md +7 -7
  83. package/.ai-rules/skills/pr-all-in-one/pr-templates.md +10 -10
  84. package/.ai-rules/skills/pr-review/SKILL.md +4 -0
  85. package/.ai-rules/skills/receiving-code-review/SKILL.md +347 -0
  86. package/.ai-rules/skills/refactoring/SKILL.md +1 -0
  87. package/.ai-rules/skills/requesting-code-review/SKILL.md +348 -0
  88. package/.ai-rules/skills/rule-authoring/SKILL.md +5 -0
  89. package/.ai-rules/skills/rule-authoring/examples/rule-template.md +142 -0
  90. package/.ai-rules/skills/rule-authoring/examples/trigger-patterns.md +126 -0
  91. package/.ai-rules/skills/security-audit/SKILL.md +4 -0
  92. package/.ai-rules/skills/skill-creator/SKILL.md +461 -0
  93. package/.ai-rules/skills/skill-creator/agents/analyzer.md +206 -0
  94. package/.ai-rules/skills/skill-creator/agents/comparator.md +167 -0
  95. package/.ai-rules/skills/skill-creator/agents/grader.md +152 -0
  96. package/.ai-rules/skills/skill-creator/assets/eval_review.html +289 -0
  97. package/.ai-rules/skills/skill-creator/assets/skill-template.md +43 -0
  98. package/.ai-rules/skills/skill-creator/eval-viewer/generate_review.py +496 -0
  99. package/.ai-rules/skills/skill-creator/references/frontmatter-guide.md +632 -0
  100. package/.ai-rules/skills/skill-creator/references/multi-tool-compat.md +480 -0
  101. package/.ai-rules/skills/skill-creator/references/schemas.md +784 -0
  102. package/.ai-rules/skills/skill-creator/scripts/aggregate_benchmark.py +302 -0
  103. package/.ai-rules/skills/skill-creator/scripts/init_skill.sh +196 -0
  104. package/.ai-rules/skills/skill-creator/scripts/run_loop.py +327 -0
  105. package/.ai-rules/skills/systematic-debugging/SKILL.md +1 -0
  106. package/.ai-rules/skills/tech-debt/SKILL.md +1 -0
  107. package/.ai-rules/skills/test-coverage-gate/SKILL.md +303 -0
  108. package/.ai-rules/skills/tmux-master/SKILL.md +491 -0
  109. package/.ai-rules/skills/using-git-worktrees/SKILL.md +368 -0
  110. package/.ai-rules/skills/verification-before-completion/SKILL.md +234 -0
  111. package/.ai-rules/skills/widget-slot-architecture/SKILL.md +6 -0
  112. package/.ai-rules/skills/widget-slot-architecture/examples/parallel-route-setup.tsx +206 -0
  113. package/.ai-rules/skills/widget-slot-architecture/examples/widget-component.tsx +250 -0
  114. package/.ai-rules/skills/writing-plans/SKILL.md +78 -0
  115. package/bin/cli.js +178 -0
  116. package/lib/init/detect-stack.js +148 -0
  117. package/lib/init/generate-config.js +31 -0
  118. package/lib/init/index.js +86 -0
  119. package/lib/init/prompt.js +60 -0
  120. package/lib/init/scaffold.js +67 -0
  121. package/lib/init/suggest-agent.js +46 -0
  122. package/package.json +10 -2
@@ -0,0 +1,358 @@
1
+ ---
2
+ name: git-master
3
+ description: Use when performing git operations - commits, rebasing, cherry-picking, history cleanup, or conflict resolution. Ensures atomic commits, clean history, and consistent commit message style.
4
+ allowed-tools: Read, Grep, Glob, Bash
5
+ ---
6
+
7
+ # Git Master
8
+
9
+ ## Overview
10
+
11
+ Messy git history obscures intent, makes debugging harder, and wastes reviewer time. Clean history tells the story of WHY changes were made, not just WHAT changed.
12
+
13
+ **Core principle:** Every commit should be a single, complete, logical change that can be understood, reverted, or cherry-picked independently.
14
+
15
+ **Violating the letter of this process is violating the spirit of clean version control.**
16
+
17
+ ## The Iron Law
18
+
19
+ ```
20
+ ONE LOGICAL CHANGE PER COMMIT. NO EXCEPTIONS.
21
+ ```
22
+
23
+ If a commit does two things, it should be two commits. If a commit is incomplete, it should not exist yet.
24
+
25
+ **No exceptions:**
26
+ - "I'll split it later" → Split it now
27
+ - "It's a small extra change" → Separate commit
28
+ - "They're related" → Related is not identical
29
+
30
+ ## When to Use
31
+
32
+ Use for ANY git operation beyond trivial:
33
+ - Creating commits (single or multiple)
34
+ - Rebasing branches (interactive or standard)
35
+ - Cherry-picking commits across branches
36
+ - Cleaning up history (amend, squash, fixup)
37
+ - Resolving merge conflicts
38
+ - Preparing branches for review
39
+
40
+ **Use this ESPECIALLY when:**
41
+ - Repository has established commit conventions
42
+ - Branch has messy work-in-progress commits before PR
43
+ - Cherry-picking between release branches
44
+ - Resolving complex merge conflicts
45
+ - History needs cleanup before merging
46
+
47
+ **Don't skip when:**
48
+ - "It's just a quick fix" (quick fixes deserve clean commits too)
49
+ - "Nobody reads commit history" (future-you does, during `git bisect`)
50
+ - "I'll squash on merge anyway" (squash merges lose valuable context)
51
+
52
+ ## When NOT to Use
53
+
54
+ - **Initial prototyping** — Experiment freely, clean up before PR
55
+ - **Throwaway branches** — No need for perfect history on disposable work
56
+ - **Automated commits** — CI/CD generated commits follow their own patterns
57
+
58
+ ## The Six Phases
59
+
60
+ ### Phase 1: Style Detection
61
+
62
+ **BEFORE making any commit, understand the repo's conventions:**
63
+
64
+ 1. **Analyze Recent History**
65
+ ```bash
66
+ git log --oneline -20
67
+ ```
68
+
69
+ 2. **Detect Commit Message Pattern**
70
+
71
+ | Pattern | Example | Convention |
72
+ |---------|---------|------------|
73
+ | **Conventional Commits** | `feat(auth): add OAuth2 flow` | `type(scope): description` |
74
+ | **Imperative mood** | `Add user validation` | Verb-first, present tense |
75
+ | **Ticket prefix** | `[PROJ-123] Fix login bug` | `[TICKET] description` |
76
+ | **Emoji prefix** | `:bug: Fix null pointer` | Emoji + description |
77
+ | **Freeform** | `Fixed the login thing` | No consistent pattern |
78
+
79
+ 3. **Match the Detected Style**
80
+ - Use the same pattern for your commits
81
+ - If no pattern detected, default to Conventional Commits
82
+ - Never mix styles within a PR
83
+
84
+ **Completion criteria:**
85
+ - [ ] `style_detected` — Commit message pattern identified
86
+ - [ ] `convention_noted` — Will follow detected convention
87
+
88
+ ### Phase 2: Atomic Commits
89
+
90
+ **Every commit must be atomic — one logical change, complete and self-contained.**
91
+
92
+ 1. **Stage Selectively**
93
+ ```bash
94
+ # Stage specific files, not everything
95
+ git add src/auth/login.ts src/auth/login.test.ts
96
+
97
+ # For partial file staging
98
+ git add -p src/utils/helpers.ts
99
+ ```
100
+
101
+ **Never use `git add .` or `git add -A` unless you have verified every change belongs together.**
102
+
103
+ 2. **Verify Staged Content**
104
+ ```bash
105
+ git diff --cached # Review what you're about to commit
106
+ git diff # Check what's NOT staged
107
+ ```
108
+
109
+ 3. **Write the Commit Message**
110
+
111
+ **Structure:**
112
+ ```
113
+ <type>(<scope>): <what changed> (max 72 chars)
114
+
115
+ <why this change was needed>
116
+ <any important context>
117
+
118
+ Refs: #issue-number (if applicable)
119
+ ```
120
+
121
+ **Good vs Bad:**
122
+
123
+ | Bad | Good |
124
+ |-----|------|
125
+ | `fix stuff` | `fix(auth): prevent session timeout on token refresh` |
126
+ | `WIP` | `feat(cart): add quantity validation for checkout` |
127
+ | `updates` | `refactor(api): extract retry logic into shared middleware` |
128
+ | `fix tests` | `test(auth): cover edge case for expired JWT tokens` |
129
+
130
+ 4. **Verify Atomicity**
131
+ - Does this commit do exactly ONE thing?
132
+ - Could someone revert JUST this commit safely?
133
+ - Does the codebase compile/pass tests at this commit?
134
+
135
+ **Completion criteria:**
136
+ - [ ] `changes_staged_selectively` — No unrelated changes staged
137
+ - [ ] `message_follows_convention` — Matches repo's detected style
138
+ - [ ] `commit_is_atomic` — Single logical change
139
+
140
+ ### Phase 3: Rebase Workflows
141
+
142
+ **Use rebase to maintain a clean, linear history.**
143
+
144
+ 1. **Standard Rebase (update branch)**
145
+ ```bash
146
+ git fetch origin
147
+ git rebase origin/main
148
+ ```
149
+
150
+ 2. **Interactive Rebase (clean up commits)**
151
+ ```bash
152
+ git rebase -i HEAD~N # N = number of commits to review
153
+ ```
154
+
155
+ **Action guide:**
156
+
157
+ | Action | When to Use |
158
+ |--------|-------------|
159
+ | `pick` | Keep commit as-is |
160
+ | `reword` | Fix commit message only |
161
+ | `squash` | Merge into previous, combine messages |
162
+ | `fixup` | Merge into previous, discard message |
163
+ | `drop` | Remove commit entirely |
164
+
165
+ 3. **Safe Rebase Checklist**
166
+ - [ ] Branch is NOT shared with others (or team agrees on force-push)
167
+ - [ ] All changes are committed (no uncommitted work)
168
+ - [ ] You understand what each commit does before reordering
169
+
170
+ > **AI Agent Note:** Interactive commands (`rebase -i`, `add -p`) require terminal interaction. AI agents without interactive input support should use non-interactive alternatives (e.g., `git rebase --onto`, `git add <specific-files>`) or prepare the rebase todo list programmatically.
171
+
172
+ 4. **If Rebase Goes Wrong**
173
+ ```bash
174
+ git rebase --abort # Cancel in-progress rebase
175
+ git reflog # Find pre-rebase state
176
+ git reset --hard HEAD@{N} # Restore (DESTRUCTIVE — uncommitted changes lost)
177
+ ```
178
+
179
+ **Completion criteria:**
180
+ - [ ] `history_is_linear` — No unnecessary merge commits
181
+ - [ ] `commits_are_clean` — WIP commits squashed
182
+
183
+ ### Phase 4: Cherry-Pick
184
+
185
+ **Safely move individual commits between branches.**
186
+
187
+ 1. **Before Cherry-Picking**
188
+ - Identify the exact commit(s): `git log --oneline source-branch`
189
+ - Verify the commit is self-contained (atomic)
190
+ - Check for dependencies on other commits
191
+
192
+ 2. **Execute Cherry-Pick**
193
+ ```bash
194
+ git cherry-pick <commit-hash>
195
+
196
+ # For multiple commits
197
+ git cherry-pick <hash1> <hash2> <hash3>
198
+
199
+ # For a range
200
+ git cherry-pick <older-hash>..<newer-hash>
201
+ ```
202
+
203
+ 3. **Handle Cherry-Pick Conflicts**
204
+ ```bash
205
+ # View conflicting files
206
+ git status
207
+
208
+ # Resolve conflicts, then
209
+ git add <resolved-files>
210
+ git cherry-pick --continue
211
+
212
+ # Or abort if too complex
213
+ git cherry-pick --abort
214
+ ```
215
+
216
+ 4. **Verify After Cherry-Pick**
217
+ - Tests pass on the target branch
218
+ - No unintended side effects
219
+ - Commit message still makes sense in new context
220
+
221
+ **Completion criteria:**
222
+ - [ ] `commit_identified` — Correct commit(s) selected
223
+ - [ ] `conflicts_resolved` — All conflicts handled
224
+ - [ ] `tests_pass` — Target branch is green
225
+
226
+ ### Phase 5: History Cleanup
227
+
228
+ **Fix mistakes without breaking history for others.**
229
+
230
+ 1. **Amend Last Commit**
231
+ ```bash
232
+ # Add forgotten changes
233
+ git add <forgotten-file>
234
+ git commit --amend
235
+
236
+ # Fix message only
237
+ git commit --amend -m "corrected message"
238
+ ```
239
+ **Only amend unpushed commits.** Amending pushed commits requires force-push.
240
+
241
+ 2. **Fixup Older Commits**
242
+ ```bash
243
+ # Create a fixup commit
244
+ git commit --fixup=<target-hash>
245
+
246
+ # Auto-squash during rebase
247
+ git rebase -i --autosquash HEAD~N
248
+ ```
249
+
250
+ 3. **Recovery with Reflog**
251
+ ```bash
252
+ # View recent HEAD movements
253
+ git reflog
254
+
255
+ # Restore accidentally deleted commit
256
+ git cherry-pick <reflog-hash>
257
+
258
+ # Restore to a previous state (DESTRUCTIVE — all uncommitted changes are lost)
259
+ git reset --hard HEAD@{N}
260
+ ```
261
+
262
+ 4. **Safety Rules**
263
+ - Never rewrite history on shared branches without team agreement
264
+ - Always verify `git reflog` shows the state you want to restore
265
+ - Create a backup branch before destructive operations: `git branch backup-before-cleanup`
266
+
267
+ **Completion criteria:**
268
+ - [ ] `history_corrected` — Mistakes fixed
269
+ - [ ] `no_shared_history_rewritten` — Shared branches untouched
270
+ - [ ] `backup_created` — Safety branch exists for risky operations
271
+
272
+ ### Phase 6: Conflict Resolution
273
+
274
+ **Resolve merge conflicts systematically, not by guessing.**
275
+
276
+ 1. **Understand the Conflict**
277
+ ```bash
278
+ # See which files conflict
279
+ git status
280
+
281
+ # See what both sides changed
282
+ git diff --merge
283
+ git log --merge --oneline
284
+ ```
285
+
286
+ 2. **Resolve Each File**
287
+ - Read BOTH sides of the conflict markers
288
+ - Understand WHY each side made their change
289
+ - Choose the resolution that preserves BOTH intents
290
+ - If unsure, check the original commits for context
291
+
292
+ 3. **Resolution Strategies**
293
+
294
+ | Situation | Strategy |
295
+ |-----------|----------|
296
+ | One side is clearly correct | Take that side |
297
+ | Both changes needed | Combine manually |
298
+ | Changes are incompatible | Consult the other author |
299
+ | Complex logic conflict | Write a new implementation that satisfies both |
300
+
301
+ 4. **After Resolving**
302
+ ```bash
303
+ git add <resolved-files>
304
+ git commit # or git rebase --continue / git merge --continue
305
+ ```
306
+
307
+ 5. **Verify Resolution**
308
+ - Run tests — conflicts often introduce subtle bugs
309
+ - Review the merge commit diff — ensure nothing was lost
310
+ - Check that both features still work as intended
311
+
312
+ **Completion criteria:**
313
+ - [ ] `all_conflicts_resolved` — No remaining conflict markers
314
+ - [ ] `both_intents_preserved` — No changes silently dropped
315
+ - [ ] `tests_pass` — Resolution doesn't break anything
316
+
317
+ ## Verification Checklist
318
+
319
+ Before completing any git operation:
320
+
321
+ - [ ] Commit message matches repo's detected convention
322
+ - [ ] Each commit contains exactly one logical change
323
+ - [ ] No `git add .` used without reviewing all changes
324
+ - [ ] Shared branch history not rewritten without team agreement
325
+ - [ ] Tests pass at every commit (not just the last one)
326
+ - [ ] No conflict markers left in code (`<<<<<<<`, `=======`, `>>>>>>>`)
327
+ - [ ] Backup branch created before destructive operations
328
+
329
+ ## Red Flags — STOP
330
+
331
+ | Thought | Reality |
332
+ |---------|---------|
333
+ | "I'll clean up the history later" | Later never comes. Clean it now. |
334
+ | "Just one big commit is fine" | Big commits are impossible to review, revert, or bisect. |
335
+ | "Nobody reads commit messages" | `git blame` and `git bisect` users do. Future-you does. |
336
+ | "Force push is fine, I'm the only one on this branch" | Verify first. CI, bots, and reviewers may have fetched. |
337
+ | "The merge conflict is obvious, just take mine" | Obvious conflicts hide subtle logic bugs. Read both sides. |
338
+ | "I'll squash on merge anyway" | Squash loses the story. Clean history beats squashed history. |
339
+ | "Rebase is scary, I'll just merge" | Merge commits obscure linear history. Learn rebase. |
340
+ | "This commit message is good enough" | Future readers have zero context. Be specific. |
341
+
342
+ **ALL of these mean: STOP. Follow the relevant phase.**
343
+
344
+ ## Related Skills
345
+
346
+ | Skill | Relationship |
347
+ |-------|-------------|
348
+ | `refactoring` | Refactoring produces commits — use git-master for commit hygiene |
349
+ | `test-driven-development` | TDD cycle maps to atomic commits: one test + impl per commit |
350
+ | `pr-all-in-one` | PR preparation requires clean history — git-master feeds into it |
351
+ | `deployment-checklist` | Deploy from clean branches with verified history |
352
+
353
+ ## Related Agents
354
+
355
+ | Agent | When to Involve |
356
+ |-------|----------------|
357
+ | Code Reviewer | When commit organization affects review quality |
358
+ | DevOps Engineer | When branch strategy impacts CI/CD pipeline |
@@ -1,6 +1,7 @@
1
1
  ---
2
2
  name: incident-response
3
3
  description: Use when production incident occurs, alerts fire, service degradation detected, or on-call escalation needed - guides systematic organizational response before technical fixes
4
+ disable-model-invocation: true
4
5
  ---
5
6
 
6
7
  # Incident Response
@@ -1,6 +1,7 @@
1
1
  ---
2
2
  name: legacy-modernization
3
3
  description: Use when modernizing legacy code or migrating outdated patterns to current best practices. Covers assessment, strangler fig pattern, incremental migration, and risk management.
4
+ argument-hint: [target-module-or-path]
4
5
  ---
5
6
 
6
7
  # Legacy Modernization
@@ -1,6 +1,7 @@
1
1
  ---
2
2
  name: mcp-builder
3
3
  description: Use when building or extending MCP (Model Context Protocol) servers. Covers NestJS-based server design, Tools/Resources/Prompts capability design, transport implementation (stdio/SSE), and testing strategies.
4
+ argument-hint: [capability-name]
4
5
  ---
5
6
 
6
7
  # MCP Builder
@@ -354,3 +355,9 @@ Server:
354
355
  | No error handling in tools | Always catch and return isError: true |
355
356
  | Breaking stdio with console.log | Use stderr for logs: `process.stderr.write(...)` |
356
357
  | Hardcoded paths | Use env vars or config injection |
358
+
359
+ ## Additional resources
360
+
361
+ - [Tool implementation example](examples/tool-example.ts) — Complete MCP Tool handler with schema, validation, and error handling
362
+ - [Resource implementation example](examples/resource-example.ts) — Complete MCP Resource handler with URI routing and templates
363
+ - [MCP protocol quick reference](references/protocol-spec.md) — JSON-RPC message formats, capability methods, transport modes, and error codes
@@ -0,0 +1,233 @@
1
+ /**
2
+ * MCP Resource Implementation Example
3
+ *
4
+ * Demonstrates a complete Resource handler following the MCP specification.
5
+ * Resources are read-only data exposed via URI that the AI can read.
6
+ *
7
+ * Key patterns:
8
+ * - URI-based addressing with scheme://path convention
9
+ * - Resource templates for dynamic URIs
10
+ * - List + Read separation
11
+ * - Proper MIME type handling
12
+ */
13
+
14
+ import { Injectable } from '@nestjs/common';
15
+
16
+ // --- 1. Define Static Resources ---
17
+
18
+ export const staticResources = [
19
+ {
20
+ uri: 'config://project',
21
+ name: 'Project Configuration',
22
+ description: 'Current project settings including tech stack, conventions, and build config',
23
+ mimeType: 'application/json',
24
+ },
25
+ {
26
+ uri: 'docs://changelog',
27
+ name: 'Changelog',
28
+ description: 'Project changelog with recent changes and version history',
29
+ mimeType: 'text/markdown',
30
+ },
31
+ ];
32
+
33
+ // --- 2. Define Resource Templates (Dynamic URIs) ---
34
+
35
+ export const resourceTemplates = [
36
+ {
37
+ uriTemplate: 'rules://{ruleName}',
38
+ name: 'AI Rule',
39
+ description: 'Retrieve a specific AI coding rule by name (e.g., "core", "project")',
40
+ mimeType: 'text/markdown',
41
+ },
42
+ {
43
+ uriTemplate: 'agents://{agentName}',
44
+ name: 'Agent Definition',
45
+ description: 'Retrieve a specialist agent definition by name (e.g., "solution-architect")',
46
+ mimeType: 'application/json',
47
+ },
48
+ {
49
+ uriTemplate: 'skills://{skillName}',
50
+ name: 'Skill Content',
51
+ description: 'Retrieve a skill definition by name (e.g., "mcp-builder", "api-design")',
52
+ mimeType: 'text/markdown',
53
+ },
54
+ ];
55
+
56
+ // --- 3. Result Types ---
57
+
58
+ interface ResourceContent {
59
+ uri: string;
60
+ mimeType: string;
61
+ text: string;
62
+ }
63
+
64
+ // --- 4. Implement the Resource Handler ---
65
+
66
+ @Injectable()
67
+ export class ResourceHandler {
68
+ constructor(
69
+ private readonly rulesService: RulesService,
70
+ private readonly agentsService: AgentsService,
71
+ private readonly configService: ConfigService,
72
+ ) {}
73
+
74
+ /**
75
+ * List all available resources (static + dynamic discovered).
76
+ * Called by MCP client via resources/list.
77
+ */
78
+ async listResources(): Promise<typeof staticResources> {
79
+ // Static resources are always available
80
+ const resources = [...staticResources];
81
+
82
+ // Dynamically discover available rules
83
+ const ruleNames = await this.rulesService.listRuleNames();
84
+ for (const name of ruleNames) {
85
+ resources.push({
86
+ uri: `rules://${name}`,
87
+ name: `Rule: ${name}`,
88
+ description: `AI coding rule: ${name}`,
89
+ mimeType: 'text/markdown',
90
+ });
91
+ }
92
+
93
+ return resources;
94
+ }
95
+
96
+ /**
97
+ * Read a specific resource by URI.
98
+ * Called by MCP client via resources/read.
99
+ */
100
+ async readResource(uri: string): Promise<ResourceContent> {
101
+ // Parse the URI scheme and path
102
+ const match = uri.match(/^(\w+):\/\/(.+)$/);
103
+ if (!match) {
104
+ throw new ResourceNotFoundError(`Invalid resource URI format: ${uri}`);
105
+ }
106
+
107
+ const [, scheme, path] = match;
108
+
109
+ switch (scheme) {
110
+ case 'config':
111
+ return this.readConfig(uri, path);
112
+ case 'docs':
113
+ return this.readDocs(uri, path);
114
+ case 'rules':
115
+ return this.readRule(uri, path);
116
+ case 'agents':
117
+ return this.readAgent(uri, path);
118
+ case 'skills':
119
+ return this.readSkill(uri, path);
120
+ default:
121
+ throw new ResourceNotFoundError(`Unknown resource scheme: ${scheme}`);
122
+ }
123
+ }
124
+
125
+ private async readConfig(uri: string, path: string): Promise<ResourceContent> {
126
+ if (path !== 'project') {
127
+ throw new ResourceNotFoundError(`Unknown config resource: ${path}`);
128
+ }
129
+
130
+ const config = await this.configService.getProjectConfig();
131
+ return {
132
+ uri,
133
+ mimeType: 'application/json',
134
+ text: JSON.stringify(config, null, 2),
135
+ };
136
+ }
137
+
138
+ private async readDocs(uri: string, path: string): Promise<ResourceContent> {
139
+ if (path !== 'changelog') {
140
+ throw new ResourceNotFoundError(`Unknown docs resource: ${path}`);
141
+ }
142
+
143
+ const changelog = await this.rulesService.readFile('CHANGELOG.md');
144
+ return {
145
+ uri,
146
+ mimeType: 'text/markdown',
147
+ text: changelog,
148
+ };
149
+ }
150
+
151
+ private async readRule(uri: string, ruleName: string): Promise<ResourceContent> {
152
+ const content = await this.rulesService.getRule(ruleName);
153
+ if (!content) {
154
+ throw new ResourceNotFoundError(`Rule not found: ${ruleName}`);
155
+ }
156
+
157
+ return {
158
+ uri,
159
+ mimeType: 'text/markdown',
160
+ text: content,
161
+ };
162
+ }
163
+
164
+ private async readAgent(uri: string, agentName: string): Promise<ResourceContent> {
165
+ const agent = await this.agentsService.getAgent(agentName);
166
+ if (!agent) {
167
+ throw new ResourceNotFoundError(`Agent not found: ${agentName}`);
168
+ }
169
+
170
+ return {
171
+ uri,
172
+ mimeType: 'application/json',
173
+ text: JSON.stringify(agent, null, 2),
174
+ };
175
+ }
176
+
177
+ private async readSkill(uri: string, skillName: string): Promise<ResourceContent> {
178
+ const content = await this.rulesService.getSkill(skillName);
179
+ if (!content) {
180
+ throw new ResourceNotFoundError(`Skill not found: ${skillName}`);
181
+ }
182
+
183
+ return {
184
+ uri,
185
+ mimeType: 'text/markdown',
186
+ text: content,
187
+ };
188
+ }
189
+ }
190
+
191
+ // --- 5. Register in MCP Service ---
192
+
193
+ /*
194
+ // In mcp.service.ts:
195
+ import { staticResources, resourceTemplates, ResourceHandler } from './resources/resource-handler';
196
+
197
+ server.setRequestHandler(ListResourcesRequestSchema, async () => ({
198
+ resources: await this.resourceHandler.listResources(),
199
+ }));
200
+
201
+ server.setRequestHandler(ListResourceTemplatesRequestSchema, async () => ({
202
+ resourceTemplates,
203
+ }));
204
+
205
+ server.setRequestHandler(ReadResourceRequestSchema, async (request) => ({
206
+ contents: [await this.resourceHandler.readResource(request.params.uri)],
207
+ }));
208
+ */
209
+
210
+ // --- Error Types ---
211
+
212
+ class ResourceNotFoundError extends Error {
213
+ constructor(message: string) {
214
+ super(message);
215
+ this.name = 'ResourceNotFoundError';
216
+ }
217
+ }
218
+
219
+ // Placeholder interfaces for dependency injection
220
+ interface RulesService {
221
+ listRuleNames(): Promise<string[]>;
222
+ getRule(name: string): Promise<string | null>;
223
+ getSkill(name: string): Promise<string | null>;
224
+ readFile(path: string): Promise<string>;
225
+ }
226
+
227
+ interface AgentsService {
228
+ getAgent(name: string): Promise<Record<string, unknown> | null>;
229
+ }
230
+
231
+ interface ConfigService {
232
+ getProjectConfig(): Promise<Record<string, unknown>>;
233
+ }