mcp

package
v0.6.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 9, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package mcp implements a Model Context Protocol (MCP) server that exposes promql-cli over stdio transport (JSON-RPC 2.0, protocol 2024-11-05).

Capabilities:

tools      — query_instant, query_range, list_metrics, list_labels,
             load_metrics, execute_line (with optional streaming)
resources  — promql://metrics, promql://metrics/list, promql://labels,
             and one promql://metrics/<name> per loaded metric
prompts    — parameterized PromQL templates (error-rate-by-service, etc.)
logging    — logging/setLevel to adjust slog verbosity at runtime
executionStreaming — execute_line stream=true support

Lifecycle methods: initialize, ping, shutdown, notifications/initialized.

Source layout:

mcp.go        — Server, transport framing, dispatch, lifecycle, logging
tools.go      — tool definitions, handlers, query execution, formatting
resources.go  — resources/list + resources/read
prompts.go    — prompts/list + prompts/get

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetServerVersion added in v0.6.2

func SetServerVersion(v string)

SetServerVersion overrides the version reported in the MCP initialize response (e.g. with the version resolved from build info at runtime).

Types

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server implements the MCP protocol over stdin/stdout.

func NewServer

func NewServer(engine *promql.Engine, storage *sstorage.SimpleStorage) *Server

NewServer creates an MCP server over stdin/stdout.

func NewServerWithIO added in v0.6.1

func NewServerWithIO(engine *promql.Engine, storage *sstorage.SimpleStorage, in io.Reader, out io.Writer) *Server

NewServerWithIO creates an MCP server over the given reader/writer. The writer is captured once, so later swaps of os.Stdout (e.g. output capture during execute_line) never affect protocol frames.

func (*Server) Run

func (s *Server) Run(ctx context.Context) error

Run reads JSON-RPC messages from stdin, dispatches them, and writes responses to stdout. It returns when stdin is closed or ctx is done.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL