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); }

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