Skip to content

feat: MCP integration for AI tools#1156

Merged
zeitlinger merged 25 commits into
mainfrom
mcp-integration
Apr 9, 2026
Merged

feat: MCP integration for AI tools#1156
zeitlinger merged 25 commits into
mainfrom
mcp-integration

Conversation

@zeitlinger
Copy link
Copy Markdown
Member

Closes #1091

Summary

  • Enables MCP servers so AI coding tools (Claude, Cursor, etc.) can query the LGTM stack
  • Tempo native MCP for TraceQL queries (built-in, just needs config flag)
  • mcp-grafana for PromQL, LogQL, dashboards (external, SA token bootstrapped)
  • Generates /etc/lgtm/mcp.json at startup — one config block for any MCP client
  • Opt-in collector debug exporter via OTEL_COLLECTOR_DEBUG_EXPORTER=true
  • Full docs at docs/mcp-integration.md

Setup

docker exec lgtm cat /etc/lgtm/mcp.json

Paste into your AI tool's MCP configuration.

Test plan

  • Start container, verify mcp.json is generated with valid SA token
  • Connect mcp-grafana, query metrics and logs
  • Connect Tempo MCP, query traces
  • Enable OTEL_COLLECTOR_DEBUG_EXPORTER=true, verify debug output in logs
  • OATS acceptance tests pass

Copilot AI review requested due to automatic review settings March 12, 2026 14:35
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds documentation and container-side scaffolding to support Model Context Protocol (MCP) integrations so AI coding tools can query LGTM data (traces/metrics/logs/dashboards), plus an optional OpenTelemetry Collector debug-exporter overlay.

Changes:

  • Document MCP setup and add a new MCP integration guide.
  • Enable Tempo’s MCP server and emit an MCP config JSON (including a Grafana service-account token) from the container.
  • Add an opt-in OTEL Collector “debug exporter” overlay and extend acceptance test log expectations.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
README.md Adds a short “AI Tool Integration (MCP)” entry point and MCP link.
docs/mcp-integration.md New guide describing MCP setup, including Grafana + Tempo MCP configuration.
docker/run-all.sh Generates Grafana service account token and writes /etc/lgtm/mcp.json, plus startup log hints.
docker/tempo-config.yaml Enables Tempo MCP server in the query frontend.
docker/run-otelcol.sh Adds OTEL_COLLECTOR_DEBUG_EXPORTER flag to layer an extra collector config.
docker/otelcol-config-debug.yaml New overlay config that adds debug exporters to traces/metrics/logs pipelines.
examples/python/oats.yaml Extends acceptance test to assert the new MCP-related startup log lines.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread docker/run-all.sh Outdated
Comment thread docker/run-all.sh Outdated
Comment thread docker/run-otelcol.sh Outdated
Comment thread docker/otelcol-config-debug.yaml Outdated
Comment thread docs/mcp-integration.md Outdated
Comment thread docs/mcp-integration.md
Comment thread examples/python/oats.yaml Outdated
Comment thread README.md Outdated
Copilot AI review requested due to automatic review settings March 12, 2026 15:03
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Comments suppressed due to low confidence (1)

docker/run-otelcol.sh:43

  • When both OTEL_EXPORTER_OTLP_ENDPOINT (adds otelcol-config-export-http.yaml) and OTEL_COLLECTOR_DEBUG_EXPORTER (adds otelcol-config-debug.yaml) are enabled, the later debug config replaces the pipelines' exporters lists, which drops otlphttp/external and stops exporting to the external OTLP endpoint. Consider generating a combined config (or a separate debug+external config) so the exporters list includes both debug/* and otlphttp/external when both flags are set (instead of last-one-wins).
debug_config_file=""
if [[ ${OTEL_COLLECTOR_DEBUG_EXPORTER:-false} == "true" ]]; then
	echo "Enabling debug exporter for OpenTelemetry Collector"
	debug_config_file="--config=file:./otelcol-config-debug.yaml"
fi

