@grafana/viz-contract 1.1.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 (173) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/LICENSE +201 -0
  3. package/README.md +140 -0
  4. package/fixtures/epoch-range/args.json +14 -0
  5. package/fixtures/epoch-range/meta.json +4 -0
  6. package/fixtures/epoch-range/request.json +17 -0
  7. package/fixtures/epoch-range/response.json +114 -0
  8. package/fixtures/epoch-range/result.json +252 -0
  9. package/fixtures/epoch-range/spec.json +141 -0
  10. package/fixtures/epoch-range/state.json +4 -0
  11. package/fixtures/error-all-queries-failed/spec.json +45 -0
  12. package/fixtures/error-all-queries-failed/state.json +8 -0
  13. package/fixtures/error-invalid-spec/spec.json +25 -0
  14. package/fixtures/error-invalid-spec/state.json +8 -0
  15. package/fixtures/error-unsupported-panel-type/spec.json +1372 -0
  16. package/fixtures/error-unsupported-panel-type/state.json +8 -0
  17. package/fixtures/error-unsupported-spec-version/spec.json +1372 -0
  18. package/fixtures/error-unsupported-spec-version/state.json +8 -0
  19. package/fixtures/hostile-label/args.json +14 -0
  20. package/fixtures/hostile-label/meta.json +4 -0
  21. package/fixtures/hostile-label/request.json +17 -0
  22. package/fixtures/hostile-label/response.json +420 -0
  23. package/fixtures/hostile-label/result.json +558 -0
  24. package/fixtures/hostile-label/spec.json +447 -0
  25. package/fixtures/hostile-label/state.json +4 -0
  26. package/fixtures/no-data/args.json +14 -0
  27. package/fixtures/no-data/meta.json +4 -0
  28. package/fixtures/no-data/request.json +17 -0
  29. package/fixtures/no-data/response.json +40 -0
  30. package/fixtures/no-data/result.json +178 -0
  31. package/fixtures/no-data/spec.json +67 -0
  32. package/fixtures/no-data/state.json +4 -0
  33. package/fixtures/partial-error/args.json +20 -0
  34. package/fixtures/partial-error/meta.json +4 -0
  35. package/fixtures/partial-error/request.json +28 -0
  36. package/fixtures/partial-error/response.json +220 -0
  37. package/fixtures/partial-error/result.json +358 -0
  38. package/fixtures/partial-error/spec.json +253 -0
  39. package/fixtures/partial-error/state.json +9 -0
  40. package/fixtures/pick-annotations-only/args.json +10 -0
  41. package/fixtures/pick-annotations-only/meta.json +4 -0
  42. package/fixtures/pick-annotations-only/response.json +41 -0
  43. package/fixtures/pick-annotations-only/result.json +53 -0
  44. package/fixtures/pick-categories/args.json +10 -0
  45. package/fixtures/pick-categories/meta.json +4 -0
  46. package/fixtures/pick-categories/response.json +58 -0
  47. package/fixtures/pick-categories/result.json +116 -0
  48. package/fixtures/pick-empty-result/args.json +10 -0
  49. package/fixtures/pick-empty-result/meta.json +4 -0
  50. package/fixtures/pick-empty-result/response.json +11 -0
  51. package/fixtures/pick-empty-result/result.json +23 -0
  52. package/fixtures/pick-failed-query-with-frames/args.json +10 -0
  53. package/fixtures/pick-failed-query-with-frames/meta.json +4 -0
  54. package/fixtures/pick-failed-query-with-frames/response.json +43 -0
  55. package/fixtures/pick-failed-query-with-frames/result.json +131 -0
  56. package/fixtures/pick-few-parts/args.json +10 -0
  57. package/fixtures/pick-few-parts/meta.json +4 -0
  58. package/fixtures/pick-few-parts/response.json +40 -0
  59. package/fixtures/pick-few-parts/result.json +98 -0
  60. package/fixtures/pick-heatmap-cells/args.json +10 -0
  61. package/fixtures/pick-heatmap-cells/meta.json +4 -0
  62. package/fixtures/pick-heatmap-cells/response.json +55 -0
  63. package/fixtures/pick-heatmap-cells/result.json +143 -0
  64. package/fixtures/pick-log-lines/args.json +10 -0
  65. package/fixtures/pick-log-lines/meta.json +4 -0
  66. package/fixtures/pick-log-lines/response.json +49 -0
  67. package/fixtures/pick-log-lines/result.json +76 -0
  68. package/fixtures/pick-no-rows/args.json +10 -0
  69. package/fixtures/pick-no-rows/meta.json +4 -0
  70. package/fixtures/pick-no-rows/response.json +32 -0
  71. package/fixtures/pick-no-rows/result.json +120 -0
  72. package/fixtures/pick-node-graph/args.json +10 -0
  73. package/fixtures/pick-node-graph/meta.json +4 -0
  74. package/fixtures/pick-node-graph/response.json +77 -0
  75. package/fixtures/pick-node-graph/result.json +89 -0
  76. package/fixtures/pick-numeric-only/args.json +10 -0
  77. package/fixtures/pick-numeric-only/meta.json +4 -0
  78. package/fixtures/pick-numeric-only/response.json +40 -0
  79. package/fixtures/pick-numeric-only/result.json +89 -0
  80. package/fixtures/pick-single-stat/args.json +10 -0
  81. package/fixtures/pick-single-stat/meta.json +4 -0
  82. package/fixtures/pick-single-stat/response.json +29 -0
  83. package/fixtures/pick-single-stat/result.json +69 -0
  84. package/fixtures/pick-time-series-instant/args.json +10 -0
  85. package/fixtures/pick-time-series-instant/meta.json +4 -0
  86. package/fixtures/pick-time-series-instant/response.json +40 -0
  87. package/fixtures/pick-time-series-instant/result.json +128 -0
  88. package/fixtures/pick-time-series-long/args.json +10 -0
  89. package/fixtures/pick-time-series-long/meta.json +4 -0
  90. package/fixtures/pick-time-series-long/response.json +61 -0
  91. package/fixtures/pick-time-series-long/result.json +167 -0
  92. package/fixtures/pick-time-series-multi-frame/args.json +10 -0
  93. package/fixtures/pick-time-series-multi-frame/meta.json +4 -0
  94. package/fixtures/pick-time-series-multi-frame/response.json +74 -0
  95. package/fixtures/pick-time-series-multi-frame/result.json +162 -0
  96. package/fixtures/pick-time-series-null-time/args.json +10 -0
  97. package/fixtures/pick-time-series-null-time/meta.json +4 -0
  98. package/fixtures/pick-time-series-null-time/response.json +40 -0
  99. package/fixtures/pick-time-series-null-time/result.json +128 -0
  100. package/fixtures/pick-time-series-single/args.json +10 -0
  101. package/fixtures/pick-time-series-single/meta.json +4 -0
  102. package/fixtures/pick-time-series-single/response.json +40 -0
  103. package/fixtures/pick-time-series-single/result.json +128 -0
  104. package/fixtures/pick-time-series-wide/args.json +10 -0
  105. package/fixtures/pick-time-series-wide/meta.json +4 -0
  106. package/fixtures/pick-time-series-wide/response.json +61 -0
  107. package/fixtures/pick-time-series-wide/result.json +149 -0
  108. package/fixtures/prometheus-line/args.json +14 -0
  109. package/fixtures/prometheus-line/meta.json +4 -0
  110. package/fixtures/prometheus-line/request.json +17 -0
  111. package/fixtures/prometheus-line/response.json +1344 -0
  112. package/fixtures/prometheus-line/result.json +1483 -0
  113. package/fixtures/prometheus-line/spec.json +1372 -0
  114. package/fixtures/prometheus-line/state.json +4 -0
  115. package/fixtures/smoke-barchart/spec.json +64 -0
  116. package/fixtures/smoke-barchart/state.json +4 -0
  117. package/fixtures/smoke-boxplot/spec.json +96 -0
  118. package/fixtures/smoke-boxplot/state.json +4 -0
  119. package/fixtures/smoke-bubble/spec.json +229 -0
  120. package/fixtures/smoke-bubble/state.json +4 -0
  121. package/fixtures/smoke-candlestick/spec.json +97 -0
  122. package/fixtures/smoke-candlestick/state.json +4 -0
  123. package/fixtures/smoke-chord/spec.json +72 -0
  124. package/fixtures/smoke-chord/state.json +4 -0
  125. package/fixtures/smoke-funnel/spec.json +62 -0
  126. package/fixtures/smoke-funnel/state.json +4 -0
  127. package/fixtures/smoke-geomap/spec.json +76 -0
  128. package/fixtures/smoke-geomap/state.json +4 -0
  129. package/fixtures/smoke-heatmap/spec.json +103 -0
  130. package/fixtures/smoke-heatmap/state.json +4 -0
  131. package/fixtures/smoke-histogram/spec.json +63 -0
  132. package/fixtures/smoke-histogram/state.json +4 -0
  133. package/fixtures/smoke-nodeGraph/spec.json +101 -0
  134. package/fixtures/smoke-nodeGraph/state.json +4 -0
  135. package/fixtures/smoke-parallel/spec.json +78 -0
  136. package/fixtures/smoke-parallel/state.json +4 -0
  137. package/fixtures/smoke-piechart/spec.json +62 -0
  138. package/fixtures/smoke-piechart/state.json +4 -0
  139. package/fixtures/smoke-radar/spec.json +82 -0
  140. package/fixtures/smoke-radar/state.json +4 -0
  141. package/fixtures/smoke-sankey/spec.json +72 -0
  142. package/fixtures/smoke-sankey/state.json +4 -0
  143. package/fixtures/smoke-state-timeline/spec.json +64 -0
  144. package/fixtures/smoke-state-timeline/state.json +4 -0
  145. package/fixtures/smoke-status-history/spec.json +64 -0
  146. package/fixtures/smoke-status-history/state.json +4 -0
  147. package/fixtures/smoke-streamgraph/spec.json +229 -0
  148. package/fixtures/smoke-streamgraph/state.json +4 -0
  149. package/fixtures/smoke-sunburst/spec.json +72 -0
  150. package/fixtures/smoke-sunburst/state.json +4 -0
  151. package/fixtures/smoke-timeseries/spec.json +163 -0
  152. package/fixtures/smoke-timeseries/state.json +4 -0
  153. package/fixtures/smoke-treemap/spec.json +72 -0
  154. package/fixtures/smoke-treemap/state.json +4 -0
  155. package/fixtures/too-large/args.json +14 -0
  156. package/fixtures/too-large/meta.json +4 -0
  157. package/fixtures/type-mismatch/args.json +15 -0
  158. package/fixtures/type-mismatch/meta.json +4 -0
  159. package/fixtures/type-mismatch/request.json +17 -0
  160. package/fixtures/type-mismatch/response.json +1344 -0
  161. package/fixtures/type-mismatch/result.json +9 -0
  162. package/package.json +32 -0
  163. package/registry/chart-types.json +170 -0
  164. package/registry/constants.json +14 -0
  165. package/registry/notices.json +40 -0
  166. package/registry/panel-types.json +14 -0
  167. package/registry/pick.json +46 -0
  168. package/registry/states.json +85 -0
  169. package/renderer-api.d.ts +70 -0
  170. package/schemas/bundled/query-datasource-args.schema.json +86 -0
  171. package/schemas/bundled/registry.schema.json +375 -0
  172. package/schemas/bundled/tool-result.schema.json +245 -0
  173. package/schemas/bundled/viz-spec.schema.json +261 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,17 @@
