Shared Go library providing Prometheus metrics, logging/metrics middleware, and version injection for codeready-toolchain MCP servers.
Prometheus metric definitions shared across all MCP servers:
-
MCPCallsTotal— CounterVec tracking total MCP calls byserver,method,name,success -
MCPCallDuration— HistogramVec tracking MCP call duration in seconds
MCP server middleware using *slog.Logger:
-
NewMetricsMiddleware(serverName string, logger *slog.Logger) mcp.Middleware— records Prometheus metrics for every MCP call -
NewLoggingMiddleware(logger *slog.Logger) mcp.Middleware— logs MCP method start/completion/failure with session ID and duration
Build-time version info injected via ldflags:
-
Commit— git commit hash -
BuildTime— binary build timestamp
Inject at build time:
go build -ldflags "-X github.com/codeready-toolchain/mcp-common/pkg/version.Commit=$(git rev-parse HEAD) -X github.com/codeready-toolchain/mcp-common/pkg/version.BuildTime=$(date -u +%Y-%m-%dT%H:%M:%SZ)"import (
"github.com/codeready-toolchain/mcp-common/pkg/metrics"
"github.com/codeready-toolchain/mcp-common/pkg/middleware"
"github.com/codeready-toolchain/mcp-common/pkg/version"
)Requires Go version 1.24.x (1.24.13 or higher) — download for your development environment here.
This repository uses Go modules.