run_with_logging "OpenTelemetry Collector ${OPENTELEMETRY_COLLECTOR_VERSION}" "${ENABLE_LOGS_OTELCOL:-false}" \
	./otelcol-contrib/otelcol-contrib --feature-gates service.profilesSupport --config=file:./otelcol-config.yaml ${secondary_config_file} ${debug_config_file}


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread docker/run-all.sh Outdated
Comment thread docker/run-all.sh Outdated
Comment thread build-lgtm.sh Outdated
Copilot AI review requested due to automatic review settings March 12, 2026 15:28
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread docker/run-all.sh Outdated
Comment thread docker/run-all.sh Outdated
Comment thread build-lgtm.sh Outdated
Comment thread README.md Outdated
Comment thread docs/mcp-integration.md Outdated
Copilot AI review requested due to automatic review settings March 12, 2026 15:49
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 7 comments.

Comments suppressed due to low confidence (2)

build-lgtm.sh:25

  • This now prefers Podman over Docker when both are installed, but still unconditionally runs buildx build. On many systems podman buildx isn’t available by default, so this can break builds that previously succeeded with Docker. Consider checking for buildx support (or falling back to podman build / using Docker when available), or allow users to override the runtime selection.
if command -v podman >/dev/null 2>&1; then
	RUNTIME=podman
elif command -v docker >/dev/null 2>&1; then
	RUNTIME=docker
else
	echo "Unable to find a suitable container runtime such as Docker or Podman. Exiting."
	exit 1
fi

if [ "$RUNTIME" = "podman" ]; then
	TAG="localhost/grafana/otel-lgtm:${RELEASE}"
else
	TAG="grafana/otel-lgtm:${RELEASE}"
fi

$RUNTIME buildx build -f docker/Dockerfile docker --tag "$TAG" --build-arg LGTM_VERSION="${RELEASE}"

docker/run-otelcol.sh:43

  • When both OTEL_EXPORTER_OTLP_ENDPOINT (external export) and OTEL_COLLECTOR_DEBUG_EXPORTER=true are set, this passes two extra --config files that both override service.pipelines.*.exporters (otelcol-config-export-http.yaml and otelcol-config-debug.yaml). Depending on config merge precedence, the later file can clobber the earlier one, dropping the external exporter (or the debug exporter). Consider generating a combined exporters list (external + debug) or ensuring the overlay config doesn’t overwrite other overlays’ exporter settings.
debug_config_file=""
if [[ ${OTEL_COLLECTOR_DEBUG_EXPORTER:-false} == "true" ]]; then
	echo "Enabling debug exporter for OpenTelemetry Collector"
	debug_config_file="--config=file:./otelcol-config-debug.yaml"
fi

