get_datasource_by_name
Retrieve detailed information about a specific Grafana datasource by providing its name to access configuration and connection details.
Instructions
Retrieves detailed information about a specific datasource using its name.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | The name of the datasource |
Implementation Reference
- src/tools/datasource.ts:57-70 (handler)The main handler function for the 'get_datasource_by_name' MCP tool. It instantiates a GrafanaClient using the server config and calls getDatasourceByName on it to retrieve and return the datasource details.export const getDatasourceByName: ToolDefinition = { name: 'get_datasource_by_name', description: 'Retrieves detailed information about a specific datasource using its name.', inputSchema: GetDatasourceByNameSchema, handler: async (params, context: ToolContext) => { try { const client = new GrafanaClient(context.config.grafanaConfig); const datasource = await client.getDatasourceByName(params.name); return createToolResult(datasource); } catch (error: any) { return createErrorResult(error.message); } }, };
- src/tools/datasource.ts:13-15 (schema)Zod schema defining the input for the tool: an object with a required 'name' string parameter.const GetDatasourceByNameSchema = z.object({ name: z.string().describe('The name of the datasource'), });
- src/cli.ts:105-105 (registration)Call to registerDatasourceTools which registers the get_datasource_by_name tool (along with others) on the MCP server, conditional on 'datasource' tools being enabled.registerDatasourceTools(server);
- Supporting method in GrafanaClient class that makes the Grafana API request to fetch a datasource by its name and handles errors.async getDatasourceByName(name: string): Promise<Datasource> { try { const response = await this.client.get(`/api/datasources/name/${name}`); return response.data; } catch (error) { this.handleError(error); } }