Skip to content

Commit 87de73d

Browse files
authored
Merge pull request #29 from grafana/golang
feat: rewrite MCP server in Go
2 parents 23ab161 + 65142f6 commit 87de73d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+3507
-2347
lines changed

.dockerignore

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Git
2+
.git
3+
.gitignore
4+
.github/
5+
6+
# Docker
7+
Dockerfile
8+
.dockerignore
9+
10+
# Build artifacts
11+
bin/
12+
dist/
13+
build/
14+
*.exe
15+
*.exe~
16+
*.dll
17+
*.so
18+
*.dylib
19+
20+
# Go specific
21+
vendor/
22+
go.work
23+
24+
# Testing
25+
*_test.go
26+
**/test/
27+
**/tests/
28+
coverage.out
29+
coverage.html
30+
31+
# IDE and editor files
32+
.idea/
33+
.vscode/
34+
*.swp
35+
*.swo
36+
*~
37+
38+
# OS specific
39+
.DS_Store
40+
Thumbs.db
41+
42+
# Temporary files
43+
tmp/
44+
temp/
45+
*.tmp
46+
*.log
47+
48+
# Documentation
49+
docs/
50+
*.md
51+
LICENSE
52+
53+
# Development tools
54+
.air.toml
55+
.golangci.yml
56+
.goreleaser.yml
57+
58+
# Debug files
59+
debug
60+
__debug_bin

.github/workflows/cloud.yml

-39
This file was deleted.

.github/workflows/go.yml

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Go
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
8+
jobs:
9+
lint:
10+
name: Lint
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
16+
- name: Set up Go
17+
uses: actions/setup-go@v5
18+
with:
19+
go-version: '1.24'
20+
cache: true
21+
22+
- name: Lint
23+
uses: golangci/golangci-lint-action@v3
24+
with:
25+
version: v1.64
26+
27+
test:
28+
name: Test
29+
runs-on: ubuntu-latest
30+
steps:
31+
- name: Checkout code
32+
uses: actions/checkout@v4
33+
34+
# Start the Grafana server.
35+
# Do this early so that it can start up in time for the tests to run.
36+
# We may need to add a wait here.
37+
- name: Start docker-compose services
38+
uses: hoverkraft-tech/[email protected]
39+
with:
40+
compose-file: "docker-compose.yaml"
41+
42+
- name: Set up Go
43+
uses: actions/setup-go@v5
44+
with:
45+
go-version: '1.24'
46+
cache: true
47+
48+
- name: Wait for Grafana server and Prometheus server to start and scrape
49+
run: sleep 30
50+
51+
- name: Run tests
52+
run: make test-all

.github/workflows/python.yml

-47
This file was deleted.

.github/workflows/release.yml

-103
This file was deleted.

Dockerfile

+30-17
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,41 @@
1-
FROM python:3.13-slim AS builder
2-
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
1+
# Build stage
2+
FROM golang:1.24-bullseye AS builder
33

4-
# Change the working directory to the `app` directory
4+
# Set the working directory
55
WORKDIR /app
66

7-
# Install dependencies
8-
RUN --mount=type=cache,target=/root/.cache/uv \
9-
--mount=type=bind,source=uv.lock,target=uv.lock \
10-
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
11-
uv sync --frozen --no-install-project --no-editable
7+
# Copy go.mod and go.sum files
8+
COPY go.mod go.sum ./
129

13-
# Copy the project into the intermediate image
14-
ADD . /app
10+
# Download dependencies
11+
RUN go mod download
1512

16-
# Sync the project
17-
RUN --mount=type=cache,target=/root/.cache/uv \
18-
uv sync --frozen --no-editable
13+
# Copy the source code
14+
COPY . .
1915

20-
FROM python:3.13-slim
16+
# Build the application
17+
RUN go build -o mcp-grafana ./cmd/mcp-grafana
2118

22-
# Copy the environment, but not the source code
23-
COPY --from=builder --chown=app:app /app/.venv /app/.venv
19+
# Final stage
20+
FROM debian:bullseye-slim
2421

22+
# Install ca-certificates for HTTPS requests
23+
RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*
24+
25+
# Create a non-root user
26+
RUN useradd -r -u 1000 -m mcp-grafana
27+
28+
# Set the working directory
29+
WORKDIR /app
30+
31+
# Copy the binary from the builder stage
32+
COPY --from=builder --chown=1000:1000 /app/mcp-grafana /app/
33+
34+
# Use the non-root user
35+
USER mcp-grafana
36+
37+
# Expose the port the app runs on
2538
EXPOSE 8000
2639

2740
# Run the application
28-
ENTRYPOINT ["/app/.venv/bin/mcp-grafana", "--transport", "sse"]
41+
ENTRYPOINT ["/app/mcp-grafana", "--transport", "sse", "--sse-address", "0.0.0.0:8000"]

Makefile

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
11
.PHONY: build-image
22
build-image:
3-
docker build -t mcp-grafana:latest .
3+
docker build -t mcp-grafana:latest .
4+
5+
.PHONY: lint
6+
lint:
7+
go tool -modfile go.tools.mod golangci-lint run
8+
9+
.PHONY: test
10+
test:
11+
go test ./...
12+
13+
.PHONY: test-all
14+
test-all:
15+
go test -v -tags integration ./...
16+
17+
.PHONY: run
18+
go run ./...

0 commit comments

Comments
 (0)