run_with_logging "OpenTelemetry Collector ${OPENTELEMETRY_COLLECTOR_VERSION}" "${ENABLE_LOGS_OTELCOL:-false}" \
	./otelcol-contrib/otelcol-contrib --feature-gates service.profilesSupport --config=file:./otelcol-config.yaml ${secondary_config_file} ${debug_config_file}


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread run-lgtm.sh
Comment thread docs/mcp-integration.md
Comment thread docs/mcp-integration.md
Comment thread docker/run-all.sh Outdated
Comment thread docker/run-all.sh Outdated
Comment thread docker/run-all.sh Outdated
Comment thread README.md
- Auto-create Grafana service account and token at startup
- Generate /etc/lgtm/mcp.json (mcp-grafana + Tempo native MCP)
- Generate /etc/lgtm/claude-mcp-setup.sh for one-command Claude Code setup
- Add opt-in collector debug exporter (OTEL_COLLECTOR_DEBUG_EXPORTER=true)
- Enable Tempo MCP server, expose port 3200
- Add docs/mcp-integration.md
Copilot AI review requested due to automatic review settings March 12, 2026 16:17
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread docker/run-all.sh
Comment thread docker/run-all.sh Outdated
Comment thread docker/run-all.sh Outdated
Comment thread docker/run-all.sh Outdated
Comment thread docker/run-all.sh Outdated
- Break long curl and otelcol commands to stay under 150 chars
- Remove space before redirects (shfmt: `> file` → `>file`)
- Fix heredoc body indentation for shfmt compliance
Integrate debug exporter config into main's array-based arg handling.
Comment thread docker/run-all.sh Outdated
Comment thread docker/run-all.sh Outdated
Comment thread docker/run-all.sh Outdated
Comment thread docker/run-all.sh Outdated
Comment thread docker/run-all.sh Outdated
Comment thread docker/run-all.sh Outdated
- Extract Grafana credentials and base URL into variables (martincostello)
- Restrict file permissions on token and MCP config files (umask 077)
- Fix README wording: clarify Grafana MCP is client-side, not in-container
- Quote SA token in claude-mcp-setup.sh heredoc
- Use GitHub URL instead of relative path in MCP docs output
Copilot AI review requested due to automatic review settings March 18, 2026 09:36
@zeitlinger zeitlinger requested a review from a team as a code owner March 18, 2026 09:36
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread docker/run-all.sh Outdated
Comment thread docker/run-all.sh Outdated
Comment thread docker/run-all.sh
@zeitlinger zeitlinger marked this pull request as draft March 19, 2026 09:28
@zeitlinger
Copy link
Copy Markdown
Member Author

Keeping in draft - waiting for feedback from human testers

Copilot AI review requested due to automatic review settings April 1, 2026 11:57
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 14 out of 14 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread docker/run-otelcol.bats
Comment thread docker/run-otelcol.bats
Comment thread docker/run-otelcol.bats
Comment thread docker/run-otelcol.bats
Comment thread docker/run-otelcol.bats
Comment thread README.md
@alesj
Copy link
Copy Markdown
Contributor

alesj commented Apr 1, 2026

@zeitlinger any plans to support some non-stdio transport for grafana as well?

@alesj
Copy link
Copy Markdown
Contributor

alesj commented Apr 1, 2026

Btw, when running the mcp image - docker run -i docker.io/grafana/otel-lgtm (or w/o -i),
I cannot shut it down via ctrl-c ...

@zeitlinger
Copy link
Copy Markdown
Member Author

@zeitlinger any plans to support some non-stdio transport for grafana as well?

no, mcp-grafana is a process tool, stdio only by design

that being said, I'd love to try out a CLI based approach too, but this is the first thing that's available

… handling

- Remove brittle MCP log assertions from oats.yaml (only printed when SA
  token creation succeeds, causing test failures on container restarts)
- Clarify docs/mcp-integration.md: Tempo has an in-container HTTP MCP
  endpoint; Grafana uses a client-side uvx mcp-grafana process
- Add --init to docker/podman run in run-lgtm.sh and run-lgtm.ps1 so
  ctrl-c properly forwards signals to container processes
@alesj
Copy link
Copy Markdown
Contributor

alesj commented Apr 1, 2026

no, mcp-grafana is a process tool, stdio only by design

Being a mcp and uvx noob, iiuc mcp-grafana is a separate process that runs,
exposing mcp, and knows how to do queries (for logs, prom, dashboards)?

As such it makes a bit hard for use to wire it I guess,
since we only do Docker images run in devservices.
Dunno how we could also start mcp-grafana ... hence needing a remote transport, afais.

@alesj
Copy link
Copy Markdown
Contributor

alesj commented Apr 1, 2026

Ah, I've been told this is not true ... we could also start uvx ... nice :-)

zeitlinger added a commit to grafana/flint that referenced this pull request Apr 1, 2026
## Summary

- Add `*.bats` to the shellcheck file pattern in `super-linter.sh`
native mode

## Why

Bats test files use bash syntax and shellcheck catches real issues in
them (SC2034 unused variables, SC2314 bats-specific `!` usage, etc.).
Docker super-linter already lints `.bats` files; native mode was missing
the glob pattern, creating a gap where CI catches issues that local
`native-lint` misses.

