feat: multi-instance registry and automatic token refresh on 401#23
feat: multi-instance registry and automatic token refresh on 401#23harikaduyu wants to merge 1 commit into
Conversation
Add a registry config format so a single gq process (and a single MCP
server) can serve multiple Grafana instances without restart.
- config: auto-detect registry vs single-instance by presence of
'instances' key in GRAFANA_CONFIG file
- config: Registry type with per-instance InstanceConfig; top-level
token_command with {url} substitution, overridable per instance
- client: TokenCommand field; on 401, run token_command via sh -c,
update in-memory token, retry once
- mcp: registry mode adds required 'instance' param to all tools;
single clientFunc pattern eliminates handler duplication
- mcp: per-instance client cache preserves refreshed tokens across calls
- cli: --instance flag on query/metrics/instant subcommands
Co-authored-by: opencode <opencode@noreply.opencode.ai>
Co-authored-by: GitHub Copilot <copilot@noreply.github.com>
|
I have read the CLA Document and I hereby sign the CLA 1 out of 2 committers have signed the CLA. Warning 1 commit in this PR was authored by an email address that is not linked to any GitHub user, so we cannot tell whether the author has signed the CLA. Unlinked author:
To unblock this PR, do one of the following:
|
What did you do?
GRAFANA_CONFIGfile can now define multiple named Grafana instances under aninstanceskeyurlvsinstancesat the top leveltoken_commandfield (single-instance and registry) — a shell command run viash -con 401; stdout becomes the new token and the request is retried oncetoken_commandwith{url}substitution applied per instance, overridable per instanceinstanceparameter to all four tools; a per-session client cache preserves refreshed tokens across calls--instanceflag added toquery,metrics, andinstantsubcommandsWhy did you do it?
Two problems:
Token expiry caused silent failures — the MCP server read the token once at startup; after expiry every call returned 401 with no recovery.
token_command+ on-401 retry makes this fully automatic.One-MCP-per-instance doesn't scale — with 6+ Grafana instances, each needing its own MCP server entry, context slots, and manual token management. The registry collapses N servers into one, with
instanceas a tool parameter.Checklist