Documentation
¶
Overview ¶
Package prometheus provides MCP tools for interacting with Prometheus servers.
This package implements the following MCP tools:
Query Tools:
- execute_query: Execute PromQL instant queries
- execute_range_query: Execute PromQL range queries with time bounds
Discovery Tools:
- list_metrics: List all available metrics
- get_metric_metadata: Get metadata for specific metrics
- get_targets: Get information about scrape targets
Authentication Support:
- Basic authentication via username/password
- Bearer token authentication
- Multi-tenant organization ID headers
All tools support the standard Prometheus HTTP API and handle authentication automatically based on the server configuration.
Example tool usage:
execute_query: {"query": "up", "time": "2023-01-01T00:00:00Z"}
execute_range_query: {"query": "rate(http_requests_total[5m])", "start": "2023-01-01T00:00:00Z", "end": "2023-01-01T01:00:00Z", "step": "1m"}
list_metrics: {}
get_metric_metadata: {"metric": "http_requests_total"}
get_targets: {}
Index ¶
- Constants
- func RegisterPrometheusTools(s *mcpserver.MCPServer, sc *server.ServerContext, middleware ...ToolMiddleware) error
- type Client
- func (c *Client) CheckReady(ctx context.Context) (*HealthStatus, error)
- func (c *Client) ExecuteQuery(ctx context.Context, query string, timeParam string) (*QueryResult, error)
- func (c *Client) ExecuteQueryWithOptions(ctx context.Context, query string, timeParam string, options QueryOptions) (*QueryResult, error)
- func (c *Client) ExecuteRangeQuery(ctx context.Context, query, start, end, step string) (*QueryResult, error)
- func (c *Client) ExecuteRangeQueryWithOptions(ctx context.Context, query, start, end, step string, options QueryOptions) (*QueryResult, error)
- func (c *Client) FindSeries(ctx context.Context, matches []string, options SeriesOptions) (*SeriesResult, error)
- func (c *Client) GetAlertManagers(ctx context.Context) (interface{}, error)
- func (c *Client) GetAlerts(ctx context.Context) (interface{}, error)
- func (c *Client) GetBuildInfo(ctx context.Context) (interface{}, error)
- func (c *Client) GetConfig(ctx context.Context) (interface{}, error)
- func (c *Client) GetFlags(ctx context.Context) (interface{}, error)
- func (c *Client) GetMetricMetadata(ctx context.Context, metric string) (MetricMetadata, error)
- func (c *Client) GetMetricMetadataWithOptions(ctx context.Context, metric string, options MetricMetadataOptions) (MetricMetadata, error)
- func (c *Client) GetRules(ctx context.Context) (interface{}, error)
- func (c *Client) GetRuntimeInfo(ctx context.Context) (interface{}, error)
- func (c *Client) GetTSDBStats(ctx context.Context, options TSDBOptions) (interface{}, error)
- func (c *Client) GetTargets(ctx context.Context) (*TargetsResult, error)
- func (c *Client) GetTargetsMetadata(ctx context.Context, matchTarget, metric, limit string) (interface{}, error)
- func (c *Client) ListLabelNames(ctx context.Context, options LabelOptions) (*LabelNamesResult, error)
- func (c *Client) ListLabelValues(ctx context.Context, label string, options LabelOptions) (*LabelValuesResult, error)
- func (c *Client) QueryExemplars(ctx context.Context, query, start, end string) (interface{}, error)
- type HealthStatus
- type LabelNamesResult
- type LabelOptions
- type LabelValuesResult
- type MetricMetadata
- type MetricMetadataOptions
- type PrometheusHandler
- type QueryOptions
- type QueryResult
- type SeriesOptions
- type SeriesResult
- type TSDBOptions
- type TargetsResult
- type ToolMiddleware
Constants ¶
const ( MaxResultLength = 50000 TruncationAdvice = `` /* 608-byte string literal not displayed */ )
Constants for result truncation
Variables ¶
This section is empty.
Functions ¶
func RegisterPrometheusTools ¶
func RegisterPrometheusTools(s *mcpserver.MCPServer, sc *server.ServerContext, middleware ...ToolMiddleware) error
RegisterPrometheusTools registers Prometheus-related tools with the MCP server. Pass optional ToolMiddleware values to instrument every tool call (e.g. metrics, tracing).
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps the official Prometheus client with logging
func NewClient ¶
NewClient creates a new Prometheus client using the official client library. It returns an error for configuration problems (empty URL, unreadable CA file) rather than returning a partially initialised client that panics on first use.
func (*Client) CheckReady ¶ added in v0.0.18
func (c *Client) CheckReady(ctx context.Context) (*HealthStatus, error)
CheckReady checks whether the Prometheus/Mimir server is ready to serve traffic.
It first tries GET /-/ready against the scheme+host of the configured URL (the Prometheus standard endpoint). If that returns 404 — as happens with the Mimir nginx gateway, which only exposes GET /ready at the root — it falls back to GET /ready on the same base URL.
Using the scheme+host (not the full path) avoids the common misconfiguration where PROMETHEUS_URL is set to http://mimir-gateway/prometheus and appending /-/ready produces .../prometheus/-/ready, which the Mimir gateway has no route for.
func (*Client) ExecuteQuery ¶
func (c *Client) ExecuteQuery(ctx context.Context, query string, timeParam string) (*QueryResult, error)
ExecuteQuery executes an instant PromQL query
func (*Client) ExecuteQueryWithOptions ¶ added in v0.0.4
func (c *Client) ExecuteQueryWithOptions(ctx context.Context, query string, timeParam string, options QueryOptions) (*QueryResult, error)
ExecuteQueryWithOptions executes an instant PromQL query with additional options
func (*Client) ExecuteRangeQuery ¶
func (c *Client) ExecuteRangeQuery(ctx context.Context, query, start, end, step string) (*QueryResult, error)
ExecuteRangeQuery executes a range PromQL query
func (*Client) ExecuteRangeQueryWithOptions ¶ added in v0.0.4
func (c *Client) ExecuteRangeQueryWithOptions(ctx context.Context, query, start, end, step string, options QueryOptions) (*QueryResult, error)
ExecuteRangeQueryWithOptions executes a range PromQL query with additional options
func (*Client) FindSeries ¶ added in v0.0.4
func (c *Client) FindSeries(ctx context.Context, matches []string, options SeriesOptions) (*SeriesResult, error)
FindSeries finds series by label matchers
func (*Client) GetAlertManagers ¶ added in v0.0.4
GetAlertManagers gets AlertManager discovery info
func (*Client) GetBuildInfo ¶ added in v0.0.4
GetBuildInfo gets build information
func (*Client) GetMetricMetadata ¶
GetMetricMetadata gets metadata for a specific metric
func (*Client) GetMetricMetadataWithOptions ¶ added in v0.0.4
func (c *Client) GetMetricMetadataWithOptions(ctx context.Context, metric string, options MetricMetadataOptions) (MetricMetadata, error)
GetMetricMetadataWithOptions gets metadata for a specific metric with options
func (*Client) GetRuntimeInfo ¶ added in v0.0.4
GetRuntimeInfo gets runtime information
func (*Client) GetTSDBStats ¶ added in v0.0.4
func (c *Client) GetTSDBStats(ctx context.Context, options TSDBOptions) (interface{}, error)
GetTSDBStats gets TSDB cardinality statistics
func (*Client) GetTargets ¶
func (c *Client) GetTargets(ctx context.Context) (*TargetsResult, error)
GetTargets gets information about scrape targets
func (*Client) GetTargetsMetadata ¶ added in v0.0.4
func (c *Client) GetTargetsMetadata(ctx context.Context, matchTarget, metric, limit string) (interface{}, error)
GetTargetsMetadata gets metadata about metrics from specific targets
func (*Client) ListLabelNames ¶ added in v0.0.4
func (c *Client) ListLabelNames(ctx context.Context, options LabelOptions) (*LabelNamesResult, error)
ListLabelNames gets all available label names
func (*Client) ListLabelValues ¶ added in v0.0.4
func (c *Client) ListLabelValues(ctx context.Context, label string, options LabelOptions) (*LabelValuesResult, error)
ListLabelValues gets values for a specific label
type HealthStatus ¶ added in v0.0.18
type HealthStatus struct {
Ready bool `json:"ready"`
StatusCode int `json:"statusCode"`
Message string `json:"message"`
}
HealthStatus represents the result of a readiness check
type LabelNamesResult ¶ added in v0.0.4
type LabelNamesResult struct {
LabelNames []string `json:"labelNames"`
Warnings []string `json:"warnings,omitempty"`
}
LabelNamesResult represents the result of listing label names
type LabelOptions ¶ added in v0.0.4
LabelOptions holds options for label-related queries
type LabelValuesResult ¶ added in v0.0.4
type LabelValuesResult struct {
LabelValues []string `json:"labelValues"`
Warnings []string `json:"warnings,omitempty"`
}
LabelValuesResult represents the result of listing label values
type MetricMetadata ¶
type MetricMetadata map[string]interface{}
MetricMetadata represents metadata for a metric
type MetricMetadataOptions ¶ added in v0.0.4
type MetricMetadataOptions struct {
Limit string
}
MetricMetadataOptions holds optional parameters for getting metric metadata
type PrometheusHandler ¶ added in v0.0.4
type PrometheusHandler func(ctx context.Context, request mcp.CallToolRequest, client *Client, sc *server.ServerContext) (*mcp.CallToolResult, error)
Handler wrapper type for cleaner function signatures
type QueryOptions ¶ added in v0.0.4
QueryOptions holds optional parameters for queries
type QueryResult ¶
type QueryResult struct {
ResultType string `json:"resultType"`
Result interface{} `json:"result"`
}
QueryResult represents the result of an instant query
type SeriesOptions ¶ added in v0.0.4
SeriesOptions holds options for series queries
type SeriesResult ¶ added in v0.0.4
type SeriesResult struct {
Series []map[string]string `json:"series"`
Warnings []string `json:"warnings,omitempty"`
}
SeriesResult represents the result of finding series
type TSDBOptions ¶ added in v0.0.4
type TSDBOptions struct {
Limit string
}
TSDBOptions holds options for TSDB queries
type TargetsResult ¶
type TargetsResult struct {
ActiveTargets []interface{} `json:"activeTargets"`
DroppedTargets []interface{} `json:"droppedTargets"`
}
TargetsResult represents the result of the targets API
type ToolMiddleware ¶ added in v0.0.21
type ToolMiddleware func( name string, next func(context.Context, mcp.CallToolRequest) (*mcp.CallToolResult, error), ) func(context.Context, mcp.CallToolRequest) (*mcp.CallToolResult, error)
ToolMiddleware is an optional hook invoked around each MCP tool call. name is the tool name; next is the underlying handler. Implement this to add metrics, tracing, or other cross-cutting concerns.