Skip to content

feat(tools): add tools for InfluxDB datasource#614

Open
Shaik-Sirajuddin wants to merge 27 commits intografana:mainfrom
Shaik-Sirajuddin:influx_datasource
Open

feat(tools): add tools for InfluxDB datasource#614
Shaik-Sirajuddin wants to merge 27 commits intografana:mainfrom
Shaik-Sirajuddin:influx_datasource

Conversation

@Shaik-Sirajuddin
Copy link
Copy Markdown
Contributor

@Shaik-Sirajuddin Shaik-Sirajuddin commented Mar 2, 2026

Introduce InfluxDB Tools with support for SQL , FLUX , INFLUQL Queries

Graphana provides native backend for InfluxDB Datasources ,
Addresses #176 suggestions for datasource support in mcp-grafana

Technical Details :
Utilizes /api/ds/query/ endpoint for queries
Tools make use of the parameterized datasource 's query language (one of sql/flux/influxql) to execute queries

Tools Added:

  • query_influx
  • list_buckets_influxdb
  • list_measurements_influxdb
  • list_tag_keys_influxdb
  • list_field_keys_influxdb

Additional

  • Integration Tests Added
  • Updated Docker Compose For InfluxDB Containers

Note

Medium Risk
Adds a new InfluxDB query surface (SQL/Flux/InfluxQL) with query rewriting/limit enforcement and expands the local dev/test stack, which could affect query correctness and integration behavior across datasources.

Overview
Adds first-class InfluxDB support via new MCP tools: query_influxdb plus discovery helpers to list buckets (Flux-only), measurements, tag keys, and field keys, with time range parsing and enforced per-query limits.

Refactors /api/ds/query plumbing by introducing shared types in pkg/grafana/datasource.go and switching ClickHouse, CloudWatch, and Cloud Monitoring Prometheus backend code/tests to use grafana.DSQueryResponse instead of bespoke response structs.

Extends the integration environment with InfluxDB v2 + v3 services, seeded sample data, and provisioned InfluxDB datasources in docker-compose.yaml/Grafana provisioning; also wires the new tool category into cmd/mcp-grafana with a --disable-influxdb flag.

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

@Shaik-Sirajuddin Shaik-Sirajuddin requested a review from a team as a code owner March 2, 2026 08:14
@cla-assistant
Copy link
Copy Markdown

cla-assistant bot commented Mar 18, 2026

CLA assistant check
All committers have signed the CLA.

