mcp

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: Apache-2.0 Imports: 18 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package mcp serves the kubectl-nv command tree as a Model Context Protocol server over stdio, one tool per read-only leaf command.

The tools are derived from the cobra tree rather than listed here, so a command another track adds becomes a tool without this package changing. What is listed here is the opposite: the four commands that are never tools, and the one inherited flag a tool may carry.

The input schema is an allowlist. Everything that decides which cluster the plugin talks to, and as whom, is settled when the server starts and is not reachable from a tool call: a model that could set --server, --token or --kubeconfig could point kubectl-nv at a cluster, a proxy or an identity nobody granted it, and the read-only guarantee says nothing about which cluster is being read.

Index

Constants

View Source
const (
	// SuppressAnnotation marks a flag that no tool offers. A command sets it on
	// a flag of its own with pflag's SetAnnotation.
	//
	// It exists for the flags the read-only guard says nothing about because
	// they touch no cluster: --write-dir writes files on the machine kubectl-nv
	// runs on, which is not something to hand a model even though no Kubernetes
	// object changes.
	SuppressAnnotation = "kubectl-nv.nvidia.com/mcp-suppress"

	// HostDirAnnotation marks a flag naming a directory on the machine
	// kubectl-nv runs on that the command writes into. No tool offers one: the
	// server pins it to a fresh private directory per call and reports where
	// that is, so a model can neither choose the path nor read another call's.
	HostDirAnnotation = "kubectl-nv.nvidia.com/host-dir"

	// ExecAnnotation marks a command that can run something inside a pod. The
	// server forces --no-exec on it and refuses it outright when it has no such
	// flag.
	//
	// It is an annotation rather than a list of names here because a list is a
	// thing to forget: a command renamed, or a new one that execs, would be
	// served with the exec available and nothing would say so.
	ExecAnnotation = "kubectl-nv.nvidia.com/exec"
)
View Source
const (

	// ExitCodeMetaKey is where a tool result carries the exit code the command
	// would have left the process with. A caller that scripts kubectl-nv on the
	// command line branches on that code, and it has to be able to branch on
	// the same one here.
	ExitCodeMetaKey = "kubectl-nv.nvidia.com/exit-code"
)

Variables

This section is empty.

Functions

func NewCommand

func NewCommand(o *cmd.Options, newRoot NewRootFunc) *cobra.Command

NewCommand builds the mcp command. newRoot returns a fresh command tree, one per tool call, so that no flag a call set is still set on the next.

func NewServer

func NewServer(newRoot NewRootFunc, version string) (*sdk.Server, error)

NewServer builds the MCP server over a command tree, with one tool per read-only leaf.

func Serve

func Serve(ctx context.Context, newRoot NewRootFunc, version string, connection CallDeps) error

Serve runs the server over stdio until the client goes away or ctx is cancelled. stdio is the transport an editor or an agent runner starts a plugin on, and it is the only one offered: a listening socket would be a way into the cluster that outlives the process that asked for it.

func SetConnection

func SetConnection(server *sdk.Server, deps CallDeps)

SetConnection tells a server which cluster its calls run against. It is called once, after the mcp command's own flags are parsed and before the first call is served.

Types

type ArgSpec

type ArgSpec struct {
	// Min is how many arguments the command needs.
	Min int
	// Max is how many it accepts, or -1 for any number.
	Max int
	// Usage is the Use line the arity was read from, for the description.
	Usage string
}

ArgSpec is the arity of a command's positional arguments, read from its Use line: <NAME> and a bare NAME are required, [NAME] is optional, and a trailing ... means any number.

func (ArgSpec) Takes

func (a ArgSpec) Takes() bool

Takes reports whether the command accepts any positional argument.

type CallDeps

type CallDeps struct {
	// Streams are the buffers this call's output is collected from.
	Streams genericiooptions.IOStreams
	// ConfigFlags are the kubectl configuration flags the mcp command itself
	// was given, already parsed. A fresh tree is built over them, so every call
	// talks to the cluster the server was started against.
	ConfigFlags *genericclioptions.ConfigFlags
	// Factory is the client factory built from those flags, shared by every
	// call so that the kubeconfig is read once.
	Factory cmd.Factory
	// KubeconfigPath is what ConfigFlags resolved to, for reporting. The
	// clients are built from ConfigFlags and Factory, not from this.
	KubeconfigPath string
}

CallDeps is what one tool call runs against: where the command writes, and which cluster it talks to.

The connection half is settled when the server starts and is the same for every call. It is carried here rather than read from the environment inside each call, so that a tool call cannot be aimed at a different cluster by changing the environment underneath the server.

type NewRootFunc

type NewRootFunc func(CallDeps) *cobra.Command

NewRootFunc builds a fresh kubectl-nv command tree for one tool call.

It is a function rather than a tree because cobra keeps the flags a run set, and a tree reused across two tool calls would carry the first call's --limit into the second. One tree per call is the only way a call means what it says.

type Server

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

Server is the MCP server together with the connection every call runs against.

type Tool

type Tool struct {
	// Name is the command path joined with underscores, for instance
	// "adm_must-gather". It is what a model calls.
	Name string
	// Path is the argument path of the command inside the tree.
	Path []string
	// Description is what the command says about itself.
	Description string
	// InputSchema is the JSON Schema of the tool's arguments, built from the
	// leaf's own flags, the one allowed inherited flag, and, when the command
	// documents any, its positional arguments.
	InputSchema map[string]any
	// ForceNoExec marks a leaf that can run something inside a pod.
	ForceNoExec bool
	// HasNoExecFlag reports whether the command can be told not to exec. An
	// exec capable command that cannot is refused rather than run.
	HasNoExecFlag bool
	// HostDirFlags are the flags naming a directory the command writes into.
	// The server pins each one per call.
	HostDirFlags []string
	// WritesHost reports whether running this tool puts files on the machine
	// kubectl-nv runs on. Such a tool is not read-only, whatever it does to the
	// cluster, and its annotations have to say so.
	WritesHost bool
	// Args is what the Use line says about positional arguments.
	Args ArgSpec
	// HasOutputFlag reports whether -o can be set on this command.
	HasOutputFlag bool
}

Tool is one read-only leaf command as it is offered over MCP.

func Tools

func Tools(root *cobra.Command) []Tool

Tools returns one tool per read-only leaf of the tree, sorted by name.

Jump to

Keyboard shortcuts

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