Skip to content

feat(tools): add VictoriaLogs datasource support#634

Open
kylemclaren wants to merge 3 commits intografana:mainfrom
kylemclaren:feat/victorialogs-support
Open

feat(tools): add VictoriaLogs datasource support#634
kylemclaren wants to merge 3 commits intografana:mainfrom
kylemclaren:feat/victorialogs-support

Conversation

@kylemclaren
Copy link
Copy Markdown

@kylemclaren kylemclaren commented Mar 6, 2026

Summary

  • Adds 5 new tools for querying VictoriaLogs datasources (victoriametrics-logs-datasource type)
  • query_victorialogs — Execute LogsQL queries (POST /select/logsql/query)
  • list_victorialogs_field_names — List available field names
  • list_victorialogs_field_values — Get values for a specific field with hit counts
  • query_victorialogs_hits — Log volume over time buckets
  • query_victorialogs_streams — List matching log streams with hit counts

Why

The existing Loki tools fail against VictoriaLogs datasources because VictoriaLogs uses different API endpoints (/select/logsql/* vs /loki/api/v1/*), a different query language (LogsQL vs LogQL), and returns NDJSON instead of Loki's wrapped JSON format.

Implementation notes

  • Follows the Loki tool patterns for client construction, transport stack, and tool registration
  • Handles VictoriaLogs' NDJSON (newline-delimited JSON) response format
  • Uses POST with application/x-www-form-urlencoded for the query endpoint, GET for metadata
  • Applies limits via LogsQL pipe syntax (| limit N) rather than query params
  • Enabled by default; can be disabled with --disable-victorialogs
  • Adds VictoriaLogs service to docker-compose and datasource provisioning for integration tests

Test plan

  • make lint-jsonschema passes (no unescaped commas)
  • go build ./... compiles successfully
  • make test-unit passes
  • make test-integration with docker-compose (requires VictoriaLogs container)
  • Manual testing against a Grafana instance with VictoriaLogs datasource

🤖 Generated with Claude Code


Note

Medium Risk
Adds a new datasource integration with multiple HTTP query paths and NDJSON parsing, and enables the tool category by default, which could affect runtime behavior and integration test/dev environments.

Overview
Adds a new VictoriaLogs tool category with five read-only tools (query_victorialogs, field name/value discovery, hits, and streams) that query Grafana’s datasource proxy using VictoriaLogs /select/logsql/* endpoints and handle NDJSON responses.

Wires the category into server startup and CLI (victorialogs enabled by default, --disable-victorialogs added), and updates docs/tool table accordingly. Extends the local dev/integration setup by provisioning a VictoriaLogs datasource and adding a victorialogs container plus integration tests for the new tools.

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

Add 5 new tools for querying VictoriaLogs datasources:
- query_victorialogs: Execute LogsQL queries via POST /select/logsql/query
- list_victorialogs_field_names: List available fields via /select/logsql/field_names
- list_victorialogs_field_values: Get field values with hit counts via /select/logsql/field_values
- query_victorialogs_hits: Log volume over time via /select/logsql/hits
- query_victorialogs_streams: List matching streams via /select/logsql/streams

Key implementation details:
- Handles VictoriaLogs NDJSON (newline-delimited JSON) response format
- Uses POST with application/x-www-form-urlencoded for query endpoint
- Applies limits via LogsQL pipe syntax (| limit N)
- Follows existing Loki tool patterns for client construction and transport stack
- Enabled by default; can be disabled with --disable-victorialogs

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@kylemclaren kylemclaren requested a review from a team as a code owner March 6, 2026 11:09
@cla-assistant
Copy link
Copy Markdown

cla-assistant bot commented Mar 6, 2026

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Address review feedback from cursor bot:
- Fix hits endpoint: parse as JSON {"hits":[...]} not NDJSON
- Fix streams endpoint: parse as JSON {"values":[...]} not NDJSON
- Fix field_names endpoint: parse as JSON {"values":[...]} not NDJSON
- Fix field_values endpoint: parse as JSON {"values":[...]} not NDJSON
- Remove unused VictoriaLogsLogEntry type
- Reuse getDefaultTimeRange from loki.go instead of duplicate

Only /select/logsql/query returns NDJSON; all other endpoints return
a single JSON object with wrapped arrays.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Use VictoriaLogsHit directly in victoriaLogsHitsResponse since the types
are structurally identical, eliminating unnecessary indirection.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Collaborator

@sd2k sd2k left a comment

Choose a reason for hiding this comment

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

Hi! thanks for the contribution.

I'm endeavouring to avoid adding new tools if possible, since this MCP server's tools already adds 14-15000 tokens. Rather than adding a whole new suite of tools for VL, I think it makes sense to merge this with query_loki and the other Loki related tools. We can do so by abstracting the 'backend' away and switching based on datasource type, and renaming the tools to query_logs etc instead.

Happy to accept a PR that makes that change, if you're up for it.

@kylemclaren
Copy link
Copy Markdown
Author

good call @sd2k -- will look into it

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.

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

}
}

return &QueryVictoriaLogsHitsResult{Data: resp.Hits}, nil
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hits result Data field can be nil unlike other endpoints

Medium Severity

queryVictoriaLogsHits returns resp.Hits directly without nil-checking, so Data can be nil when the response body is empty or the JSON lacks a hits key. This causes JSON serialization to produce {"data":null} instead of {"data":[]}. Every other endpoint in this file ensures a non-nil slice — queryVictoriaLogs has an explicit nil guard, queryVictoriaLogsStreams uses make(), listVictoriaLogsFieldValues uses make(), and listVictoriaLogsFieldNames uses make().

Fix in Cursor Fix in Web

type VictoriaLogsStream struct {
Value string `json:"value"`
Hits int64 `json:"hits"`
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Duplicate struct types with identical fields

Low Severity

VictoriaLogsStream and VictoriaLogsFieldValue are structurally identical types — both have Value string and Hits int64 with the same JSON tags. One type could be reused for both the streams and field values endpoints, reducing unnecessary duplication. The comment on VictoriaLogsFieldValue even says it's "Used by field_names, field_values, and streams endpoints," yet streams uses its own separate copy.

Additional Locations (1)

Fix in Cursor Fix in Web

@elee1766
Copy link
Copy Markdown

i have my own fork where i added victorialogs support for my own needs.

it was incredibly useful to be able to expose the raw underlying victorialogs endpoint for queries. query_loki is not syntax compatible with victoria logs docs, and be able to do actual queries with matching docs was very useful.

it would at least be i think useful to expose query_victorialogs tool, even if other tools are hidden behind abstraction.

@sd2k sd2k added the cla: no Contributor License Agreement is not signed label Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: no Contributor License Agreement is not signed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants