generate_deeplink
Create direct links to Grafana dashboards, panels, and Explore queries with custom time ranges and parameters for easy sharing and access.
Instructions
Generate deeplink URLs for Grafana resources. Supports dashboards, panels, and Explore queries
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| dashboardUid | No | Dashboard UID (required for dashboard and panel types) | |
| datasourceUid | No | Datasource UID (required for explore type) | |
| panelId | No | Panel ID (required for panel type) | |
| queryParams | No | Additional query parameters | |
| resourceType | Yes | Type of resource | |
| timeRange | No | Time range for the link |
Implementation Reference
- src/tools/navigation.ts:22-83 (handler)The core handler function for the 'generate_deeplink' tool that constructs Grafana deeplink URLs for dashboards, panels, or explore views based on input parameters, time range, and query params using the Grafana base URL from context.handler: async (params, context: ToolContext) => { try { const baseUrl = context.config.grafanaConfig.url; let url = ''; const queryParams = new URLSearchParams(); // Add time range if provided if (params.timeRange) { queryParams.append('from', params.timeRange.from); queryParams.append('to', params.timeRange.to); } // Add additional query params if (params.queryParams) { Object.entries(params.queryParams).forEach(([key, value]) => { queryParams.append(key, String(value)); }); } switch (params.resourceType) { case 'dashboard': if (!params.dashboardUid) { return createErrorResult('dashboardUid is required for dashboard type'); } url = `${baseUrl}/d/${params.dashboardUid}`; break; case 'panel': if (!params.dashboardUid || params.panelId === undefined) { return createErrorResult('dashboardUid and panelId are required for panel type'); } url = `${baseUrl}/d/${params.dashboardUid}`; queryParams.append('viewPanel', params.panelId.toString()); break; case 'explore': if (!params.datasourceUid) { return createErrorResult('datasourceUid is required for explore type'); } url = `${baseUrl}/explore`; queryParams.append('left', JSON.stringify({ datasource: params.datasourceUid, queries: [], range: params.timeRange || { from: 'now-1h', to: 'now' }, })); break; default: return createErrorResult(`Unknown resource type: ${params.resourceType}`); } // Append query params to URL const queryString = queryParams.toString(); if (queryString) { url += `?${queryString}`; } return createToolResult({ url }); } catch (error: any) { return createErrorResult(error.message); } },
- src/tools/navigation.ts:5-15 (schema)Zod input schema defining parameters for the generate_deeplink tool, including resource type, UIDs, time range, and query params.const GenerateDeeplinkSchema = z.object({ resourceType: z.enum(['dashboard', 'panel', 'explore']).describe('Type of resource'), dashboardUid: z.string().optional().describe('Dashboard UID (required for dashboard and panel types)'), panelId: z.number().optional().describe('Panel ID (required for panel type)'), datasourceUid: z.string().optional().describe('Datasource UID (required for explore type)'), timeRange: z.object({ from: z.string().describe('Start time (e.g., "now-1h")'), to: z.string().describe('End time (e.g., "now")'), }).optional().describe('Time range for the link'), queryParams: z.record(z.string()).optional().describe('Additional query parameters'), });
- src/tools/navigation.ts:86-88 (registration)Registration function for navigation tools that directly registers the generate_deeplink tool with the MCP server.export function registerNavigationTools(server: any) { server.registerTool(generateDeeplink); }
- src/cli.ts:131-133 (registration)Main entrypoint call to register navigation tools (including generate_deeplink) conditionally if the 'navigation' tool category is enabled.if (enabledTools.has('navigation')) { registerNavigationTools(server); }