Skip to main content
Glama
0xteamhq

Grafana MCP Server

by 0xteamhq

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
NameRequiredDescriptionDefault
uidYesThe uid of the datasource

Implementation Reference

  • 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);
        }
      },
    };
  • 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'),
    });
  • 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);
      }
    }

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