Grafana MCP サーバーをインストール、設定し、効果的に利用する方法について説明します。Docker またはバイナリ(実行プログラム)での構築、環境変数の指定、ツールの分類、アクセス権限管理、そしてコンテキストウィンドウ(会話履歴を保持する領域)の管理に関するベストプラクティスをカバーしています。 次のような場合に使用: ユーザーが mcp-grafana をセットアップしたい、Grafana MCP ツールを設定したい、またはどの MCP ツールを使うべきかについてのアドバイスが必要な場合
Install, configure, and use the Grafana MCP server effectively. Covers setup via Docker or binary, environment variables, tool categories, RBAC, and best practices for context window management. Use when the user wants to set up mcp-grafana, configure Grafana MCP tools, or needs guidance on which MCP tool to use.
50以上のGrafana API ツールを提供するMCP サーバーです。Grafana 9.0以上に対応しており、ローカル環境とGrafana Cloud の両方で利用できます。
MCPサーバーは事前にインストール済みである必要があります。自動インストールを試みないでください。 インストールされていない場合は、ユーザーにまず先にインストールするよう案内してください。
インストール手順、事前ビルド済みバイナリ、Dockerイメージ、Helmチャートについては以下を参照: github.com/grafana/mcp-grafana
| 変数 | 説明 |
|---|---|
GRAFANA_URL |
GrafanaインスタンスのURL(デフォルト: http://localhost:3000) |
GRAFANA_SERVICE_ACCOUNT_TOKEN |
サービスアカウント トークン(推奨) |
GRAFANA_API_KEY |
APIキー(非推奨、サービスアカウント トークンを使用してください) |
GRAFANA_USERNAME + GRAFANA_PASSWORD |
基本認証 |
GRAFANA_ORG_ID |
複数組織設定の場合の組織ID |
GRAFANA_EXTRA_HEADERS |
カスタムHTTPヘッダーを含むJSONオブジェクト |
Grafanaでサービスアカウントを作成します。最低でもViewer(表示者)ロール、または書き込み操作が必要な場合はEditor(編集者)ロールを付与してください。トークンを生成します。
環境変数を設定します:
export GRAFANA_URL="https://mystack.grafana.net"
export GRAFANA_SERVICE_ACCOUNT_TOKEN="glsa_..."
MCPサーバーはCursorがプラグインを読み込む際に自動的に起動します。
Docker内から localhost に接続する場合は、host.docker.internal を使用してください:
{
"env": {
"GRAFANA_URL": "http://host.docker.internal:3000"
}
}
Dockerではなくバイナリを使う場合は、mcp.json を更新してください:
{
"mcpServers": {
"grafana": {
"command": "mcp-grafana",
"args": [],
"env": {
"GRAFANA_URL": "${GRAFANA_URL}",
"GRAFANA_SERVICE_ACCOUNT_TOKEN": "${GRAFANA_SERVICE_ACCOUNT_TOKEN}"
}
}
}
}
| フラグ | 説明 |
|---|---|
-t, --transport |
転送方式: stdio(デフォルト)、sse、streamable-http |
--address |
SSE/HTTP用のホスト:ポート(デフォルト: localhost:8000) |
--debug |
デバッグログを有効化 |
--log-level |
debug、info、warn、error |
--disable-write |
読み取り専用モード(作成・更新・削除ツールなし) |
--enabled-tools |
有効にするツールカテゴリのカンマ区切りリスト |
--metrics |
/metrics でPrometheusメトリクス(計測値)を有効化 |
search_dashboards — タイトル・メタデータで検索get_dashboard_summary — コンパクトな概要表示(フルJSONより推奨)get_dashboard_property — JSONPath経由で特定部分を抽出get_dashboard_panel_queries — パネルのクエリとデータソース情報を取得get_dashboard_by_uid — ダッシュボード全体のJSON(大容量のため必要な場合のみ)update_dashboard — ダッシュボードを作成・更新patch_dashboard — フルJSONなしで対象部分のみ変更list_datasources — すべてのデータソースを一覧表示get_datasource_by_uid / get_datasource_by_name — データソース詳細を取得query_prometheus — PromQL(Prometheus問い合わせ言語)クエリを実行list_prometheus_metric_metadata — メトリクスのメタデータを取得list_prometheus_metric_names — 利用可能なメトリクスを一覧表示list_prometheus_label_names / list_prometheus_label_values — ラベルの検出query_prometheus_histogram — ヒストグラムのパーセンタイルを計算query_loki_logs — LogQL(ログ問い合わせ言語)を使ってログ・メトリクスを照会list_loki_label_names / list_loki_label_values — ラベルの検出query_loki_stats — ストリーム統計query_loki_patterns — 検出されたログパターンlist_alert_rules / get_alert_rule_by_uid — アラートルールを読み取りcreate_alert_rule / update_alert_rule / delete_alert_rule — ルールを管理list_contact_points — 通知先list_incidents / get_incident — インシデントを読み取りcreate_incident / add_activity_to_incident — インシデントを管理list_oncall_schedules / get_oncall_shift / get_current_oncall_users — シフトスケジュールlist_oncall_teams / list_oncall_users — チーム・ユーザー検出list_alert_groups / get_alert_group — アラートグループlist_sift_investigations / get_sift_investigation / get_sift_analysisfind_error_pattern_logs / find_slow_requestslist_pyroscope_label_names / list_pyroscope_label_valueslist_pyroscope_profile_types / fetch_pyroscope_profileget_annotations / create_annotation / update_annotation / patch_annotationcreate_graphite_annotation / get_annotation_tagsgenerate_deeplink — ダッシュボード・パネル・探索機能のURLを生成get_panel_image — パネル・ダッシュボードをPNG画像として描画(Image Rendererが必要)以下のカテゴリは --enabled-tools で明示的に有効にする必要があります:
list_clickhouse_tables、describe_clickhouse_table、query_clickhouselist_cloudwatch_namespaces、list_cloudwatch_metrics、list_cloudwatch_dimensions、query_cloudwatchquery_elasticsearchlist_teams、list_users_by_org、list_all_roles、get_role_details、get_role_assignmentssearch_logs(ClickHouseとLoki全体の高レベル検索)get_query_examplesget_dashboard_by_uid ではなく get_dashboard_summary を使用してください。get_dashboard_property で必要な部分だけを抽出してください。update_dashboard ではなく、対象部分のみ変更する patch_dashboard を推奨します。search_dashboards でダッシュボードを検出してください。generate_deeplink でクリック可能なURLを提供してください。list_datasources、list_prometheus_metric_names)を使用してください。update_dashboard、create_incident、create_alert_rule)は避けてください。--disable-write フラグで読み取り専用モードを使用してください。--enabled-tools で未使用のツールカテゴリを無効化し、攻撃対象領域とコンテキスト使用量を削減してください。MCP server exposing 50+ Grafana API tools. Supports Grafana 9.0+ (local and Grafana Cloud).
The MCP server must already be installed. Do not attempt to install it automatically. If it is not available, stop and tell the user to install it first.
Installation instructions, pre-built binaries, Docker images, and Helm charts: github.com/grafana/mcp-grafana
| Variable | Description |
|---|---|
GRAFANA_URL |
Grafana instance URL (default: http://localhost:3000) |
GRAFANA_SERVICE_ACCOUNT_TOKEN |
Service account token (recommended) |
GRAFANA_API_KEY |
API key (deprecated, use service account token) |
GRAFANA_USERNAME + GRAFANA_PASSWORD |
Basic auth |
GRAFANA_ORG_ID |
Organization ID for multi-org setups |
GRAFANA_EXTRA_HEADERS |
JSON object with custom HTTP headers |
Create a service account in Grafana with at least Viewer role (or Editor for write operations). Generate a token.
Set environment variables:
export GRAFANA_URL="https://mystack.grafana.net"
export GRAFANA_SERVICE_ACCOUNT_TOKEN="glsa_..."
The MCP server starts automatically when Cursor loads the plugin.
When connecting to localhost from Docker, use host.docker.internal:
{
"env": {
"GRAFANA_URL": "http://host.docker.internal:3000"
}
}
If you prefer the binary over Docker, update mcp.json:
{
"mcpServers": {
"grafana": {
"command": "mcp-grafana",
"args": [],
"env": {
"GRAFANA_URL": "${GRAFANA_URL}",
"GRAFANA_SERVICE_ACCOUNT_TOKEN": "${GRAFANA_SERVICE_ACCOUNT_TOKEN}"
}
}
}
}
| Flag | Description |
|---|---|
-t, --transport |
Transport type: stdio (default), sse, streamable-http |
--address |
Host:port for SSE/HTTP (default: localhost:8000) |
--debug |
Enable debug logging |
--log-level |
debug, info, warn, error |
--disable-write |
Read-only mode (no create/update/delete tools) |
--enabled-tools |
Comma-separated list of enabled tool categories |
--metrics |
Enable Prometheus metrics at /metrics |
search_dashboards — search by title/metadataget_dashboard_summary — compact overview (preferred over full JSON)get_dashboard_property — extract specific parts via JSONPathget_dashboard_panel_queries — get panel queries and datasource infoget_dashboard_by_uid — full dashboard JSON (large, avoid unless needed)update_dashboard — create or update a dashboardpatch_dashboard — targeted modifications without full JSONlist_datasources — list all datasourcesget_datasource_by_uid / get_datasource_by_name — get datasource detailsquery_prometheus — execute PromQL querieslist_prometheus_metric_metadata — get metric metadatalist_prometheus_metric_names — list available metricslist_prometheus_label_names / list_prometheus_label_values — label discoveryquery_prometheus_histogram — calculate histogram percentilesquery_loki_logs — query logs/metrics using LogQLlist_loki_label_names / list_loki_label_values — label discoveryquery_loki_stats — stream statisticsquery_loki_patterns — detected log patternslist_alert_rules / get_alert_rule_by_uid — read alert rulescreate_alert_rule / update_alert_rule / delete_alert_rule — manage ruleslist_contact_points — notification endpointslist_incidents / get_incident — read incidentscreate_incident / add_activity_to_incident — manage incidentslist_oncall_schedules / get_oncall_shift / get_current_oncall_users — scheduleslist_oncall_teams / list_oncall_users — team/user discoverylist_alert_groups / get_alert_group — alert groupslist_sift_investigations / get_sift_investigation / get_sift_analysisfind_error_pattern_logs / find_slow_requestslist_pyroscope_label_names / list_pyroscope_label_valueslist_pyroscope_profile_types / fetch_pyroscope_profileget_annotations / create_annotation / update_annotation / patch_annotationcreate_graphite_annotation / get_annotation_tagsgenerate_deeplink — generate URLs for dashboards, panels, Exploreget_panel_image — render panel/dashboard as PNG (requires Image Renderer)These categories must be explicitly enabled with --enabled-tools:
list_clickhouse_tables, describe_clickhouse_table, query_clickhouselist_cloudwatch_namespaces, list_cloudwatch_metrics, list_cloudwatch_dimensions, query_cloudwatchquery_elasticsearchlist_teams, list_users_by_org, list_all_roles, get_role_details, get_role_assignmentssearch_logs (high-level across ClickHouse and Loki)get_query_examplesget_dashboard_summary instead of get_dashboard_by_uid to avoid consuming context with full dashboard JSON.get_dashboard_property with JSONPath to extract only the specific parts you need.patch_dashboard for targeted modifications over update_dashboard with full payload.search_dashboards to discover dashboards before retrieving by UID.generate_deeplink to provide clickable URLs rather than describing navigation steps.list_datasources, list_prometheus_metric_names) before writing queries.update_dashboard, create_incident, create_alert_rule) unless explicitly asked by the user.--disable-write flag for read-only mode when write access isn't needed.--enabled-tools to reduce attack surface and context usage.原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。