Comment on lines +114 to +139
type influxQueryResponse struct {
Results map[string]struct {
Status int `json:"status,omitempty"`
Frames []struct {
Schema struct {
Name string `json:"name,omitempty"`
RefID string `json:"refId,omitempty"`
Fields []struct {
Labels struct {
Field string `json:"_field,omitempty"`
} `json:"labels"`
Name string `json:"name"`
Type string `json:"type"`
TypeInfo struct {
Frame string `json:"frame,omitempty"`
} `json:"typeInfo,omitempty"`
Config map[string]interface{} `json:"config,omitempty"`
} `json:"fields"`
} `json:"schema,omitempty"`
Data struct {
Values [][]interface{} `json:"values"`
} `json:"data"`
} `json:"frames,omitempty"`
Error string `json:"error,omitempty"`
} `json:"results"`
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This structure is shared by all responses to /api/ds/query so we shouldn't need to define it multiple times. If other datasources are using it then we can factor it out and reuse it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Also /api/ds/query is frequently used by across tools ,
Having a grafana client definition with ds query method to start with may improve reusability
Should i address this via another PR ? ?


var QueryInflux = mcpgrafana.MustTool(
"query_influx",
"Queries InfluxDB datasource, supports one of Flux, SQL, or InfluxQL query languages configured with the datasource.",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This could do with being more detailed. In particular, if the type must match that configured on the datasource, then we should include brief instructions for how to find it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

updated the description to include expected in order tool usage

Shaik-Sirajuddin and others added 3 commits March 23, 2026 09:50
Co-authored-by: Ben Sully <ben.sully88@gmail.com>
Co-authored-by: Ben Sully <ben.sully88@gmail.com>
@Shaik-Sirajuddin Shaik-Sirajuddin requested a review from sd2k March 25, 2026 14:56
@Shaik-Sirajuddin
Copy link
Copy Markdown
Contributor Author

Addressed suggestions , Could you take a look @sd2k when you have a chance

@sd2k sd2k added the cla: yes Contributor License Agreement is signed label Mar 26, 2026
@sd2k
Copy link
Copy Markdown
Collaborator

sd2k commented Mar 26, 2026

Hi @Shaik-Sirajuddin, I had Claude do another pass of a review here. Here's some feedback I'd like to see before merging:


Summary

Adds InfluxDB datasource support with query, bucket, measurement, tag, and field key listing tools across SQL/Flux/InfluxQL query languages. Good refactoring to extract shared DS query response types into pkg/grafana. However, there are several correctness, design, and security issues that should be addressed before merging.

Issues

  • SECURITY: InfluxQL quoting (quoteStringAsInfluxQLLiteral) delegates to quoteStringAsFluxLiteral which uses double quotes and escapes backslash/double-quote. But InfluxQL identifiers use double quotes while string literals use single quotes — SHOW TAG KEYS FROM "measurement" treats the arg as an identifier, not a string. A measurement name containing a double-quote could break out. The SQL quoteStringAsLiteral correctly uses single quotes, but the InfluxQL variant should be reviewed for correctness against the InfluxQL spec (SHOW TAG KEYS FROM expects unquoted or double-quoted identifiers, not double-quoted strings).
  • CORRECTNESS: Response body is read twice on non-200 status (influxdb.go:210-211 reads the full body for the error message, then line 215-216 tries to read again from the same resp.Body). The second read will get nothing because the body was already consumed in the error path. The code returns on the error path so this is not a runtime bug, but the full error body is read without size limit — a malicious/misconfigured server could send an unbounded response that causes OOM. Other tools (clickhouse, cloudwatch) use unmarshalJSONWithLimitMsg; InfluxDB should too.
  • CORRECTNESS: Inconsistent casing in pkg/grafana/datasource.go — DSQueryPayload, DSQueryFrameData, DSQueryResponse use 'DS' prefix, while DsQueryFrameField, DsQueryFrameSchema, DsQueryFrame, DsQueryResult use 'Ds' prefix. Pick one convention (DS is more standard Go for acronyms).
  • CORRECTNESS: The comment on line 1 of pkg/grafana/datasource.go is malformed: '// package grafana' should either be a proper doc comment or removed (Go convention is to use the comment for package documentation, not repeat the declaration).
  • DESIGN: tool names are inconsistent with MCP tool naming — query_influx vs list_influxdb_buckets, list_measurements_influxdb, list_tag_keys_influxdb, list_field_keys_influxdb. The PR description says tools are named list_buckets_influxdb etc. but the actual code uses list_influxdb_buckets for buckets but *_influxdb suffix for others. Pick one pattern consistently.
  • DESIGN: DatasourceRef type in influxdb.go duplicates a concept that likely exists elsewhere in the codebase. The InfluxQLQuery struct name is misleading — it's used for all three query types (SQL, Flux, InfluxQL), not just InfluxQL.
  • CORRECTNESS: testdata/tools/influxdb/user is an empty file with no apparent purpose — appears to be accidentally committed.
  • DESIGN: enforceQueryLimit wraps user SQL queries as subqueries by prepending '(' — this changes query semantics and may break queries that use CTEs, window functions, or other SQL features that don't work as subqueries. The Flux limit append also doesn't account for queries that already have a |>limit() operator — it would just append another one (unlike the InfluxQL path which detects and replaces existing limits).
  • CORRECTNESS: The error path in influxdb.go:209-211 reads the full response body with no size limit (io.ReadAll without LimitReader), while the success path correctly uses a 10MB LimitReader. A large error response could cause OOM.

Suggestions

  • Use unmarshalJSONWithLimitMsg consistently with other datasource tools instead of raw json.Unmarshal, and apply LimitReader to the error body path too.
  • Normalize type name casing in pkg/grafana/datasource.go to consistently use 'DS' prefix (DSQueryFrameField, DSQueryFrameSchema, etc.).
  • Rename InfluxQLQuery to something generic like influxDBQueryPayload since it serves all three query types.
  • Add unit tests for the quoting functions with adversarial inputs (e.g., measurement names containing quotes, backslashes, newlines).
  • Remove the empty testdata/tools/influxdb/user file.
  • Fix typo in main.go capability description: 'datasourcs' -> 'datasources', and remove extra spaces before colons/commas.
  • Consider detecting existing |>limit() in Flux queries before appending another one, similar to how InfluxQL limits are handled.
  • The docker-compose.yaml file is missing a trailing newline — add one to avoid diff noise in future changes.
  • Add missing trailing newlines to testdata/tools/influxdb/ secret files and seed scripts.

@Shaik-Sirajuddin
Copy link
Copy Markdown
Contributor Author

Sure , I will reflect the suggested improvements

Copy link
Copy Markdown

@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.

Fix All in Cursor

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

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

Labels

cla: yes Contributor License Agreement is signed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants