grafana/mcp-grafana

Strategy for managing context windows with Dashboard JSON

OpeOnikute opened this issue · 2 comments

We eventually want LLMs to understand and possibly modify dashboards. The best way to do this is to access the dashboard JSON. An alternative is to provide a screenshot of the dashboard to a model that can understand images, which doesn't scale and can miss crucial context.

Providing modification tools is fairly trivial, but we need to be careful about context windows. Dashboard JSONs can be very large and users can use up their context limits without knowing. We can use this issue to discuss possible solutions, while adding disclaimers in the code for a start.

Some early thoughts:

  • We could aim to provide the dashboard JSON to LLMs (via the get_dashboard_via_uid tool) only once. We then instruct the LLM to only send specific modifications. The update_dashboard tool can be built to take these specific updates instead, and validate them before applying.
  • We could also provide features in get_dashboard_via_uid that can fetch only specific parts of the dashboard. Maybe it could even be a new, unique tool like get_dashboard_property. LLMs can then use this to fetch only the context they need.

I can see possible use-cases for both, and a complete solution would probably involve more features.

We could leverage jsonpath for this too. It would let us update just specific parts of the JSON and then merge back into the original.

@sd2k suggested this in our recent chat - definitely worth exploring that approach as well.

If Grafana MCP server supports updating or creating a dashboard based on dashboard definitions with Grafonnet, it might help with this issue because Jsonnet syntax is much more compact than JSON.