Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: rewrite MCP server in Go #29

Merged
merged 35 commits into from
Mar 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
c5822b8
Remove Python impl
sd2k Feb 26, 2025
c53e4a3
Add initial Go scaffolding
sd2k Feb 26, 2025
b4e5cec
Add reflection conversion to get strongly typed tool handlers
sd2k Feb 27, 2025
342cbf7
Add datasource tools
sd2k Feb 27, 2025
317a563
Add Incident tools
sd2k Feb 27, 2025
6cda0e7
Add Prometheus tools
sd2k Feb 27, 2025
592d905
Fix some tools
sd2k Feb 27, 2025
0a40174
Run go mod tidy
sd2k Feb 27, 2025
d712cec
Rename client.go to mcpgrafana.go
csmarchbanks Mar 10, 2025
02ce91b
Link to PR for mcp-go dependency replacement
csmarchbanks Mar 10, 2025
598b532
Add flag for host and port when using sse
csmarchbanks Mar 10, 2025
083779b
Move executabile into a sub directory
csmarchbanks Mar 10, 2025
b8a111c
Make Tool APIs more type safe and require fewer temporaries
sd2k Mar 11, 2025
fe3ae9f
Update README to include new installation instructions
sd2k Mar 11, 2025
aaaf51b
Fix casing in function name
sd2k Mar 11, 2025
a17cb43
Remove old Python CI pipelines; add one to run Go tests
sd2k Mar 11, 2025
a83af0f
Add linting via golangci-lint
sd2k Mar 11, 2025
da9ecad
Update Dockerfile to build Go-based image
sd2k Mar 11, 2025
2963168
WIP - more tools flexibility, add datasources test
sd2k Mar 11, 2025
a4e0f2b
Re-add docker-compose provisioning files; update datasources tests
sd2k Mar 11, 2025
60c5c8b
WIP - prometheus tests
sd2k Mar 11, 2025
b82120d
Add integration tags and test in CI
sd2k Mar 11, 2025
a2a8dd3
Update Incident tools, add tests
sd2k Mar 11, 2025
3bf811f
Update search tool; add test
sd2k Mar 11, 2025
d56f3aa
Remove unneeded nested types from datasource tools
sd2k Mar 11, 2025
a089318
Update comment in prometheus_test.go
sd2k Mar 11, 2025
cdb3842
Add docker-compose startup to CI
sd2k Mar 11, 2025
602f8dd
Wait for Grafana/Prometheus to start up in CI
sd2k Mar 11, 2025
50d416f
Skip query_range tests as the temporary Prometheus instance will neve…
sd2k Mar 11, 2025
9c88527
Rename workflow to 'Go' for nicer appearance in GitHub
sd2k Mar 11, 2025
77be25c
Fix Incident URL
csmarchbanks Mar 12, 2025
69c799e
Limit the amount of data returned for list tools
csmarchbanks Mar 12, 2025
1ed9aa7
Remove unused incidentSummary type
sd2k Mar 12, 2025
1443281
Merge pull request #30 from grafana/summarize-list-operations
sd2k Mar 12, 2025
65142f6
Run Go workflow on all PRs
sd2k Mar 12, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Git
.git
.gitignore
.github/

# Docker
Dockerfile
.dockerignore

# Build artifacts
bin/
dist/
build/
*.exe
*.exe~
*.dll
*.so
*.dylib

# Go specific
vendor/
go.work

# Testing
*_test.go
**/test/
**/tests/
coverage.out
coverage.html

# IDE and editor files
.idea/
.vscode/
*.swp
*.swo
*~

# OS specific
.DS_Store
Thumbs.db

# Temporary files
tmp/
temp/
*.tmp
*.log

# Documentation
docs/
*.md
LICENSE

# Development tools
.air.toml
.golangci.yml
.goreleaser.yml

# Debug files
debug
__debug_bin
39 changes: 0 additions & 39 deletions .github/workflows/cloud.yml

This file was deleted.

52 changes: 52 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Go

on:
push:
branches: [ main ]
pull_request:

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.24'
cache: true

- name: Lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.64

test:
name: Test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

# Start the Grafana server.
# Do this early so that it can start up in time for the tests to run.
# We may need to add a wait here.
- name: Start docker-compose services
uses: hoverkraft-tech/[email protected]
with:
compose-file: "docker-compose.yaml"

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.24'
cache: true

- name: Wait for Grafana server and Prometheus server to start and scrape
run: sleep 30

- name: Run tests
run: make test-all
47 changes: 0 additions & 47 deletions .github/workflows/python.yml

This file was deleted.

103 changes: 0 additions & 103 deletions .github/workflows/release.yml

This file was deleted.

47 changes: 30 additions & 17 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,28 +1,41 @@
FROM python:3.13-slim AS builder
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
# Build stage
FROM golang:1.24-bullseye AS builder

# Change the working directory to the `app` directory
# Set the working directory
WORKDIR /app

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

# Copy the project into the intermediate image
ADD . /app
# Download dependencies
RUN go mod download

# Sync the project
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --frozen --no-editable
# Copy the source code
COPY . .

FROM python:3.13-slim
# Build the application
RUN go build -o mcp-grafana ./cmd/mcp-grafana

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

# Install ca-certificates for HTTPS requests
RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*

# Create a non-root user
RUN useradd -r -u 1000 -m mcp-grafana

# Set the working directory
WORKDIR /app

# Copy the binary from the builder stage
COPY --from=builder --chown=1000:1000 /app/mcp-grafana /app/

# Use the non-root user
USER mcp-grafana

# Expose the port the app runs on
EXPOSE 8000

# Run the application
ENTRYPOINT ["/app/.venv/bin/mcp-grafana", "--transport", "sse"]
ENTRYPOINT ["/app/mcp-grafana", "--transport", "sse", "--sse-address", "0.0.0.0:8000"]
17 changes: 16 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
.PHONY: build-image
build-image:
docker build -t mcp-grafana:latest .
docker build -t mcp-grafana:latest .

.PHONY: lint
lint:
go tool -modfile go.tools.mod golangci-lint run

.PHONY: test
test:
go test ./...

.PHONY: test-all
test-all:
go test -v -tags integration ./...

.PHONY: run
go run ./...
Loading
Loading