@hivehub/rulebook 2.1.0 → 3.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 (187) hide show
  1. package/README.md +779 -661
  2. package/dist/cli/commands.d.ts +22 -0
  3. package/dist/cli/commands.d.ts.map +1 -1
  4. package/dist/cli/commands.js +291 -8
  5. package/dist/cli/commands.js.map +1 -1
  6. package/dist/core/claude-mcp.d.ts +32 -0
  7. package/dist/core/claude-mcp.d.ts.map +1 -0
  8. package/dist/core/claude-mcp.js +92 -0
  9. package/dist/core/claude-mcp.js.map +1 -0
  10. package/dist/core/config-manager.d.ts.map +1 -1
  11. package/dist/core/config-manager.js +27 -6
  12. package/dist/core/config-manager.js.map +1 -1
  13. package/dist/core/generator.d.ts.map +1 -1
  14. package/dist/core/generator.js +98 -49
  15. package/dist/core/generator.js.map +1 -1
  16. package/dist/core/migrator.d.ts +13 -0
  17. package/dist/core/migrator.d.ts.map +1 -1
  18. package/dist/core/migrator.js +76 -9
  19. package/dist/core/migrator.js.map +1 -1
  20. package/dist/core/openspec-migrator.d.ts +1 -1
  21. package/dist/core/openspec-migrator.d.ts.map +1 -1
  22. package/dist/core/openspec-migrator.js +14 -7
  23. package/dist/core/openspec-migrator.js.map +1 -1
  24. package/dist/core/workflow-generator.js +297 -261
  25. package/dist/core/workflow-generator.js.map +1 -1
  26. package/dist/index.js +40 -1
  27. package/dist/index.js.map +1 -1
  28. package/dist/mcp/rulebook-server.d.ts.map +1 -1
  29. package/dist/mcp/rulebook-server.js +255 -74
  30. package/dist/mcp/rulebook-server.js.map +1 -1
  31. package/dist/memory/hnsw-index.d.ts +63 -0
  32. package/dist/memory/hnsw-index.d.ts.map +1 -0
  33. package/dist/memory/hnsw-index.js +421 -0
  34. package/dist/memory/hnsw-index.js.map +1 -0
  35. package/dist/memory/memory-cache.d.ts +33 -0
  36. package/dist/memory/memory-cache.d.ts.map +1 -0
  37. package/dist/memory/memory-cache.js +85 -0
  38. package/dist/memory/memory-cache.js.map +1 -0
  39. package/dist/memory/memory-hooks.d.ts +42 -0
  40. package/dist/memory/memory-hooks.d.ts.map +1 -0
  41. package/dist/memory/memory-hooks.js +193 -0
  42. package/dist/memory/memory-hooks.js.map +1 -0
  43. package/dist/memory/memory-manager.d.ts +55 -0
  44. package/dist/memory/memory-manager.d.ts.map +1 -0
  45. package/dist/memory/memory-manager.js +209 -0
  46. package/dist/memory/memory-manager.js.map +1 -0
  47. package/dist/memory/memory-search.d.ts +42 -0
  48. package/dist/memory/memory-search.d.ts.map +1 -0
  49. package/dist/memory/memory-search.js +166 -0
  50. package/dist/memory/memory-search.js.map +1 -0
  51. package/dist/memory/memory-store.d.ts +59 -0
  52. package/dist/memory/memory-store.d.ts.map +1 -0
  53. package/dist/memory/memory-store.js +394 -0
  54. package/dist/memory/memory-store.js.map +1 -0
  55. package/dist/memory/memory-types.d.ts +69 -0
  56. package/dist/memory/memory-types.d.ts.map +1 -0
  57. package/dist/memory/memory-types.js +7 -0
  58. package/dist/memory/memory-types.js.map +1 -0
  59. package/dist/memory/memory-vectorizer.d.ts +29 -0
  60. package/dist/memory/memory-vectorizer.d.ts.map +1 -0
  61. package/dist/memory/memory-vectorizer.js +104 -0
  62. package/dist/memory/memory-vectorizer.js.map +1 -0
  63. package/dist/types.d.ts +7 -0
  64. package/dist/types.d.ts.map +1 -1
  65. package/package.json +107 -106
  66. package/templates/commands/rulebook-memory-save.md +48 -0
  67. package/templates/commands/rulebook-memory-search.md +47 -0
  68. package/templates/commands/rulebook-task-apply.md +2 -2
  69. package/templates/commands/rulebook-task-archive.md +2 -2
  70. package/templates/commands/rulebook-task-create.md +2 -2
  71. package/templates/commands/rulebook-task-list.md +2 -2
  72. package/templates/commands/rulebook-task-show.md +2 -2
  73. package/templates/commands/rulebook-task-validate.md +2 -2
  74. package/templates/git/CI_CD_PATTERNS.md +4 -4
  75. package/templates/git/GITHUB_ACTIONS.md +3 -3
  76. package/templates/git/GITLAB_CI.md +4 -4
  77. package/templates/git/SECRETS_MANAGEMENT.md +4 -4
  78. package/templates/hooks/COMMIT_MSG.md +4 -4
  79. package/templates/hooks/POST_CHECKOUT.md +3 -3
  80. package/templates/hooks/PREPARE_COMMIT_MSG.md +3 -3
  81. package/templates/hooks/PRE_COMMIT.md +4 -4
  82. package/templates/hooks/PRE_PUSH.md +4 -4
  83. package/templates/modules/MEMORY.md +63 -0
  84. package/templates/skills/cli/aider/SKILL.md +59 -0
  85. package/templates/skills/cli/amazon-q/SKILL.md +35 -0
  86. package/templates/skills/cli/auggie/SKILL.md +42 -0
  87. package/templates/skills/cli/claude/SKILL.md +42 -0
  88. package/templates/skills/cli/claude-code/SKILL.md +146 -0
  89. package/templates/skills/cli/cline/SKILL.md +42 -0
  90. package/templates/skills/cli/codebuddy/SKILL.md +30 -0
  91. package/templates/skills/cli/codeium/SKILL.md +30 -0
  92. package/templates/skills/cli/codex/SKILL.md +31 -0
  93. package/templates/skills/cli/continue/SKILL.md +44 -0
  94. package/templates/skills/cli/cursor-cli/SKILL.md +38 -0
  95. package/templates/skills/cli/factory/SKILL.md +28 -0
  96. package/templates/skills/cli/gemini/SKILL.md +45 -0
  97. package/templates/skills/cli/kilocode/SKILL.md +28 -0
  98. package/templates/skills/cli/opencode/SKILL.md +28 -0
  99. package/templates/skills/core/agent-automation/SKILL.md +194 -0
  100. package/templates/skills/core/dag/SKILL.md +314 -0
  101. package/templates/skills/core/documentation-rules/SKILL.md +47 -0
  102. package/templates/skills/core/quality-enforcement/SKILL.md +78 -0
  103. package/templates/skills/frameworks/angular/SKILL.md +46 -0
  104. package/templates/skills/frameworks/django/SKILL.md +93 -0
  105. package/templates/skills/frameworks/electron/SKILL.md +157 -0
  106. package/templates/skills/frameworks/flask/SKILL.md +48 -0
  107. package/templates/skills/frameworks/flutter/SKILL.md +65 -0
  108. package/templates/skills/frameworks/jquery/SKILL.md +42 -0
  109. package/templates/skills/frameworks/laravel/SKILL.md +48 -0
  110. package/templates/skills/frameworks/nestjs/SKILL.md +53 -0
  111. package/templates/skills/frameworks/nextjs/SKILL.md +137 -0
  112. package/templates/skills/frameworks/nuxt/SKILL.md +50 -0
  113. package/templates/skills/frameworks/rails/SKILL.md +76 -0
  114. package/templates/skills/frameworks/react/SKILL.md +48 -0
  115. package/templates/skills/frameworks/react-native/SKILL.md +57 -0
  116. package/templates/skills/frameworks/spring/SKILL.md +49 -0
  117. package/templates/skills/frameworks/symfony/SKILL.md +46 -0
  118. package/templates/skills/frameworks/vue/SKILL.md +46 -0
  119. package/templates/skills/frameworks/zend/SKILL.md +45 -0
  120. package/templates/skills/ides/copilot/SKILL.md +47 -0
  121. package/templates/skills/ides/cursor/SKILL.md +53 -0
  122. package/templates/skills/ides/jetbrains-ai/SKILL.md +45 -0
  123. package/templates/skills/ides/replit/SKILL.md +46 -0
  124. package/templates/skills/ides/tabnine/SKILL.md +39 -0
  125. package/templates/skills/ides/vscode/SKILL.md +50 -0
  126. package/templates/skills/ides/windsurf/SKILL.md +46 -0
  127. package/templates/skills/ides/zed/SKILL.md +42 -0
  128. package/templates/skills/languages/ada/SKILL.md +68 -0
  129. package/templates/skills/languages/c/SKILL.md +343 -0
  130. package/templates/skills/languages/cpp/SKILL.md +753 -0
  131. package/templates/skills/languages/csharp/SKILL.md +427 -0
  132. package/templates/skills/languages/dart/SKILL.md +342 -0
  133. package/templates/skills/languages/elixir/SKILL.md +464 -0
  134. package/templates/skills/languages/erlang/SKILL.md +371 -0
  135. package/templates/skills/languages/go/SKILL.md +655 -0
  136. package/templates/skills/languages/haskell/SKILL.md +187 -0
  137. package/templates/skills/languages/java/SKILL.md +617 -0
  138. package/templates/skills/languages/javascript/SKILL.md +641 -0
  139. package/templates/skills/languages/julia/SKILL.md +107 -0
  140. package/templates/skills/languages/kotlin/SKILL.md +521 -0
  141. package/templates/skills/languages/lisp/SKILL.md +110 -0
  142. package/templates/skills/languages/lua/SKILL.md +84 -0
  143. package/templates/skills/languages/objectivec/SKILL.md +100 -0
  144. package/templates/skills/languages/php/SKILL.md +426 -0
  145. package/templates/skills/languages/python/SKILL.md +692 -0
  146. package/templates/skills/languages/r/SKILL.md +360 -0
  147. package/templates/skills/languages/ruby/SKILL.md +431 -0
  148. package/templates/skills/languages/rust/SKILL.md +487 -0
  149. package/templates/skills/languages/sas/SKILL.md +83 -0
  150. package/templates/skills/languages/scala/SKILL.md +358 -0
  151. package/templates/skills/languages/solidity/SKILL.md +590 -0
  152. package/templates/skills/languages/sql/SKILL.md +147 -0
  153. package/templates/skills/languages/swift/SKILL.md +476 -0
  154. package/templates/skills/languages/zig/SKILL.md +275 -0
  155. package/templates/skills/modules/atlassian/SKILL.md +265 -0
  156. package/templates/skills/modules/context7/SKILL.md +64 -0
  157. package/templates/skills/modules/figma/SKILL.md +277 -0
  158. package/templates/skills/modules/github-mcp/SKILL.md +74 -0
  159. package/templates/skills/modules/grafana/SKILL.md +338 -0
  160. package/templates/skills/modules/memory/SKILL.md +73 -0
  161. package/templates/skills/modules/notion/SKILL.md +257 -0
  162. package/templates/skills/modules/playwright/SKILL.md +100 -0
  163. package/templates/skills/modules/rulebook-mcp/SKILL.md +166 -0
  164. package/templates/skills/modules/serena/SKILL.md +347 -0
  165. package/templates/skills/modules/supabase/SKILL.md +233 -0
  166. package/templates/skills/modules/synap/SKILL.md +79 -0
  167. package/templates/skills/modules/vectorizer/SKILL.md +73 -0
  168. package/templates/skills/services/azure-blob/SKILL.md +194 -0
  169. package/templates/skills/services/cassandra/SKILL.md +249 -0
  170. package/templates/skills/services/dynamodb/SKILL.md +318 -0
  171. package/templates/skills/services/elasticsearch/SKILL.md +357 -0
  172. package/templates/skills/services/gcs/SKILL.md +188 -0
  173. package/templates/skills/services/influxdb/SKILL.md +275 -0
  174. package/templates/skills/services/kafka/SKILL.md +351 -0
  175. package/templates/skills/services/mariadb/SKILL.md +193 -0
  176. package/templates/skills/services/memcached/SKILL.md +252 -0
  177. package/templates/skills/services/minio/SKILL.md +211 -0
  178. package/templates/skills/services/mongodb/SKILL.md +278 -0
  179. package/templates/skills/services/mysql/SKILL.md +368 -0
  180. package/templates/skills/services/neo4j/SKILL.md +257 -0
  181. package/templates/skills/services/oracle/SKILL.md +300 -0
  182. package/templates/skills/services/postgresql/SKILL.md +336 -0
  183. package/templates/skills/services/rabbitmq/SKILL.md +296 -0
  184. package/templates/skills/services/redis/SKILL.md +302 -0
  185. package/templates/skills/services/s3/SKILL.md +308 -0
  186. package/templates/skills/services/sqlite/SKILL.md +304 -0
  187. package/templates/skills/services/sqlserver/SKILL.md +304 -0
