Skip to main content
Glama
0xteamhq

Grafana MCP Server

by 0xteamhq

list_prometheus_metric_names

Retrieve and filter metric names from a Prometheus datasource using regex patterns to identify specific monitoring metrics for analysis.

Instructions

List metric names in a Prometheus datasource. Retrieves all metric names and filters them using regex.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
datasourceUidYesThe UID of the datasource to query
limitNoThe maximum number of results to return
pageNoThe page number to return
regexNoThe regex to match against the metric names

Implementation Reference

  • The ToolDefinition export including the async handler function that implements the core logic: queries Prometheus series to extract unique metric names, applies optional regex filtering and pagination, sorts and returns the list.
    export const listPrometheusMetricNames: ToolDefinition = {
      name: 'list_prometheus_metric_names',
      description: 'List metric names in a Prometheus datasource. Retrieves all metric names and filters them using regex.',
      inputSchema: ListPrometheusMetricNamesSchema,
      handler: async (params, context: ToolContext) => {
        try {
          const client = new PrometheusClient(context.config.grafanaConfig, params.datasourceUid);
          
          // Get all series to extract metric names
          const series = await client.getSeries(['__name__=~".+"']);
          const metricNames = new Set<string>();
          
          for (const s of series) {
            if (s.__name__) {
              metricNames.add(s.__name__);
            }
          }
          
          let names = Array.from(metricNames).sort();
          
          // Apply regex filter if provided
          if (params.regex) {
            const regex = new RegExp(params.regex);
            names = names.filter(name => regex.test(name));
          }
          
          // Apply pagination
          if (params.limit || params.page) {
            const limit = params.limit || 100;
            const page = params.page || 1;
            const start = (page - 1) * limit;
            names = names.slice(start, start + limit);
          }
          
          return createToolResult(names);
        } catch (error: any) {
          return createErrorResult(error.message);
        }
      },
    };
  • Zod schema for input validation: requires datasourceUid, optional regex, limit, and page parameters.
    const ListPrometheusMetricNamesSchema = z.object({
      datasourceUid: z.string().describe('The UID of the datasource to query'),
      regex: z.string().optional().describe('The regex to match against the metric names'),
      limit: z.number().optional().describe('The maximum number of results to return'),
      page: z.number().optional().describe('The page number to return'),
    });
  • Function to register all Prometheus tools with the MCP server, including the call to server.registerTool(listPrometheusMetricNames).
    export function registerPrometheusTools(server: any) {
      server.registerTool(queryPrometheus);
      server.registerTool(listPrometheusMetricNames);
      server.registerTool(listPrometheusLabelNames);
      server.registerTool(listPrometheusLabelValues);
      server.registerTool(listPrometheusMetricMetadata);
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions 'Retrieves all metric names and filters them using regex,' which implies a read-only operation with filtering, but lacks details on permissions, rate limits, pagination behavior (despite 'limit' and 'page' parameters), error handling, or response format. For a tool with 4 parameters and no annotations, this is insufficient transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose. It avoids redundancy and waste, making it appropriately concise. However, it could be slightly more structured by separating the filtering aspect for clarity, but overall it's well-sized for the tool's complexity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool has 4 parameters, no annotations, and no output schema, the description is incomplete. It doesn't cover behavioral aspects like pagination, response format, or error conditions, which are critical for an agent to use the tool correctly. The description alone is inadequate for a tool of this complexity without additional structured data.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema fully documents all parameters. The description adds minimal value beyond the schema by mentioning regex filtering, but doesn't explain parameter interactions, default values, or usage examples. With high schema coverage, the baseline score of 3 is appropriate as the description doesn't significantly enhance parameter understanding.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('List metric names') and resource ('in a Prometheus datasource'), making the purpose evident. It distinguishes from some siblings like 'list_prometheus_label_names' by focusing on metric names, but doesn't explicitly differentiate from 'query_prometheus' which might also retrieve metrics. The description is specific but could be more precise about sibling differentiation.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention siblings like 'list_prometheus_label_names' for labels or 'query_prometheus' for metric values, nor does it specify prerequisites or exclusions. Usage is implied by the name and description alone, with no explicit context for selection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/0xteamhq/mcp-grafana'

If you have feedback or need assistance with the MCP directory API, please join our Discord server