Discovered while fixing shellcheck errors in
[grafana/docker-otel-lgtm#1156](grafana/docker-otel-lgtm#1156).

The same fix is applied to `run-linters.sh` in #136.

## Test plan

- [ ] `mise run test` passes
Comment thread README.md
Comment thread docker/run-all.sh Outdated
Comment thread docker/run-otelcol.bats
Comment thread docker/run-otelcol.bats
Replace bash parameter expansion one-liner with a readable two-liner.
Add kubectl exec equivalent for Kubernetes users in MCP setup section.
Copilot AI review requested due to automatic review settings April 2, 2026 14:08
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 5 comments.

Comments suppressed due to low confidence (1)

README.md:265

  • The README now documents port-forwarding Tempo on 3200 and suggests mise k8s-port-forward as an alternative, but the k8s-port-forward task in mise.toml still forwards only 3000 4040 4317 4318 9090 (no 3200). This makes the mise shortcut inconsistent with the documented port-forward command; consider updating the mise task to include 3200:3200 as well.
# Configure port forwarding
kubectl port-forward service/lgtm 3000:3000 3200:3200 4040:4040 4317:4317 4318:4318 9090:9090

# Using mise
mise k8s-apply
mise k8s-port-forward
</details>



---

💡 <a href="/grafana/docker-otel-lgtm/new/main?filename=.github/instructions/*.instructions.md" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Add Copilot custom instructions</a> for smarter, more guided reviews. <a href="https://docs.github.com/en/copilot/customizing-copilot/adding-repository-custom-instructions-for-github-copilot" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Learn how to get started</a>.

Comment thread docker/run-otelcol.bats
Comment thread docker/run-otelcol.bats
Comment thread docker/run-otelcol.bats
Comment thread docker/run-otelcol.bats
Comment thread docker/run-all.sh
@zeitlinger zeitlinger marked this pull request as draft April 8, 2026 12:26
@zeitlinger
Copy link
Copy Markdown
Member Author

Put in draft mode - I want to try GCX first

- run-lgtm.sh: explicitly pass OTEL_COLLECTOR_DEBUG_EXPORTER so
  `OTEL_COLLECTOR_DEBUG_EXPORTER=true ./run-lgtm.sh` works as documented
- docker/run-all.sh: extract GRAFANA_SA_URL variable to avoid repeating
  the base URL across all service-account API calls
- docs/mcp-integration.md: add podman exec alternative to TOKEN line
@zeitlinger zeitlinger marked this pull request as ready for review April 8, 2026 14:46
Copilot AI review requested due to automatic review settings April 8, 2026 14:46
@zeitlinger
Copy link
Copy Markdown
Member Author

Put in draft mode - I want to try GCX first

@martincostello as discussed - let's do this PR before trying out a new approach

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread docker/run-otelcol.bats
Comment thread run-lgtm.ps1
Comment thread run-lgtm.ps1
Copy link
Copy Markdown
Member

@martincostello martincostello left a comment

Choose a reason for hiding this comment

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

Looks OK to me modulo the GitHub Copilot comments.

…p.sh

- mise.toml: k8s-port-forward task was missing 3200:3200 even though the README
  documents it in the manual kubectl command
- docker/run-all.sh: quote -e arguments in the generated claude-mcp-setup.sh
  so URLs with special chars don't break the claude mcp add invocation
@zeitlinger zeitlinger enabled auto-merge (squash) April 9, 2026 15:35
@zeitlinger zeitlinger merged commit a905404 into main Apr 9, 2026
17 checks passed
@zeitlinger zeitlinger deleted the mcp-integration branch April 9, 2026 15:42
@alesj
Copy link
Copy Markdown
Contributor

alesj commented Apr 12, 2026

@zeitlinger is there a new image version already out with this cool mcp stuff?
(so that I update it in Quarkus as well ...)

@martincostello
Copy link
Copy Markdown
Member

These changes should be in v0.24.0.

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.

Enable MCP server for tempo

6 participants