@@ -0,0 +1,277 @@
1
+ ---
2
+ name: "Figma"
3
+ description: "Use MCP Figma for design system integration, asset export, and design-to-code workflows."
4
+ version: "1.0.0"
5
+ category: "modules"
6
+ author: "Rulebook"
7
+ tags: ["modules", "mcp"]
8
+ dependencies: []
9
+ conflicts: []
10
+ ---
11
+ <!-- FIGMA:START -->
12
+ # Figma MCP Instructions
13
+
14
+ **CRITICAL**: Use MCP Figma for design system integration, asset export, and design-to-code workflows.
15
+
16
+ ## Core Operations
17
+
18
+ ### File Operations
19
+ ```typescript
20
+ // Get file
21
+ figma.getFile({ file_key: 'file-key' })
22
+
23
+ // Get file nodes
24
+ figma.getFileNodes({
25
+ file_key: 'file-key',
26
+ ids: ['node-id-1', 'node-id-2']
27
+ })
28
+
29
+ // Get file versions
30
+ figma.getFileVersions({ file_key: 'file-key' })
31
+ ```
32
+
33
+ ### Image Export
34
+ ```typescript
35
+ // Export images
36
+ figma.getImage({
37
+ file_key: 'file-key',
38
+ ids: 'node-id',
39
+ format: 'png', // png, jpg, svg, pdf
40
+ scale: 2 // @2x resolution
41
+ })
42
+
43
+ // Export multiple
44
+ figma.getImage({
45
+ file_key: 'file-key',
46
+ ids: 'node-1,node-2,node-3',
47
+ format: 'svg',
48
+ svg_outline_text: true
49
+ })
50
+ ```
51
+
52
+ ### Components
53
+ ```typescript
54
+ // Get components
55
+ figma.getFileComponents({ file_key: 'file-key' })
56
+
57
+ // Get component sets
58
+ figma.getFileComponentSets({ file_key: 'file-key' })
59
+
60
+ // Get team components
61
+ figma.getTeamComponents({ team_id: 'team-id' })
62
+ ```
63
+
64
+ ### Styles
65
+ ```typescript
66
+ // Get file styles
67
+ figma.getFileStyles({ file_key: 'file-key' })
68
+
69
+ // Get team styles
70
+ figma.getTeamStyles({ team_id: 'team-id' })
71
+ ```
72
+
73
+ ### Comments
74
+ ```typescript
75
+ // Get comments
76
+ figma.getComments({ file_key: 'file-key' })
77
+
78
+ // Post comment
79
+ figma.postComment({
80
+ file_key: 'file-key',
81
+ message: 'Approved for development',
82
+ comment_id: 'parent-comment-id' // For replies
83
+ })
84
+ ```
85
+
86
+ ## Common Patterns
87
+
88
+ ### Design Token Export
89
+ ```typescript
90
+ // Export design tokens from Figma styles
91
+ const { data: { styles } } = await figma.getFileStyles({ file_key: fileKey })
92
+
93
+ const tokens = {
94
+ colors: {},
95
+ typography: {},
96
+ spacing: {}
97
+ }
98
+
99
+ for (const style of Object.values(styles)) {
100
+ if (style.style_type === 'FILL') {
101
+ tokens.colors[style.name] = extractColor(style)
102
+ } else if (style.style_type === 'TEXT') {
103
+ tokens.typography[style.name] = extractTextStyle(style)
104
+ }
105
+ }
106
+
107
+ // Write to tokens.json
108
+ fs.writeFileSync('tokens.json', JSON.stringify(tokens, null, 2))
109
+ ```
110
+
111
+ ### Component Sync
112
+ ```typescript
113
+ // Sync Figma components to code
114
+ const { data: components } = await figma.getFileComponents({ file_key: fileKey })
115
+
116
+ for (const component of Object.values(components)) {
117
+ // Export component as SVG
118
+ const { data: images } = await figma.getImage({
119
+ file_key: fileKey,
120
+ ids: component.node_id,
121
+ format: 'svg'
122
+ })
123
+
124
+ // Save to assets folder
125
+ const svg = await fetch(images[component.node_id]).then(r => r.text())
126
+ fs.writeFileSync(`assets/icons/${component.name}.svg`, svg)
127
+ }
128
+ ```
129
+
130
+ ### Screenshot Generation
131
+ ```typescript
132
+ // Generate screenshots for documentation
133
+ const screens = ['home-screen', 'login-screen', 'dashboard']
134
+
135
+ for (const screenId of screens) {
136
+ const { data: images } = await figma.getImage({
137
+ file_key: fileKey,
138
+ ids: screenId,
139
+ format: 'png',
140
+ scale: 2
141
+ })
142
+
143
+ const imageUrl = images[screenId]
144
+ const response = await fetch(imageUrl)
145
+ const buffer = await response.buffer()
146
+
147
+ fs.writeFileSync(`docs/screenshots/${screenId}.png`, buffer)
148
+ }
149
+ ```
150
+
151
+ ### Design Review Automation
152
+ ```typescript
153
+ // Check for new comments
154
+ const { data: comments } = await figma.getComments({ file_key: fileKey })
155
+
156
+ const unresolved = comments.filter(c => !c.resolved_at)
157
+
158
+ if (unresolved.length > 0) {
159
+ console.log(`${unresolved.length} unresolved design comments`)
160
+
161
+ // Create Jira issues for unresolved comments
162
+ for (const comment of unresolved) {
163
+ await jira.issues.createIssue({
164
+ fields: {
165
+ project: { key: 'DESIGN' },
166
+ summary: `Design feedback: ${comment.message.substring(0, 50)}`,
167
+ description: comment.message,
168
+ issuetype: { name: 'Task' }
169
+ }
170
+ })
171
+ }
172
+ }
173
+ ```
174
+
175
+ ### Design System Documentation
176
+ ```typescript
177
+ // Generate component documentation
178
+ const { data: components } = await figma.getFileComponents({ file_key: fileKey })
179
+
180
+ let markdown = '# Design System Components\n\n'
181
+
182
+ for (const [id, component] of Object.entries(components)) {
183
+ // Export thumbnail
184
+ const { data: images } = await figma.getImage({
185
+ file_key: fileKey,
186
+ ids: id,
187
+ format: 'png',
188
+ scale: 1
189
+ })
190
+
191
+ markdown += `## ${component.name}\n\n`
192
+ markdown += `![${component.name}](${images[id]})\n\n`
193
+ markdown += `**Description:** ${component.description || 'No description'}\n\n`
194
+ }
195
+
196
+ fs.writeFileSync('docs/design-system.md', markdown)
197
+ ```
198
+
199
+ ## Best Practices
200
+
201
+ ✅ **DO:**
202
+ - Cache file data to reduce API calls
203
+ - Use version history for tracking changes
204
+ - Export assets at appropriate resolutions
205
+ - Document component usage
206
+ - Use meaningful component names
207
+ - Keep design tokens in sync
208
+ - Handle rate limits (requests/minute)
209
+
210
+ ❌ **DON'T:**
211
+ - Export entire files repeatedly
212
+ - Ignore version control
213
+ - Hardcode file keys
214
+ - Skip error handling
215
+ - Export at wrong resolutions
216
+ - Commit API tokens
217
+
218
+ ## Configuration
219
+
220
+ ```json
221
+ {
222
+ "mcpServers": {
223
+ "figma": {
224
+ "command": "npx",
225
+ "args": ["-y", "@modelcontextprotocol/server-figma"],
226
+ "env": {
227
+ "FIGMA_ACCESS_TOKEN": "your-personal-access-token"
228
+ }
229
+ }
230
+ }
231
+ }
232
+ ```
233
+
234
+ **Setup:**
235
+ 1. Generate personal access token: Account Settings → Personal Access Tokens
236
+ 2. Grant appropriate scopes (file content, comments)
237
+ 3. Store token securely
238
+
239
+ ## Integration Patterns
240
+
241
+ ### CI/CD Asset Pipeline
242
+ ```bash
243
+ # Export icons on every design update
244
+ figma-export --file-key=$FIGMA_FILE --format=svg --output=src/assets/icons
245
+
246
+ # Optimize SVGs
247
+ svgo --folder src/assets/icons
248
+
249
+ # Commit if changes detected
250
+ git diff --quiet src/assets/icons || git commit -m "chore: Update design assets"
251
+ ```
252
+
253
+ ### Design-to-Code Workflow
254
+ ```typescript
255
+ // 1. Detect design changes
256
+ const currentVersion = await figma.getFile({ file_key: fileKey })
257
+ const lastVersion = loadLastProcessedVersion()
258
+
259
+ if (currentVersion.version !== lastVersion) {
260
+ // 2. Export updated components
261
+ await exportComponents(fileKey)
262
+
263
+ // 3. Generate code
264
+ await generateComponentCode()
265
+
266
+ // 4. Run tests
267
+ await runVisualRegressionTests()
268
+
269
+ // 5. Create PR if tests pass
270
+ if (testsPass) {
271
+ await createPullRequest('Update components from Figma')
272
+ }
273
+ }
274
+ ```
275
+
276
+ <!-- FIGMA:END -->
277
+
@@ -0,0 +1,74 @@
1
+ ---
2
+ name: "GitHub MCP"
3
+ description: "Monitor CI/CD workflows after every `git push` using GitHub MCP."
4
+ version: "1.0.0"
5
+ category: "modules"
6
+ author: "Rulebook"
7
+ tags: ["modules", "mcp"]
8
+ dependencies: []
9
+ conflicts: []
10
+ ---
11
+ <!-- GITHUB_MCP:START -->
12
+ # GitHub MCP Server Integration
13
+
14
+ **CRITICAL**: Monitor CI/CD workflows after every `git push` using GitHub MCP.
15
+
16
+ ## Workflow After Push
17
+
18
+ ```
19
+ 1. Push changes
20
+ 2. Wait 10 seconds
21
+ 3. Check workflow status via GitHub MCP
22
+ 4. If workflows running → check again in next interaction
23
+ 5. If workflows failed → fetch logs, analyze, fix
24
+ 6. If workflows passed → confirm to user
25
+ ```
26
+
27
+ ## Error Recovery
28
+
29
+ **When CI/CD fails:**
30
+
31
+ ```
32
+ 1. Fetch error information (workflow, job, step, logs)
33
+ 2. Analyze against AGENTS.md standards
34
+ 3. Propose fix
35
+ 4. Implement fix with full quality checks
36
+ 5. Commit and provide push command
37
+ 6. Monitor workflows again
38
+ ```
39
+
40
+ ## Best Practices
41
+
42
+ ✅ **DO:**
43
+ - Always check workflows after push
44
+ - Fetch complete error logs on failures
45
+ - Fix issues before next feature
46
+ - Verify fixes locally before re-pushing
47
+ - Report status to user
48
+
49
+ ❌ **DON'T:**
50
+ - Ignore workflow failures
51
+ - Push again without fixing
52
+ - Skip error analysis
53
+ - Proceed if workflows failing
54
+ - Create tags if CI/CD failed
55
+
56
+ ## Configuration
57
+
58
+ ```json
59
+ {
60
+ "mcpServers": {
61
+ "github": {
62
+ "command": "npx",
63
+ "args": ["-y", "@modelcontextprotocol/server-github"],
64
+ "env": {
65
+ "GITHUB_PERSONAL_ACCESS_TOKEN": "your_token_here"
66
+ }
67
+ }
68
+ }
69
+ }
70
+ ```
71
+
72
+ **Token permissions:** Repository (read), Actions (read), Workflows (read/write)
73
+
74
+ <!-- GITHUB_MCP:END -->
@@ -0,0 +1,338 @@
1
+ ---
2
+ name: "Grafana"
3
+ description: "Use MCP Grafana for metrics visualization, alerting, and observability dashboards."
4
+ version: "1.0.0"
5
+ category: "modules"
6
+ author: "Rulebook"
7
+ tags: ["modules", "mcp"]
8
+ dependencies: []
9
+ conflicts: []
10
+ ---
11
+ <!-- GRAFANA:START -->
12
+ # Grafana MCP Instructions
13
+
14
+ **CRITICAL**: Use MCP Grafana for metrics visualization, alerting, and observability dashboards.
15
+
16
+ ## Core Operations
17
+
18
+ ### Dashboard Management
19
+ ```typescript
20
+ // Get dashboard
21
+ grafana.dashboards.getDashboardByUid({ uid: 'dashboard-uid' })
22
+
23
+ // Create dashboard
24
+ grafana.dashboards.postDashboard({
25
+ dashboard: {
26
+ title: 'Application Metrics',
27
+ tags: ['production', 'api'],
28
+ timezone: 'browser',
29
+ panels: [
30
+ {
31
+ title: 'Request Rate',
32
+ type: 'graph',
33
+ targets: [{ expr: 'rate(http_requests_total[5m])' }]
34
+ }
35
+ ]
36
+ },
37
+ overwrite: false
38
+ })
39
+
40
+ // Update dashboard
41
+ grafana.dashboards.postDashboard({
42
+ dashboard: modifiedDashboard,
43
+ overwrite: true
44
+ })
45
+
46
+ // Delete dashboard
47
+ grafana.dashboards.deleteDashboardByUid({ uid: 'dashboard-uid' })
48
+ ```
49
+
50
+ ### Data Sources
51
+ ```typescript
52
+ // Get data sources
53
+ grafana.datasources.getDataSources()
54
+
55
+ // Add data source
56
+ grafana.datasources.addDataSource({
57
+ name: 'Prometheus',
58
+ type: 'prometheus',
59
+ url: 'http://prometheus:9090',
60
+ access: 'proxy',
61
+ isDefault: true
62
+ })
63
+
64
+ // Query data source
65
+ grafana.datasources.queryDataSource({
66
+ datasourceId: 1,
67
+ from: Date.now() - 3600000, // 1 hour ago
68
+ to: Date.now(),
69
+ queries: [
70
+ { expr: 'up', refId: 'A' }
71
+ ]
72
+ })
73
+ ```
74
+
75
+ ### Alerts
76
+ ```typescript
77
+ // Get alerts
78
+ grafana.alerting.getAlerts({ state: 'alerting' })
79
+
80
+ // Create alert rule
81
+ grafana.alerting.postAlertRule({
82
+ title: 'High Error Rate',
83
+ condition: 'A',
84
+ data: [
85
+ {
86
+ refId: 'A',
87
+ queryType: '',
88
+ relativeTimeRange: { from: 600, to: 0 },
89
+ datasourceUid: 'prometheus-uid',
90
+ model: {
91
+ expr: 'rate(http_errors_total[5m]) > 0.05'
92
+ }
93
+ }
94
+ ],
95
+ noDataState: 'NoData',
96
+ execErrState: 'Alerting',
97
+ for: '5m',
98
+ annotations: {
99
+ description: 'Error rate exceeded 5%'
100
+ },
101
+ labels: { severity: 'high' }
102
+ })
103
+
104
+ // Pause alert
105
+ grafana.alerting.pauseAlertRule({ uid: 'alert-uid', paused: true })
106
+ ```
107
+
108
+ ### Annotations
109
+ ```typescript
110
+ // Create annotation
111
+ grafana.annotations.postAnnotation({
112
+ dashboardUid: 'dashboard-uid',
113
+ time: Date.now(),
114
+ timeEnd: Date.now(),
115
+ tags: ['deployment'],
116
+ text: 'Deployed version 1.2.0'
117
+ })
118
+
119
+ // Get annotations
120
+ grafana.annotations.getAnnotations({
121
+ from: Date.now() - 86400000, // Last 24h
122
+ to: Date.now(),
123
+ tags: ['deployment']
124
+ })
125
+ ```
126
+
127
+ ### Organizations & Users
128
+ ```typescript
129
+ // Get organization
130
+ grafana.orgs.getOrgByName({ orgName: 'Main Org' })
131
+
132
+ // Add user
133
+ grafana.users.createUser({
134
+ email: 'user@example.com',
135
+ login: 'username',
136
+ password: 'secure-password',
137
+ name: 'User Name'
138
+ })
139
+
140
+ // Update user permissions
141
+ grafana.org.updateOrgUser({
142
+ userId: 123,
143
+ role: 'Editor' // Viewer, Editor, Admin
144
+ })
145
+ ```
146
+
147
+ ## Common Patterns
148
+
149
+ ### Deployment Tracking
150
+ ```typescript
151
+ // Mark deployment on dashboard
152
+ await grafana.annotations.postAnnotation({
153
+ time: Date.now(),
154
+ tags: ['deployment', 'production'],
155
+ text: `Deployed ${process.env.GIT_SHA}`,
156
+ dashboardUid: 'main-dashboard'
157
+ })
158
+
159
+ // Create snapshot after deployment
160
+ const snapshot = await grafana.snapshots.createDashboardSnapshot({
161
+ dashboard: dashboard,
162
+ name: `Production Metrics - ${new Date().toISOString()}`,
163
+ expires: 86400 // 24 hours
164
+ })
165
+ ```
166
+
167
+ ### Automated Dashboard Creation
168
+ ```typescript
169
+ // Create dashboard for new service
170
+ async function createServiceDashboard(serviceName) {
171
+ const dashboard = {
172
+ title: `${serviceName} Metrics`,
173
+ tags: ['microservices', serviceName],
174
+ panels: [
175
+ {
176
+ title: 'Request Rate',
177
+ type: 'graph',
178
+ targets: [{
179
+ expr: `rate(http_requests_total{service="${serviceName}"}[5m])`
180
+ }]
181
+ },
182
+ {
183
+ title: 'Error Rate',
184
+ type: 'graph',
185
+ targets: [{
186
+ expr: `rate(http_errors_total{service="${serviceName}"}[5m])`
187
+ }]
188
+ },
189
+ {
190
+ title: 'Response Time (p95)',
191
+ type: 'graph',
192
+ targets: [{
193
+ expr: `histogram_quantile(0.95, rate(http_duration_seconds_bucket{service="${serviceName}"}[5m]))`
194
+ }]
195
+ }
196
+ ]
197
+ }
198
+
199
+ return await grafana.dashboards.postDashboard({
200
+ dashboard,
201
+ overwrite: false
202
+ })
203
+ }
204
+ ```
205
+
206
+ ### Alert Management
207
+ ```typescript
208
+ // Check for firing alerts
209
+ const alerts = await grafana.alerting.getAlerts({ state: 'alerting' })
210
+
211
+ if (alerts.length > 0) {
212
+ console.log(`${alerts.length} alerts firing:`)
213
+
214
+ for (const alert of alerts) {
215
+ console.log(`- ${alert.labels.alertname}: ${alert.annotations.description}`)
216
+
217
+ // Create incident ticket
218
+ await jira.issues.createIssue({
219
+ fields: {
220
+ project: { key: 'OPS' },
221
+ summary: `Alert: ${alert.labels.alertname}`,
222
+ description: alert.annotations.description,
223
+ issuetype: { name: 'Incident' },
224
+ priority: { name: alert.labels.severity === 'critical' ? 'Highest' : 'High' }
225
+ }
226
+ })
227
+ }
228
+ }
229
+ ```
230
+
231
+ ### Metrics Reporting
232
+ ```typescript
233
+ // Generate daily metrics report
234
+ async function generateDailyReport() {
235
+ const datasourceId = 1 // Prometheus
236
+ const from = Date.now() - 86400000 // 24h ago
237
+ const to = Date.now()
238
+
239
+ // Query metrics
240
+ const requestRate = await grafana.datasources.queryDataSource({
241
+ datasourceId,
242
+ from,
243
+ to,
244
+ queries: [{ expr: 'sum(rate(http_requests_total[24h]))', refId: 'A' }]
245
+ })
246
+
247
+ const errorRate = await grafana.datasources.queryDataSource({
248
+ datasourceId,
249
+ from,
250
+ to,
251
+ queries: [{ expr: 'sum(rate(http_errors_total[24h]))', refId: 'A' }]
252
+ })
253
+
254
+ // Create report
255
+ const report = {
256
+ date: new Date().toISOString(),
257
+ totalRequests: requestRate.results.A.frames[0].data.values[1][0],
258
+ totalErrors: errorRate.results.A.frames[0].data.values[1][0],
259
+ errorPercentage: (totalErrors / totalRequests * 100).toFixed(2)
260
+ }
261
+
262
+ // Post to Confluence/Notion
263
+ await notion.pages.create({
264
+ parent: { database_id: reportsDbId },
265
+ properties: {
266
+ 'Title': { title: [{ text: { content: `Daily Metrics - ${report.date}` } }] },
267
+ 'Requests': { number: report.totalRequests },
268
+ 'Errors': { number: report.totalErrors },
269
+ 'Error Rate': { number: parseFloat(report.errorPercentage) }
270
+ }
271
+ })
272
+ }
273
+ ```
274
+
275
+ ## Best Practices
276
+
277
+ ✅ **DO:**
278
+ - Use dashboard folders for organization
279
+ - Tag dashboards appropriately
280
+ - Set up proper alert thresholds
281
+ - Use variables for flexibility
282
+ - Create snapshots before changes
283
+ - Document dashboard purpose
284
+ - Use templating for multi-instance dashboards
285
+
286
+ ❌ **DON'T:**
287
+ - Create duplicate dashboards
288
+ - Set alerts without testing
289
+ - Ignore alert fatigue
290
+ - Hardcode dashboard IDs
291
+ - Skip dashboard backups
292
+ - Over-complicate queries
293
+
294
+ ## Configuration
295
+
296
+ ```json
297
+ {
298
+ "mcpServers": {
299
+ "grafana": {
300
+ "command": "npx",
301
+ "args": ["-y", "@modelcontextprotocol/server-grafana"],
302
+ "env": {
303
+ "GRAFANA_URL": "http://grafana:3000",
304
+ "GRAFANA_API_KEY": "your-api-key",
305
+ "GRAFANA_ORG_ID": "1"
306
+ }
307
+ }
308
+ }
309
+ }
310
+ ```
311
+
312
+ **Setup:**
313
+ 1. Create API key: Configuration → API Keys → Add API key
314
+ 2. Grant appropriate permissions (Admin for management, Viewer for read-only)
315
+ 3. Store securely
316
+
317
+ ## Integration with CI/CD
318
+
319
+ ```typescript
320
+ // Add deployment annotation on successful deploy
321
+ if (deploymentSuccess) {
322
+ await grafana.annotations.postAnnotation({
323
+ time: Date.now(),
324
+ tags: ['deployment', process.env.ENVIRONMENT],
325
+ text: `Deployed ${process.env.GIT_SHA} to ${process.env.ENVIRONMENT}`,
326
+ dashboardUid: process.env.GRAFANA_DASHBOARD_UID
327
+ })
328
+ }
329
+
330
+ // Check alerts before deployment
331
+ const alerts = await grafana.alerting.getAlerts({ state: 'alerting' })
332
+ if (alerts.length > 0) {
333
+ console.warn('⚠️ Active alerts detected. Deployment may be risky.')
334
+ }
335
+ ```
336
+
337
+ <!-- GRAFANA:END -->
338
+