1
+ # Changelog
2
+
3
+ Each version of the contract has one entry. [8-versioning.md](8-versioning.md) gives the version rules. An entry
4
+ marked `internal` changes only an interface with the internal or the provisional promise.
5
+
6
+ ## 1.1.0
7
+
8
+ `internal`
9
+
10
+ - `render_grafana_app` adds the notes of the Source after its text line (`tool.28`, `tool.30`). New constants
11
+ `maxAppNotes` and `maxAppNoteChars`. `tool.26` is removed.
12
+ - The Source gives one note for each entry of `data.results` that has an `error` (`tool.29`).
13
+ - `future.md` loses item 1, failures in the text result.
14
+
15
+ ## 1.0.0
16
+
17
+ - First version.
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Grafana Labs
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,140 @@
1
+ # Grafana visualization contract
2
+
3
+ A model in an MCP client asks Grafana for a chart. The `query_datasource` source of the `render_grafana_app` tool
4
+ in `grafana/mcp-grafana` runs the query. The App, an MCP Apps view, gets the result. The Renderer draws the chart.
5
+
6
+ This contract gives the shapes and the rules that pass between these parts. A part that follows the contract
7
+ works with the other parts. Its engineers do not have to ask the engineers of the other parts.
8
+
9
+ ## Parts
10
+
11
+ ```mermaid
12
+ flowchart TB
13
+ subgraph Host["Host"]
14
+ Model["Model"]
15
+ subgraph App["App: ui://grafana/app.html"]
16
+ Renderer["Renderer"]
17
+ end
18
+ end
19
+ subgraph Server["mcp-grafana"]
20
+ Source["Source: query_datasource"]
21
+ end
22
+ Grafana["Grafana: /api/ds/query"]
23
+
24
+ Model -- "1. render_grafana_app" --> Source
25
+ Source -- "2. query" --> Grafana
26
+ Source -- "3. tool result" --> App
27
+ App -- "4. viz spec" --> Renderer
28
+ Renderer -- "5. state, notices, onRefresh" --> App
29
+ App -- "6. model context" --> Model
30
+ App -- "7. render_grafana_app again" --> Source
31
+ ```
32
+
33
+ | Interface | From | To | Files |
34
+ | --------- | ---- | -- | ----- |
35
+ | Tool arguments | Model | Source | [1-tool.md](1-tool.md), `schemas/query-datasource-args.schema.json` |
36
+ | Tool result | Source | App | [1-tool.md](1-tool.md), `schemas/tool-result.schema.json` |
37
+ | Viz spec | App | Renderer | [2-viz-spec.md](2-viz-spec.md), `schemas/viz-spec.schema.json` |
38
+ | Renderer API | App | Renderer | [3-renderer.md](3-renderer.md), `renderer-api.d.ts` |
39
+ | States, notices and model context | Renderer, App | App, Model | [4-states-and-notices.md](4-states-and-notices.md) |
40
+ | Refresh | Renderer, App | App, Source | [5-refresh.md](5-refresh.md) |
41
+
42
+ ## Terms
43
+
44
+ | Term | Meaning |
45
+ | ---- | ------- |
46
+ | Host | The MCP client that shows the App, for example Claude web and Desktop, Cursor and ChatGPT |
47
+ | Source | The Go code in mcp-grafana that runs the query (`query_datasource` in `render_grafana_app`) |
48
+ | App | The view in `ui://grafana/app.html` of mcp-grafana that gets the tool result and calls the Renderer |
49
+ | Renderer | The browser bundle that draws a viz spec |
50
+ | Viz spec | The JSON object that the App gives to the Renderer |
51
+ | Note | A text line that the Source gives to `render_grafana_app`, and that the model reads in the same turn (`tool.28`). Not a notice: the Renderer shows a notice in the chart (`state.7`) |
52
+
53
+ The Renderer draws the panels of the package `@plugins/grafana-echarts`.
54
+
55
+ ## How to read
56
+
57
+ 1. Files 1 to 5 give the interfaces in build order. Files 6 to 8 apply to all of them.
58
+ 2. Read the files of your part only:
59
+
60
+ | Part | Files |
61
+ | ---- | ----- |
62
+ | Source | 1, 6, 8, the schemas of the tool arguments and the tool result, and `registry/` |
63
+ | App | 1 to 8, and the registries of states, notices and constants |
64
+ | Renderer | 2 to 8, `renderer-api.d.ts`, and the registries of panel types, states, notices and constants |
65
+
66
+ 3. The schemas give the shapes. The prose gives the behavior only, and does not repeat a schema.
67
+ `schemas/bundled/` holds each schema as one file with no reference to another file. Consumers use the bundled
68
+ files.
69
+ 4. Each rule has a stable ID: a file prefix, a dot and a number, for example `refresh.3`. A test names the ID of
70
+ the rule that it checks. An ID never gets a new meaning. The ID of a removed rule is not used again.
71
+ 5. "Must" is a requirement. "Can" is a permission.
72
+ 6. The prose names a fixed value by its constant, for example `maxResultBytes`. The value is in
73
+ `registry/constants.json` and in the table below.
74
+
75
+ ## Use the package
76
+
77
+ The npm package `@grafana/viz-contract` holds the bundled schemas, the registries, the fixtures and the types of
78
+ the Renderer API. Each package version is a contract version.
79
+
80
+ ```sh
81
+ npm install --save-dev @grafana/viz-contract
82
+ ```
83
+
84
+ ```ts
85
+ import panelTypes from '@grafana/viz-contract/registry/panel-types.json' with { type: 'json' };
86
+ import vizSpecSchema from '@grafana/viz-contract/schemas/viz-spec.schema.json' with { type: 'json' };
87
+ import type { RenderOptions } from '@grafana/viz-contract/renderer-api';
88
+ ```
89
+
90
+ `renderer-api` has types only. Import it with `import type`. The functions that it declares come from the Renderer.
91
+
92
+ A test that reads all fixtures finds the folder like this:
93
+
94
+ ```ts
95
+ import { createRequire } from 'node:module';
96
+ import path from 'node:path';
97
+
98
+ const pkg = createRequire(import.meta.url).resolve('@grafana/viz-contract/package.json');
99
+ const fixturesDir = path.join(path.dirname(pkg), 'fixtures');
100
+ ```
101
+
102
+ ## Promises
103
+
104
+ The interfaces do not have the same promise of stability. [8-versioning.md](8-versioning.md) gives the three
105
+ promises and the promise of each interface.
106
+
107
+ The tool result, the viz spec and the Renderer API have the internal promise. They can change in any minor
108
+ version, with no deprecation period. If you build on them outside mcp-grafana and the Renderer, pin a tagged
109
+ version.
110
+
111
+ ## Constants
112
+
113
+ <!-- constants:start. A script makes this table from registry/constants.json. Do not edit it. -->
114
+ | Name | Value | Unit | Changeable | Meaning |
115
+ | ---- | ----- | ---- | ---------- | ------- |
116
+ | `maxResultBytes` | 1048576 | bytes | yes | Largest structuredContent of the tool result |
117
+ | `refreshTimeoutMs` | 60000 | ms | no | Time before a refresh with no result fails |
118
+ | `defaultHeightPx` | 400 | px | no | Chart height when the element height is 0 |
119
+ | `defaultFrom` | now-1h | time | no | from when the tool arguments have none |
120
+ | `defaultTo` | now | time | no | to when the tool arguments have none |
121
+ | `defaultMaxDataPoints` | 1000 | points | no | maxDataPoints of a query that has none. intervalMs is the range divided by it |
122
+ | `maxSeries` | 50 | series | yes | Most series that the Renderer draws |
123
+ | `maxBundleGzipBytes` | not set | bytes | yes | Largest gzip size of the Renderer bundle. Not set until the host size research is done |
124
+ | `maxAppNotes` | 5 | notes | yes | Most notes of the Source that render_grafana_app adds to its text line |
125
+ | `maxAppNoteChars` | 200 | characters | yes | Longest note in the text line of render_grafana_app |
126
+ | `deprecationDays` | 30 | days | yes | Shortest deprecation period of a change to a frozen interface |
127
+ | `specVersion` | 1 | version | no | The viz spec version that this contract gives |
128
+ <!-- constants:end -->
129
+
130
+ ## Not in this contract
131
+
132
+ 1. Behavior inside one part. For example, zoom, pan and the Reset button are Renderer UI.
133
+ 2. Size changes and display modes between the App and the Host. The
134
+ [MCP Apps specification](https://github.com/modelcontextprotocol/ext-apps) gives them.
135
+ 3. Items that are not specified yet. [future.md](future.md) lists them in priority order.
136
+
137
+ ## Changes
138
+
139
+ [CHANGELOG.md](CHANGELOG.md) lists the versions. [CONTRIBUTING.md](CONTRIBUTING.md) gives the steps to change the
140
+ contract.
@@ -0,0 +1,14 @@
1
+ {
2
+ "datasourceUid": "lgtm-prometheus",
3
+ "queries": [
4
+ {
5
+ "refId": "A",
6
+ "expr": "sum by (handler) (rate(grafana_http_request_duration_seconds_count[5m]))",
7
+ "legendFormat": "{{handler}}",
8
+ "format": "time_series"
9
+ }
10
+ ],
11
+ "from": 1790349877294,
12
+ "to": 1790353477294,
13
+ "unit": "reqps"
14
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "now": 1790353477294,
3
+ "capturedAt": 1790353477806
4
+ }
@@ -0,0 +1,17 @@
1
+ {
2
+ "from": "1790349877294",
3
+ "to": "1790353477294",
4
+ "queries": [
5
+ {
6
+ "refId": "A",
7
+ "expr": "sum by (handler) (rate(grafana_http_request_duration_seconds_count[5m]))",
8
+ "legendFormat": "{{handler}}",
9
+ "format": "time_series",
10
+ "datasource": {
11
+ "uid": "lgtm-prometheus"
12
+ },
13
+ "maxDataPoints": 1000,
14
+ "intervalMs": 3600
15
+ }
16
+ ]
17
+ }
@@ -0,0 +1,114 @@
1
+ {
2
+ "status": 200,
3
+ "body": {
4
+ "results": {
5
+ "A": {
6
+ "status": 200,
7
+ "frames": [
8
+ {
9
+ "schema": {
10
+ "refId": "A",
11
+ "meta": {
12
+ "type": "timeseries-multi",
13
+ "typeVersion": [
14
+ 0,
15
+ 1
16
+ ]
17
+ },
18
+ "fields": [
19
+ {
20
+ "name": "Time",
21
+ "type": "time",
22
+ "typeInfo": {
23
+ "frame": "time.Time"
24
+ }
25
+ },
26
+ {
27
+ "name": "Value",
28
+ "type": "number",
29
+ "typeInfo": {
30
+ "frame": "float64"
31
+ },
32
+ "labels": {
33
+ "handler": "/api/ds/query"
34
+ },
35
+ "config": {
36
+ "displayNameFromDS": "/api/ds/query"
37
+ }
38
+ }
39
+ ]
40
+ },
41
+ "data": {
42
+ "values": [
43
+ [
44
+ 1790351737294,
45
+ 1790351797294,
46
+ 1790351857294,
47
+ 1790351917294,
48
+ 1790351977294,
49
+ 1790352037294,
50
+ 1790352097294,
51
+ 1790352157294,
52
+ 1790352217294,
53
+ 1790352277294,
54
+ 1790352337294,
55
+ 1790352397294,
56
+ 1790352457294,
57
+ 1790352517294,
58
+ 1790352577294,
59
+ 1790352637294,
60
+ 1790352697294,
61
+ 1790352757294,
62
+ 1790352817294,
63
+ 1790352877294,
64
+ 1790352937294,
65
+ 1790352997294,
66
+ 1790353057294,
67
+ 1790353117294,
68
+ 1790353177294,
69
+ 1790353237294,
70
+ 1790353297294,
71
+ 1790353357294,
72
+ 1790353417294,
73
+ 1790353477294
74
+ ],
75
+ [
76
+ 12,
77
+ 12.65,
78
+ 13.24,
79
+ 13.68,
80
+ 13.94,
81
+ 13.99,
82
+ 13.82,
83
+ 13.45,
84
+ 12.91,
85
+ 12.28,
86
+ 11.62,
87
+ 11,
88
+ 10.49,
89
+ 10.14,
90
+ 10,
91
+ 10.08,
92
+ 10.37,
93
+ 10.84,
94
+ 11.44,
95
+ 12.1,
96
+ 12.75,
97
+ 13.31,
98
+ 13.73,
99
+ 13.97,
100
+ 13.98,
101
+ 13.77,
102
+ 13.38,
103
+ 12.82,
104
+ 12.18,
105
+ 11.52
106
+ ]
107
+ ]
108
+ }
109
+ }
110
+ ]
111
+ }
112
+ }
113
+ }
114
+ }