Skip to content

feat: include only Grafana-connected tools#595

Open
Shaik-Sirajuddin wants to merge 7 commits intografana:mainfrom
Shaik-Sirajuddin:add_only_supported_tools
Open

feat: include only Grafana-connected tools#595
Shaik-Sirajuddin wants to merge 7 commits intografana:mainfrom
Shaik-Sirajuddin:add_only_supported_tools

Conversation

@Shaik-Sirajuddin
Copy link

@Shaik-Sirajuddin Shaik-Sirajuddin commented Feb 24, 2026

Initialize data source tools connected to grafana instance , skips non connected tools

Addresses #572

Updated Functionality :

connected-only flag to enable auto discovery

  1. server auto discovers connected datasources
  2. adds tools of connected datasource when source is enabled via flags

Test Strategy :

  • Pass pyroscope ( or any other datasource ) via enabled-tools which is not used in grafana instance

  • Start mcpserver normally

  • Verify the pyroscope tools are present by calling /list_tools

  • Start mcp server with connected-only flag

  • Verify pyroscope tools are now not visible

  • Verify Promethues , loki , e.t.c connected tools are visible


Note

Medium Risk
Changes when and how tools are registered (startup vs per-session, conditional on datasource discovery), which can affect tool visibility and session behavior across transports; scope is contained to tool registration paths.

Overview
Adds a new --connected-only flag that switches datasource tool registration from static startup registration to runtime discovery against the Grafana datasource list, so only tools for datasource types that are both enabled via flags and present in the Grafana instance are broadcast.

Implements discovery/registration in ToolManager for both stdio (server-wide InitDiscoverAndRegister) and HTTP/SSE (per-session DiscoverAndRegisterToolsSession via hooks), and refactors datasource tool packages to expose Get*Tools() factories plus datasource-type constants so discovery can map datasource types to tool sets. Includes unit tests validating sync.Once behavior for discovery initialization under concurrent/sequential access.

Written by Cursor Bugbot for commit 1839fc3. This will update automatically on new commits. Configure here.

@Shaik-Sirajuddin Shaik-Sirajuddin requested a review from a team as a code owner February 24, 2026 06:27
@CLAassistant
Copy link

CLAassistant commented Feb 24, 2026

CLA assistant check
All committers have signed the CLA.

@Shaik-Sirajuddin Shaik-Sirajuddin changed the title feat: Add Only Connected Tools of grafana feat: Add only data source tools connected to grafana instance Feb 24, 2026
@Shaik-Sirajuddin Shaik-Sirajuddin changed the title feat: Add only data source tools connected to grafana instance feat: Add only data source tools connected to grafana Feb 24, 2026
}
slog.Info("Registered Tools of discovered datasources for session ", "sessionId", sessionID, "count", len(tools))
})
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Connected-only doesn’t verify datasource health

Medium Severity

connected-only discovery treats grafana.Datasources.GetDataSources() results as “connected” and registers tools based only on datasource.Type presence, without checking datasource connectivity/health. This can expose tools for misconfigured or disconnected datasources, contradicting the connected-only flag’s documented behavior.

Additional Locations (1)

Fix in Cursor Fix in Web

@Shaik-Sirajuddin Shaik-Sirajuddin changed the title feat: Add only data source tools connected to grafana feat: include only Grafana-connected tools Feb 24, 2026
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Bugbot Autofix is ON, but it could not run because the branch was deleted or merged before Autofix could start.

mayBeEnabledTool(tools.CloudWatchDatasourceType, dt.cloudwatch, &enabledMap, enabledTools)
mayBeEnabledTool(tools.ClickHouseDatasourceType, dt.clickhouse, &enabledMap, enabledTools)

return enabledMap
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Datasource type mismatch breaks Pyroscope and ClickHouse discovery

High Severity

toolsState uses datasource type constants like tools.PyroscopeDataSourceType ("grafana-pyroscope-datasource") and tools.ClickHouseDatasourceType ("grafana-clickhouse-datasource") as the category argument to mayBeEnabledTool, which checks slices.Contains(enabled, category). However, the enabled-tools flag uses short names like "pyroscope" and "clickhouse". Since "grafana-pyroscope-datasource" will never match "pyroscope" in the enabled list, these datasources are never added to the enabledTools map and will always be skipped during discovery, even when they are connected and explicitly enabled.

Additional Locations (1)

Fix in Cursor Fix in Web

obs.NetworkTransport = mcpconv.NetworkTransportTCP
}

if err := run(transport, *addr, *basePath, *endpointPath, parseLevel(*logLevel), dt, grafanaConfig, tls, obs); err != nil {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stateless streamable-http breaks connected-only session tools

Medium Severity

WithStateLess(dt.proxied) makes the streamable-http server stateless when --disable-proxied is set. But the hook registration condition was changed to !dt.proxied || tc.onlyConnected, enabling hooks even when proxied is disabled. When both --disable-proxied and --connected-only are set, the server is stateless yet DiscoverAndRegisterToolsSession attempts to use AddSessionTools, which requires session tracking. The connected-only discovery silently fails on this transport combination.

Additional Locations (1)

Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants