Skip to main content
Glama
MCP Prometheus

MCP Prometheus

by yeonkyu-git

๏ปฟ# MCP Prometheus + Loki ๐Ÿ“ˆ

Prometheus + Loki ๊ธฐ๋ฐ˜ ๋ชจ๋‹ˆํ„ฐ๋ง์šฉ MCP ์„œ๋ฒ„์ž…๋‹ˆ๋‹ค. ์—”ํŠธ๋ฆฌํฌ์ธํŠธ๋Š” main.py์ž…๋‹ˆ๋‹ค.

Quick Start ๐Ÿš€

cd d:\MCPTools
uv sync
uv run python mcp_prometheus/main.py

Related MCP server: poly-observability-mcp

ํ”„๋กœ์ ํŠธ ๊ตฌ์กฐ ๐Ÿงฉ

mcp_prometheus/
  main.py
  core/
    config.py
    runtime.py
    server.py
    time_utils.py
  domain/
    checks.py
  infra/
    loki_client.py
    prom_client.py
  tools/
    catalog.py
    alerts_runner.py
    checks_runner.py
    loki_query.py
    promql.py
  utils/
    query_utils.py
    summarize.py

Tools ์š”์•ฝ ๐Ÿ› ๏ธ

Tool

๋ชฉ์ 

๋น„๊ณ 

list_checks

๋“ฑ๋ก๋œ ์ฒดํฌ ๋ชฉ๋ก ์กฐํšŒ

id, name, description ๋ฐ˜ํ™˜

list_environments

ํ™˜๊ฒฝ๋ณ„ Prometheus URL ์กฐํšŒ

prod/dev_test/dr

list_servers

์ตœ๊ทผ up ๊ธฐ์ค€ ์„œ๋ฒ„ ๋ชฉ๋ก ์กฐํšŒ

(instance, job) ๊ธฐ์ค€ ์ค‘๋ณต ์ œ๊ฑฐ

list_process_groups

ํ”„๋กœ์„ธ์Šค ๊ทธ๋ฃน ๋ชฉ๋ก ์กฐํšŒ

process_monitoring ๊ธฐ์ค€

list_loki_environments

ํ™˜๊ฒฝ๋ณ„ Loki URL ์กฐํšŒ

prod/dev_test

list_loki_hosts

์ตœ๊ทผ ๋กœ๊ทธ ๊ธฐ์ค€ host ํ›„๋ณด ์กฐํšŒ

๊ธฐ๋ณธ ์ตœ๊ทผ 1์‹œ๊ฐ„

list_loki_apps

์ตœ๊ทผ ๋กœ๊ทธ ๊ธฐ์ค€ app ํ›„๋ณด ์กฐํšŒ

๊ธฐ๋ณธ ์ตœ๊ทผ 1์‹œ๊ฐ„

find_logs

๊ตฌ์กฐํ™”๋œ Loki ๋กœ๊ทธ ์กฐํšŒ

loki_environment, log_env, host, app ํ•„์š”

get_alerts

Prometheus ํ™œ์„ฑ Alert ์กฐํšŒ

/api/v1/alerts ๊ธฐ๋ฐ˜, ๋ผ๋ฒจ/์ƒํƒœ ํ•„ํ„ฐ ์ง€์›

run_check

๋‹จ์ผ ์ฒดํฌ ์‹คํ–‰

๊ธฐ๋ณธ ๊ถŒ์žฅ

run_all_checks

์ „์ฒด ์ฒดํฌ ๋ณ‘๋ ฌ ์‹คํ–‰

step=5m ๊ณ ์ •

run_promql

์‚ฌ์šฉ์ž PromQL ์ง์ ‘ ์‹คํ–‰

approved=True ํ•„์š”

Loki Tool ์ž…๋ ฅ ๊ฐ€์ด๋“œ ๐Ÿชต

ํ™˜๊ฒฝ ๊ตฌ๋ถ„

  • loki_environment: ์–ด๋–ค Loki ์„œ๋ฒ„๋กœ ๋ถ™์„์ง€ ์„ ํƒ (prod, dev_test)

  • log_env: Loki ๋กœ๊ทธ ๋ผ๋ฒจ env ๊ฐ’ (prod, DEV, TEST)

์ด ๋‘˜์€ ๊ฐ™์€ ์˜๋ฏธ๊ฐ€ ์•„๋‹™๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด dev_test Loki ์„œ๋ฒ„ ์•ˆ์— DEV์™€ TEST ๋กœ๊ทธ๊ฐ€ ํ•จ๊ป˜ ์žˆ์„ ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ, find_logs ํ˜ธ์ถœ ์‹œ log_env๋Š” ๋ช…์‹œ์ ์œผ๋กœ ๋„ฃ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

Discovery Tool

  • list_loki_hosts

  • list_loki_apps

๊ณตํ†ต ๊ทœ์น™:

  • ๊ธฐ๋ณธ ๊ธฐ๊ฐ„์€ ์ตœ๊ทผ 1์‹œ๊ฐ„

  • ์ ˆ๋Œ€ ์‹œ๊ฐ„ ์กฐํšŒ ์‹œ start_time_utc_iso, end_time_utc_iso ์‚ฌ์šฉ

  • ๊ฒฐ๊ณผ๋Š” ์ค‘๋ณต ์ œ๊ฑฐ๋œ ํ›„๋ณด ๋ชฉ๋ก ๋ฐ˜ํ™˜

find_logs

ํ•„์ˆ˜:

  • loki_environment

  • log_env

  • host

  • app

์„ ํƒ:

  • ๊ธฐ๊ฐ„: hours, minutes, days

  • ์ ˆ๋Œ€ ์‹œ๊ฐ„: start_time_utc_iso, end_time_utc_iso

  • ์ข…๋ฃŒ ์˜คํ”„์…‹: end_offset_minutes, end_offset_hours, end_offset_days

  • ํ•„ํ„ฐ: contains, level

  • ๊ฐœ์ˆ˜ ์ œํ•œ: limit

์‘๋‹ต:

  • ์ƒ์„ฑ๋œ LogQL

  • UTC ๋ฒ”์œ„

  • line_count

  • logs[] (timestamp, timestamp_jakarta, labels, line)

run_check ์ž…๋ ฅ ๊ฐ€์ด๋“œ ๐Ÿงญ

ํ•„์ˆ˜

  • check_id

๊ธฐ๊ฐ„

  • ์ƒ๋Œ€: hours, minutes, days

  • ์ ˆ๋Œ€: start_time_utc_iso, end_time_utc_iso

  • ์ข…๋ฃŒ ์˜คํ”„์…‹: end_offset_minutes, end_offset_hours, end_offset_days

ํƒ€๊ฒŸ ํ•„ํ„ฐ

  • server_name

  • instance (์˜ˆ: host-or-ip:9100)

ํ•„ํ„ฐ ๊ทœ์น™:

  • server_name์™€ instance๋ฅผ ํ•จ๊ป˜ ์ฃผ๋ฉด AND ์ ์šฉ

  • ํ•˜๋‚˜๋งŒ ์ฃผ๋ฉด ํ•ด๋‹น ๋ผ๋ฒจ๋งŒ ์ ์šฉ

run_promql ๊ฐ€๋“œ๋ ˆ์ผ ๐Ÿ”’

  • approved=False: ์‹คํ–‰ํ•˜์ง€ ์•Š๊ณ  ํ™•์ธ ๋ฉ”์‹œ์ง€ ๋ฐ˜ํ™˜

  • approved=True: ์‹คํ–‰

๋ชจ๋“œ:

  • instant=True -> /api/v1/query

  • instant=False -> /api/v1/query_range

์‚ฌ์šฉ ์˜ˆ์‹œ ๐Ÿ“Œ

1) ํŠน์ • ์„œ๋ฒ„ CPU ํ‰๊ท  (์ตœ๊ทผ 24์‹œ๊ฐ„)

{
  "check_id": "cpu_avg_pct",
  "hours": 24,
  "instance": "10.23.12.11:9100",
  "environment": "prod"
}

2) ํŠน์ • ์„œ๋ฒ„ ๋””์Šคํฌ ์‚ฌ์šฉ๋ฅ  (mountpoint๋ณ„)

{
  "check_id": "disk_used_pct_by_mount",
  "hours": 24,
  "server_name": "CMS AP #1",
  "environment": "prod"
}

3) ์‚ฌ์šฉ์ž PromQL ์‹คํ–‰ (instant)

{
  "promql": "up",
  "approved": true,
  "instant": true,
  "environment": "prod"
}

4) Loki host ํ›„๋ณด ์กฐํšŒ

{
  "loki_environment": "dev_test",
  "log_env": "DEV",
  "app": "finast",
  "hours": 1
}

5) Loki ๋กœ๊ทธ ์กฐํšŒ

{
  "loki_environment": "prod",
  "log_env": "prod",
  "host": "cms-ap-01",
  "app": "cms",
  "hours": 1,
  "contains": "timeout",
  "limit": 200
}

CHECKS Catalog โœ…

