Skip to main content
Glama
0xteamhq

Grafana MCP Server

by 0xteamhq

list_datasources

Retrieve available Grafana datasources to identify data connections for monitoring and visualization. Optionally filter by specific types like Prometheus or Loki to find relevant data sources.

Instructions

List available Grafana datasources. Optionally filter by datasource type.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
typeNoThe type of datasources to search for (e.g., "prometheus", "loki")

Implementation Reference

  • ToolDefinition for 'list_datasources' including the async handler that uses GrafanaClient to fetch datasources from Grafana API, formats them, and returns the result or error.
    export const listDatasources: ToolDefinition = {
      name: 'list_datasources',
      description: 'List available Grafana datasources. Optionally filter by datasource type.',
      inputSchema: ListDatasourcesSchema,
      handler: async (params, context: ToolContext) => {
        try {
          const client = new GrafanaClient(context.config.grafanaConfig);
          const datasources = await client.listDatasources(params.type);
          
          // Format for readability
          const formatted = datasources.map(ds => ({
            uid: ds.uid,
            name: ds.name,
            type: ds.type,
            url: ds.url,
            isDefault: ds.isDefault,
          }));
          
          return createToolResult(formatted);
        } catch (error: any) {
          return createErrorResult(error.message);
        }
      },
    };
  • Zod schema defining the input parameters for the list_datasources tool (optional 'type' filter).
    const ListDatasourcesSchema = z.object({
      type: z.string().optional().describe('The type of datasources to search for (e.g., "prometheus", "loki")'),
    });
  • Registration function for datasource tools, including server.registerTool(listDatasources). This is called from src/cli.ts when datasource category is enabled.
    export function registerDatasourceTools(server: any) {
      server.registerTool(listDatasources);
      server.registerTool(getDatasourceByUid);
      server.registerTool(getDatasourceByName);
    }
  • GrafanaClient.listDatasources method: fetches all datasources from Grafana /api/datasources endpoint and optionally filters by type.
    async listDatasources(type?: string): Promise<Datasource[]> {
      try {
        const response = await this.client.get('/api/datasources');
        let datasources = response.data;
        
        if (type) {
          datasources = datasources.filter((ds: Datasource) => ds.type === type);
        }
        
        return datasources;
      } catch (error) {
        this.handleError(error);
      }
    }
  • src/cli.ts:104-106 (registration)
    Conditional call to registerDatasourceTools(server) in the MCP server startup code in CLI entrypoint.
    if (enabledTools.has('datasource')) {
      registerDatasourceTools(server);
    }
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 optional filtering but doesn't describe key behaviors such as pagination, rate limits, authentication requirements, or the format of returned data. For a list operation with no annotation coverage, this leaves significant gaps in understanding how the tool behaves in practice.

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

Conciseness5/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 ('List available Grafana datasources') and adds a brief qualifier about optional filtering. There is no wasted text, and it's structured to convey essential information without unnecessary elaboration.

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 lack of annotations and output schema, the description is incomplete for a tool that lists resources. It doesn't address behavioral aspects like pagination, error handling, or data format, which are critical for an AI agent to use the tool effectively. While the purpose is clear, the overall context needed for reliable operation is insufficient.

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?

The input schema has 100% description coverage, with the 'type' parameter documented as filtering by datasource type (e.g., 'prometheus', 'loki'). The description adds minimal value beyond this, only restating that filtering is optional. Since the schema does the heavy lifting, the baseline score of 3 is appropriate, as the description doesn't provide additional semantic context.

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 tool's purpose: 'List available Grafana datasources' with an optional filter by type. It specifies the verb ('List') and resource ('Grafana datasources'), making the action clear. However, it doesn't explicitly differentiate from sibling tools like 'get_datasource_by_name' or 'get_datasource_by_uid', which are more specific retrieval tools.

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

Usage Guidelines3/5

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

The description implies usage context by mentioning optional filtering by datasource type, suggesting it's for browsing or filtering datasources. However, it doesn't provide explicit guidance on when to use this tool versus alternatives like 'get_datasource_by_name' or 'get_datasource_by_uid', nor does it specify prerequisites or exclusions, leaving some ambiguity.

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