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
| Name | Required | Description | Default |
|---|---|---|---|
| type | No | The type of datasources to search for (e.g., "prometheus", "loki") |
Implementation Reference
- src/tools/datasource.ts:17-40 (handler)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); } }, };
- src/tools/datasource.ts:5-7 (schema)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")'), });
- src/tools/datasource.ts:72-76 (registration)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); }
- src/clients/grafana-client.ts:88-101 (helper)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); }