Source: domain/checks.py (CHECKS)

System / Resource

  • cpu_avg_pct: CPU average usage (%) by instance/server_name

  • cpu_peak_pct: window peak CPU usage (%) over selected range

  • mem_used_pct: memory used ratio (%)

  • mem_swap_used_pct: swap used ratio (%)

  • load15_avg: 15-minute load average

  • cpu_iowait_pct: CPU iowait ratio (%)

Disk / Filesystem

  • disk_used_pct_by_mount: filesystem used (%) by mountpoint/device (0-100 scale)

  • disk_used_top5_pct: top 5 filesystem usage (%)

  • disk_inodes_used_pct: inode usage (%)

  • fs_readonly: readonly filesystem indicator (1=readonly)

  • disk_io_busy_pct: disk I/O busy ratio (%)

Availability

  • up: target liveness (1=up, 0=down)

Network / TCP

  • net_in_bytes: inbound throughput (bytes/sec)

  • net_out_bytes: outbound throughput (bytes/sec)

  • net_errs_per_sec: RX+TX network errors per second

  • tcp_retrans_per_sec: TCP retransmit segments per second

  • tcp_established: established TCP connections

  • tcp_time_wait: TIME_WAIT TCP sockets

  • tcp_inuse: in-use TCP sockets

  • tcp_orphan: orphan TCP sockets

Process Monitoring

  • proc_cpu_pct: process group CPU usage (%)

  • proc_mem_bytes: process group memory usage (bytes)

  • proc_count: process group process count

PostgreSQL

  • pg_up: PostgreSQL exporter up state (1=up, 0=down)

  • pg_qps: PostgreSQL transactions/sec (commit + rollback)

  • pg_cache_hit_pct: PostgreSQL buffer cache hit ratio (%)

  • pg_active_conn: active PostgreSQL connections

ํ™˜๊ฒฝ ๋ณ€์ˆ˜ ์š”์•ฝ โš™๏ธ

PROM_ENV_URLS={"prod":"http://...:9090","dev_test":"http://...:9090","dr":"http://...:9090"}
PROM_URL=http://...:9090
PROM_BEARER_TOKEN=
PROM_TIMEOUT_SEC=15

LOKI_ENV_URLS={"prod":"http://...:3100","dev_test":"http://...:3100"}
LOKI_URL=http://...:3100
LOKI_BEARER_TOKEN=
LOKI_TIMEOUT_SEC=15

ALERT_WARN_PCT=85
ALERT_CRIT_PCT=95
ALERT_SUSTAIN_MINUTES=5

PROM_MAX_SAMPLES_PER_SERIES=5000
PROM_MAX_PARALLEL_CHECKS=6

ํ™˜๊ฒฝ ์„ ํƒ ์šฐ์„ ์ˆœ์œ„:

  1. environment

  2. env_hint

  3. PROM_URL fallback

Loki ํ™˜๊ฒฝ ์„ ํƒ ์šฐ์„ ์ˆœ์œ„:

  1. loki_environment

  2. LOKI_URL fallback

์šด์˜ ํŒ ๐Ÿ’ก

  • ๋ฆฌํฌํŠธ ์ถœ๋ ฅ ์‹œ % ๋‹จ์œ„๋ฅผ ๋ช…ํ™•ํžˆ ํ‘œ๊ธฐํ•˜์„ธ์š”.

  • ๋‹จ์ผ ์„œ๋ฒ„ ์ ๊ฒ€์€ instance ๋˜๋Š” server_name ํ•„ํ„ฐ๋ฅผ ์‚ฌ์šฉํ•˜์„ธ์š”.

  • disk_used_pct_by_mount ๊ฐ’์€ 0~100 ์Šค์ผ€์ผ์ž…๋‹ˆ๋‹ค. (0.8 = 0.8%)

  • Loki ์กฐํšŒ ์ „์—๋Š” list_loki_hosts ๋˜๋Š” list_loki_apps๋กœ ํ›„๋ณด๊ฐ’์„ ๋จผ์ € ํ™•์ธํ•˜๋Š” ํŽธ์ด ์•ˆ์ „ํ•ฉ๋‹ˆ๋‹ค.

Available Tools

12 tools
find_logsD

Inputs: loki_environment (required), log_env (required), host (required), app (required), +11 more. Returns: result

get_alertsC

Fetch active alerts from Prometheus /api/v1/alerts.

Filters (exact-match):

  • severity/state/alertname/job/server_name/instance

Inputs: severity, state, alertname, job, +5 more. Returns: result

list_checksB

Return all allowlisted monitoring checks available to the MCP server.

