Skip to main content
Glama
0xteamhq

Grafana MCP Server

by 0xteamhq

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
NameRequiredDescriptionDefault
nameYesThe name of the datasource

Implementation Reference

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

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