get_datasource_by_uid
Retrieve detailed information about a specific Grafana datasource using its unique identifier (UID) to streamline data access and management.
Instructions
Retrieves detailed information about a specific datasource using its UID.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| uid | Yes | The uid of the datasource |
Implementation Reference
- src/tools/datasource.ts:42-55 (handler)The ToolDefinition object defining the 'get_datasource_by_uid' tool, including its handler function that instantiates GrafanaClient and calls getDatasourceByUid.export const getDatasourceByUid: ToolDefinition = { name: 'get_datasource_by_uid', description: 'Retrieves detailed information about a specific datasource using its UID.', inputSchema: GetDatasourceByUidSchema, handler: async (params, context: ToolContext) => { try { const client = new GrafanaClient(context.config.grafanaConfig); const datasource = await client.getDatasourceByUid(params.uid); return createToolResult(datasource); } catch (error: any) { return createErrorResult(error.message); } }, };
- src/tools/datasource.ts:9-11 (schema)Zod schema defining the input parameters for the 'get_datasource_by_uid' tool (requires 'uid' string).const GetDatasourceByUidSchema = z.object({ uid: z.string().describe('The uid of the datasource'), });
- src/tools/datasource.ts:72-76 (registration)Function that registers the datasource-related tools, including 'get_datasource_by_uid', to the MCP server.export function registerDatasourceTools(server: any) { server.registerTool(listDatasources); server.registerTool(getDatasourceByUid); server.registerTool(getDatasourceByName); }
- GrafanaClient helper method that performs the actual API request to Grafana to fetch datasource by UID.async getDatasourceByUid(uid: string): Promise<Datasource> { try { const response = await this.client.get(`/api/datasources/uid/${uid}`); return response.data; } catch (error) { this.handleError(error); } }