Response:

  • checks[].id: stable check id

  • checks[].name: display name

  • checks[].description: human-readable check description

Inputs: no named parameters. Returns: result

list_environmentsB

Return configured Prometheus environments and their base URLs.

Response:

  • environments[].key: environment key (for example prod, dev_test, dr)

  • environments[].prom_url: Prometheus URL for that environment

Inputs: no named parameters. Returns: result

list_loki_appsD

Inputs: loki_environment (required), log_env, host, hours, +8 more. Returns: result

list_loki_environmentsD

Inputs: no named parameters. Returns: result

list_loki_hostsD

Inputs: loki_environment (required), log_env, app, hours, +8 more. Returns: result

list_process_groupsC

Return process group names from process monitoring metrics.

Source metric:

  • namedprocess_namegroup_cpu_seconds_total{job="process_monitoring"}

  • label queried: groupname

Inputs: environment, env_hint. Returns: result

list_serversA

List monitored servers detected from recent up{server_name!=""} series.

Inputs:

  • environment: explicit environment key (highest priority).

  • env_hint: fallback environment hint when environment is not provided.

Behavior:

  • Queries last 10 minutes of up{server_name!=""}.

  • Returns unique targets by (instance, job) with server_name.

Inputs: environment, env_hint. Returns: result

run_all_checksA

Run all allowlisted checks in parallel for the same time range and filters.

Inputs are equivalent to run_check, including:

  • server_name: filter by label server_name

  • instance: filter by label instance (single-target filter)

Note:

  • step is fixed to 5m in this tool to control payload size. Any provided step value is ignored.

Inputs: hours, minutes, days, step, +10 more. Returns: result

run_checkA

Run one allowlisted check via Prometheus query_range and return summarized results.

Inputs:

  • check_id: required check id from domain.checks.CHECKS.

  • hours/minutes/days: relative lookback window.

  • start_time_utc_iso/end_time_utc_iso: absolute UTC range (if provided, this is used).

  • end_offset_minutes/end_offset_hours/end_offset_days: shift end time to the past.

  • step: range-query step (example: 1m, 5m, 15m).

  • include_samples: include raw samples in each series summary.

  • server_name: label filter for server_name.

  • instance: label filter for instance (example: host-or-ip:9100). Use this when targeting one exact exporter endpoint.

  • environment/env_hint: environment selector (environment has higher priority).

Filter behavior:

  • If both server_name and instance are provided, both filters are applied.

  • If only one is provided, only that label is applied.

Inputs: check_id (required), hours, minutes, days, +11 more. Returns: result

run_promqlA

Run custom PromQL.

Guardrail:

  • approved must be True before execution.

Modes:

  • instant=True: use /api/v1/query at a single timestamp.

  • instant=False: use /api/v1/query_range for a time window.

Inputs: promql (required), approved, instant, hours, +14 more. Returns: result

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelogโ€ฆ

    TDQS

    C2.6/5.0

    Scored across 12 tools

    Disambiguation4/5

    Most tools have distinct purposes, such as get_alerts for fetching alerts and run_check for executing specific checks. However, list_loki_apps, list_loki_environments, and list_loki_hosts are ambiguous without descriptions, potentially causing confusion about their specific functions and differences.

    Naming Consistency5/5

    Tool names follow a highly consistent verb_noun pattern throughout, such as list_servers, run_promql, and find_logs. All tools use snake_case without any deviations, making the naming predictable and easy to understand.

    Tool Count4/5

    With 12 tools, the count is well-suited for a Prometheus monitoring server, covering key operations like listing resources and running queries. It's slightly on the higher side but remains reasonable for the domain, though some tools like the Loki-related ones might be redundant or under-specified.

    Completeness3/5

    The toolset provides good coverage for querying and listing operations in Prometheus, including alerts, checks, and servers. However, there are notable gaps, such as missing tools for creating or managing alerts, configuring checks, or handling Loki data beyond listing, which limits full lifecycle management in the monitoring domain.

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      An MCP server that enables Large Language Models to retrieve, analyze, and query metric data from Prometheus databases through pre-defined routes.
      33
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Unified MCP server for observability and monitoring, providing tools to query metrics, logs, and traces through Prometheus, Grafana, Loki, and Jaeger.
      2
      Mozilla Public 2.0
    • F
      license
      Not graded
      quality
      D
      maintenance
      In-cluster MCP server for read-only diagnostics of Grafana, Prometheus, Alertmanager, and Loki, enabling metric queries, alert listings, and log queries through Grafana datasource proxies with Kubernetes RBAC authentication.
      -