iflow-mcp_drdroidlab-grafana-mcp-server 0.1.0__py3-none-any.whl

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.
File without changes
@@ -0,0 +1,36 @@
1
+ import json
2
+ import sys
3
+ from time import sleep
4
+
5
+
6
+ def run_stdio_server(handler):
7
+ """
8
+ Reads JSON-RPC requests from stdin, calls the handler, and writes responses to stdout.
9
+ The handler should be a function that takes a dict and returns a dict (the response).
10
+ """
11
+ while True:
12
+ line = sys.stdin.readline()
13
+ if not line:
14
+ print("No line read", file=sys.stderr)
15
+ sleep(1)
16
+ continue
17
+ line = line.strip()
18
+ if not line:
19
+ continue
20
+ try:
21
+ data = json.loads(line)
22
+ response = handler(data)
23
+ sys.stdout.write(json.dumps(response) + "\n")
24
+ sys.stdout.flush()
25
+ except Exception as e:
26
+ sys.stdout.write(
27
+ json.dumps(
28
+ {
29
+ "jsonrpc": "2.0",
30
+ "error": {"code": -32000, "message": str(e)},
31
+ "id": None,
32
+ }
33
+ )
34
+ + "\n"
35
+ )
36
+ sys.stdout.flush()
@@ -0,0 +1,290 @@
1
+ Metadata-Version: 2.4
2
+ Name: iflow-mcp_drdroidlab-grafana-mcp-server
3
+ Version: 0.1.0
4
+ Summary: MCP Server for Grafana API integration - enables AI assistants to query Grafana dashboards, datasources, and metrics
5
+ Project-URL: Homepage, https://github.com/yourusername/grafana-mcp-server
6
+ Project-URL: Documentation, https://github.com/yourusername/grafana-mcp-server#readme
7
+ Project-URL: Repository, https://github.com/yourusername/grafana-mcp-server
8
+ Project-URL: Issues, https://github.com/yourusername/grafana-mcp-server/issues
9
+ Author-email: Your Name <your.email@example.com>
10
+ License: MIT License
11
+
12
+ Copyright (c) 2025 Doctor Droid
13
+
14
+ Permission is hereby granted, free of charge, to any person obtaining a copy
15
+ of this software and associated documentation files (the "Software"), to deal
16
+ in the Software without restriction, including without limitation the rights
17
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18
+ copies of the Software, and to permit persons to whom the Software is
19
+ furnished to do so, subject to the following conditions:
20
+
21
+ The above copyright notice and this permission notice shall be included in all
22
+ copies or substantial portions of the Software.
23
+
24
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30
+ SOFTWARE.
31
+ License-File: LICENSE
32
+ Keywords: ai,claude,cursor,grafana,mcp,monitoring,observability
33
+ Classifier: Development Status :: 3 - Alpha
34
+ Classifier: Intended Audience :: Developers
35
+ Classifier: Intended Audience :: System Administrators
36
+ Classifier: License :: OSI Approved :: MIT License
37
+ Classifier: Programming Language :: Python :: 3
38
+ Classifier: Programming Language :: Python :: 3.11
39
+ Classifier: Programming Language :: Python :: 3.12
40
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
41
+ Classifier: Topic :: System :: Monitoring
42
+ Requires-Python: >=3.11
43
+ Requires-Dist: flaky
44
+ Requires-Dist: flask==3.0.0
45
+ Requires-Dist: pytest>=8.4.1
46
+ Requires-Dist: python-dateutil>=2.9.0.post0
47
+ Requires-Dist: pyyaml>=6.0.1
48
+ Requires-Dist: requests>=2.31.0
49
+ Requires-Dist: ruff>=0.12.3
50
+ Requires-Dist: typing-extensions
51
+ Provides-Extra: dev
52
+ Requires-Dist: black; extra == 'dev'
53
+ Requires-Dist: pytest-cov; extra == 'dev'
54
+ Requires-Dist: pytest-xdist; extra == 'dev'
55
+ Provides-Extra: prod
56
+ Requires-Dist: gunicorn; extra == 'prod'
57
+ Description-Content-Type: text/markdown
58
+
59
+ # Grafana MCP Server
60
+
61
+ ## Available Tools
62
+
63
+ The following tools are available via the MCP server:
64
+
65
+ - **test_connection**: Verify connectivity to your Grafana instance and configuration.
66
+ - **grafana_promql_query**: Execute PromQL queries against Grafana's Prometheus datasource. Fetches metrics data using PromQL expressions, optimizes time series responses to reduce token size.
67
+ - **grafana_loki_query**: Query Grafana Loki for log data. Fetches logs for a specified duration (e.g., '5m', '1h', '2d'), converts relative time to absolute timestamps.
68
+ - **grafana_get_dashboard_config**: Retrieves dashboard configuration details from the database. Queries the connectors_connectormetadatamodelstore table for dashboard metadata.
69
+ - **grafana_query_dashboard_panels**: Execute queries for specific dashboard panels. Can query up to 4 panels at once, supports template variables, optimizes metrics data.
70
+ - **grafana_fetch_label_values**: Fetch label values for dashboard variables from Prometheus datasource. Retrieves available values for specific labels (e.g., 'instance', 'job'). Supports optional metric filtering.
71
+ - **grafana_fetch_dashboard_variables**: Fetch all variables and their values from a Grafana dashboard. Retrieves dashboard template variables and their current values.
72
+ - **grafana_fetch_all_dashboards**: Fetch all dashboards from Grafana with basic information like title, UID, folder, tags, etc.
73
+ - **grafana_fetch_datasources**: Fetch all datasources from Grafana with their configuration details.
74
+ - **grafana_fetch_folders**: Fetch all folders from Grafana with their metadata and permissions.
75
+
76
+ ## 🚀 Usage & Requirements
77
+
78
+ ### 1. Get Your Grafana API Endpoint & Service Account Token
79
+
80
+ 1. Ensure you have a running Grafana instance (self-hosted or cloud).
81
+ 2. Generate a Service Account Token from your Grafana UI:
82
+ - Create Service Account: In your Grafana dashboard, navigate to Admin >> Users & Access >> Service Accounts >> Create a Service Account with Viewer permissions
83
+ - Generate Service Account Key: Within Service Account, create a new Service Account token.
84
+ - Copy the service account token (starts with `glsa_`)
85
+
86
+ ---
87
+
88
+ ## 2. Installation & Running Options
89
+
90
+ ### 2A. Install & Run with uv (Recommended for Local Development)
91
+
92
+ #### 2A.1. Install dependencies with uv
93
+
94
+ ```bash
95
+ uv venv .venv
96
+ source .venv/bin/activate
97
+ uv sync
98
+ ```
99
+
100
+ #### 2A.2. Run the server with uv
101
+
102
+ ```bash
103
+ uv run -m src.grafana_mcp_server.mcp_server
104
+ ```
105
+
106
+ - You can also use `uv` to run any other entrypoint scripts as needed.
107
+ - Make sure your `config.yaml` is in the same directory as `mcp_server.py` or set the required environment variables (see Configuration section).
108
+
109
+ ---
110
+
111
+ ### 2B. Run with Docker Compose (Recommended for Production/Containerized Environments)
112
+
113
+ 1. Edit `grafana-mcp-server/src/grafana_mcp_server/config.yaml` with your Grafana details (host, API key).
114
+ 2. Start the server:
115
+ ```bash
116
+ docker compose up -d
117
+ ```
118
+ - The server will run in HTTP (SSE) mode on port 8000 by default.
119
+ - You can override configuration with environment variables (see below).
120
+
121
+ ---
122
+
123
+ ## 3. Configuration
124
+
125
+ The server loads configuration in the following order of precedence:
126
+
127
+ 1. **Environment Variables** (recommended for Docker/CI):
128
+ - `GRAFANA_HOST`: Grafana instance URL (e.g. `https://your-grafana-instance.com`)
129
+ - `GRAFANA_API_KEY`: Grafana Service Account Token (required)
130
+ - `GRAFANA_SSL_VERIFY`: `true` or `false` (default: `true`)
131
+ - `MCP_SERVER_PORT`: Port to run the server on (default: `8000`)
132
+ - `MCP_SERVER_DEBUG`: `true` or `false` (default: `true`)
133
+ 2. **YAML file fallback** (`config.yaml`):
134
+ ```yaml
135
+ grafana:
136
+ host: "https://your-grafana-instance.com"
137
+ api_key: "your-grafana-api-key-here"
138
+ ssl_verify: "true"
139
+ server:
140
+ port: 8000
141
+ debug: true
142
+ ```
143
+
144
+ ---
145
+
146
+ ## 4. Integration with AI Assistants (e.g., Claude Desktop, Cursor)
147
+
148
+ You can integrate this MCP server with any tool that supports the MCP protocol. Here are the main options:
149
+
150
+ ### 4A. Using Docker (with environment variables)
151
+
152
+ ```json
153
+ {
154
+ "mcpServers": {
155
+ "grafana": {
156
+ "command": "docker",
157
+ "args": [
158
+ "run",
159
+ "--rm",
160
+ "-i",
161
+ "-e",
162
+ "GRAFANA_HOST",
163
+ "-e",
164
+ "GRAFANA_API_KEY",
165
+ "-e",
166
+ "GRAFANA_SSL_VERIFY",
167
+ "drdroidlab/grafana-mcp-server",
168
+ "-t",
169
+ "stdio"
170
+ ],
171
+ "env": {
172
+ "GRAFANA_HOST": "https://your-grafana-instance.com",
173
+ "GRAFANA_API_KEY": "your-grafana-api-key-here",
174
+ "GRAFANA_SSL_VERIFY": "true"
175
+ }
176
+ }
177
+ }
178
+ }
179
+ ```
180
+
181
+ - The `-t stdio` argument is supported for compatibility with Docker MCP clients (forces stdio handshake mode).
182
+ - Adjust the volume path or environment variables as needed for your deployment.
183
+
184
+ ### 4B. Connecting to an Already Running MCP Server (HTTP/SSE)
185
+
186
+ If you have an MCP server already running (e.g., on a remote host, cloud VM, or Kubernetes), you can connect your AI assistant or tool directly to its HTTP endpoint.
187
+
188
+ ```json
189
+ {
190
+ "mcpServers": {
191
+ "grafana": {
192
+ "url": "http://your-server-host:8000/mcp"
193
+ }
194
+ }
195
+ }
196
+ ```
197
+
198
+ - Replace `your-server-host` with the actual host where your MCP server is running.
199
+ - **For local setup, use `localhost` as the server host (i.e., `http://localhost:8000/mcp`).**
200
+ - **Use `http` for local or unsecured deployments, and `https` for production or secured deployments.**
201
+ - Make sure the server is accessible from your client machine (check firewall, security group, etc.).
202
+
203
+ ---
204
+
205
+ ## Health Check
206
+
207
+ ```bash
208
+ curl http://localhost:8000/health
209
+ ```
210
+
211
+ The server runs on port 8000 by default.
212
+
213
+ ---
214
+
215
+ ## 5. Project Structure
216
+
217
+ ```
218
+ grafana-mcp-server/
219
+ │ └── src/
220
+ │ └── grafana_mcp_server/
221
+ │ ├── __init__.py
222
+ │ ├── config.yaml # Configuration file
223
+ │ ├── mcp_server.py # Main MCP server implementation
224
+ │ ├── stdio_server.py # STDIO server for MCP
225
+ │ └── processor/
226
+ │ ├── __init__.py
227
+ │ ├── grafana_processor.py # Grafana API processor
228
+ │ └── processor.py # Base processor interface
229
+ ├── tests/
230
+ ├── Dockerfile
231
+ ├── docker-compose.yml
232
+ ├── pyproject.toml
233
+ └── README.md
234
+ ```
235
+
236
+ ---
237
+
238
+ ---
239
+
240
+ ## 6. Troubleshooting
241
+
242
+ ### Common Issues
243
+
244
+ 1. **Connection Failed**:
245
+
246
+ - Verify your Grafana instance is running and accessible
247
+ - Check your API key has proper permissions
248
+ - Ensure SSL verification settings match your setup
249
+
250
+ 2. **Authentication Errors**:
251
+
252
+ - Verify your API key is correct and not expired
253
+ - Check if your Grafana instance requires additional authentication
254
+
255
+ 3. **Query Failures**:
256
+ - Ensure datasource UIDs are correct
257
+ - Verify PromQL/Loki query syntax
258
+ - Check if the datasource is accessible with your API key
259
+
260
+ ### Debug Mode
261
+
262
+ Enable debug mode to get more detailed logs:
263
+
264
+ ```bash
265
+ export MCP_SERVER_DEBUG=true
266
+ ```
267
+
268
+ ---
269
+
270
+ ## 7. Contributing
271
+
272
+ 1. Fork the repository
273
+ 2. Create a feature branch (`git checkout -b feature/amazing-feature`)
274
+ 3. Commit your changes (`git commit -m 'Add some amazing feature'`)
275
+ 4. Push to the branch (`git push origin feature/amazing-feature`)
276
+ 5. Open a Pull Request
277
+
278
+ ---
279
+
280
+ ## 8. License
281
+
282
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
283
+
284
+ ---
285
+
286
+ ## 9. Support
287
+
288
+ 1. Need help anywhere? Join our [discord channel](https://discord.gg/GTzfNMSm) and message on #mcp channel.
289
+ 2. Want a 1-click MCP Server? Join the same community and let us know.
290
+ 3. For issues and questions, please open an issue on GitHub or contact the maintainers.
@@ -0,0 +1,12 @@
1
+ grafana_mcp_server/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ grafana_mcp_server/config.yaml,sha256=_3atvreP7JjPCGxeHA0TcC0D6aBbYDol0w63ffwMUMQ,328
3
+ grafana_mcp_server/mcp_server.py,sha256=x8S-BFKjFaqL2V2xDTOr88M88vJgDxBF93exKYZRo5w,24061
4
+ grafana_mcp_server/stdio_server.py,sha256=tSuTC0tc_17FHTan43MSp7SuNRyg3vLIoyfXNaahkjY,1054
5
+ grafana_mcp_server/processor/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ grafana_mcp_server/processor/grafana_processor.py,sha256=p0X763gvgFs3iMnuOev_2Sb_C__ysmbJFpi5yhcHRV8,31128
7
+ grafana_mcp_server/processor/processor.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
+ iflow_mcp_drdroidlab_grafana_mcp_server-0.1.0.dist-info/METADATA,sha256=nZYhW8Ch5V1kjTcBnrHU75Xj5H2Tly0pTzO2EvqXJ6g,10530
9
+ iflow_mcp_drdroidlab_grafana_mcp_server-0.1.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
10
+ iflow_mcp_drdroidlab_grafana_mcp_server-0.1.0.dist-info/entry_points.txt,sha256=QEuMtd0vnzBw9u2OlbrLtMEgDD1cjjLiznlg8MsG6Ik,78
11
+ iflow_mcp_drdroidlab_grafana_mcp_server-0.1.0.dist-info/licenses/LICENSE,sha256=v6DSvYihESAcIL8D-f5hYXu05--UCvk7ack7ozumkWU,1069
12
+ iflow_mcp_drdroidlab_grafana_mcp_server-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.28.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ grafana-mcp-server = src.grafana_mcp_server.mcp_server:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Doctor Droid
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.