Skip to content

Commit f1222d1

Browse files
committed
Fix
Signed-off-by: Saswata Mukherjee <saswataminsta@yahoo.com>
1 parent c22fcb8 commit f1222d1

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

TOOLS.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ This MCP server exposes the following tools for interacting with Prometheus/Than
1212
**Usage Tips:**
1313

1414
- YOU MUST CALL THIS TOOL BEFORE ANY OTHER QUERY TOOL
15-
- This tool MUST be called first for EVERY observability question to: 1. Discover what metrics actually exist in this environment 2. Find the EXACT metric name to use in queries 3. Avoid querying non-existent metrics
15+
- This tool MUST be called first for EVERY observability question to: 1. Discover what metrics actually exist in this environment 2. Find the EXACT metric name to use in queries 3. Avoid querying non-existent metrics 4. The 'name_regex' parameter should always be provided, and be a best guess of what the metric would be named like. 5. Do not use a blanket regex like .* or .+ in the 'name_regex' parameter. Use specific ones like kube.*, node.*, etc.
1616
- NEVER skip this step. NEVER guess metric names. Metric names vary between environments.
1717
- After calling this tool: 1. Search the returned list for relevant metrics 2. Use the EXACT metric name found in subsequent queries 3. If no relevant metric exists, inform the user
1818

19-
| | |
20-
| :------------- | :--- |
21-
| **Parameters** | None |
19+
**Parameters:**
20+
21+
| Parameter | Type | Required | Description |
22+
| :----------- | :------- | :------: | :------------------------------------------------------------------------------------------------------------------------------------ |
23+
| `name_regex` | `string` || Regex pattern to filter metric names (e.g., 'http_.*', 'node_.*', 'kube.*'). This parameter is required. Don't pass in blanket regex. |
2224

2325
**Output Schema:**
2426

pkg/prometheus/loader.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (p *RealLoader) WithGuardrails(g *Guardrails) *RealLoader {
5656

5757
func (p *RealLoader) ListMetrics(ctx context.Context, nameRegex string) ([]string, error) {
5858
// Create a matcher for the __name__ label with the provided regex
59-
matcher := fmt.Sprintf("{__name__=~\"%s\"}", nameRegex)
59+
matcher := fmt.Sprintf("{__name__=~\"%q\"}", nameRegex)
6060
labelValues, _, err := p.client.LabelValues(ctx, "__name__", []string{matcher}, time.Now().Add(-ListMetricsTimeRange), time.Now())
6161
if err != nil {
6262
return nil, fmt.Errorf("error fetching metric names: %w", err)

0 commit comments

Comments
 (0)