server

package
v2.56.0 Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ExcludedNamespaces is used to filter out core.Command that should not be exposed as MCP tools based on their namespace.
	ExcludedNamespaces = []string{

		"config",

		"alias",
		"autocomplete",
		"shell",
		"login",
		"init",
	}

	// ExcludedVerbs is used to filter out core.Command that should not be exposed as MCP tools based on their verb.
	ExcludedVerbs = []string{
		"edit",
	}
)

Functions

func BuildResourceURI

func BuildResourceURI(namespace, resource string) string

BuildResourceURI creates a URI for a namespace/resource combination

func CommandNameToToolName

func CommandNameToToolName(cmd *core.Command) string

CommandNameToToolName converts a command to an MCP tool name

func McpServer

func McpServer() *core.Command

func McpServerListResources

func McpServerListResources() *core.Command

func McpServerListTools

func McpServerListTools() *core.Command

func McpServerServe

func McpServerServe() *core.Command

func ResourceName

func ResourceName(cmd *core.Command) string

ResourceName generates a human-readable name for the resource

func RunStreamableHTTPServer

func RunStreamableHTTPServer(
	ctx context.Context,
	mcpServer *MCPServer,
	address string,
) error

func ShouldLoadCommand

func ShouldLoadCommand(cmd *core.Command, config CommandFilterConfig) bool

ShouldLoadCommand returns true if the command should be registered as an MCP tool. It filters out: - Hidden commands - Commands with ExcludeFromMCP flag set - Commands without a Run function (namespace/resource containers) - Commands in excluded namespaces - Commands with excluded verbs - When readOnly is true, only commands with get/list verbs are registered - When enabledNamespaces/ Resources/ Verbs are set, only matching commands are registered

func SplitArg

func SplitArg(s string) []string

SplitArg splits a comma-separated string into a slice of strings. Returns an empty slice if the input is empty.

Types

type CommandFilterConfig

type CommandFilterConfig struct {
	ReadOnly          bool
	EnabledNamespaces []string
	EnabledResources  []string
	EnabledVerbs      []string
}

CommandFilterConfig holds the configuration for filtering CLI commands when registering them as MCP tools/resources.

type CommandResource

type CommandResource struct {
	Command *core.Command
}

CommandResource wraps a CLI command for MCP resource exposure

func NewCommandResource

func NewCommandResource(cmd *core.Command) *CommandResource

NewCommandResource creates a new CommandResource from a core.Command

func (*CommandResource) Execute

func (cr *CommandResource) Execute(
	ctx context.Context,
	inputArgs map[string]any,
) (*mcp.ReadResourceResult, error)

Execute runs the CLI command with the provided arguments and returns resource contents

func (*CommandResource) ToMCPResource

func (cr *CommandResource) ToMCPResource() *mcp.Resource

ToMCPResource converts the CommandResource to an MCP Resource

type CommandTool

type CommandTool struct {
	Command *core.Command
}

CommandTool wraps a CLI command for MCP tool execution

func FilterCommands

func FilterCommands(commands []*core.Command, config CommandFilterConfig) []*CommandTool

FilterCommands filters CLI commands based on the given config. Returns a slice of CommandTool ready to be passed to NewMCPServer.

func NewCommandTool

func NewCommandTool(cmd *core.Command) *CommandTool

NewCommandTool creates a new CommandTool from a core.Command

func (*CommandTool) Execute

func (ct *CommandTool) Execute(
	ctx context.Context,
	inputArgs map[string]any,
) (*mcp.CallToolResult, error)

Execute runs the CLI command with the provided arguments

func (*CommandTool) ToMCPTool

func (ct *CommandTool) ToMCPTool() *mcp.Tool

ToMCPTool converts the CommandTool to an MCP Tool

type JSONSchema

type JSONSchema struct {
	Type                 string                 `json:"type,omitempty"`
	Description          string                 `json:"description,omitempty"`
	Properties           map[string]*JSONSchema `json:"properties,omitempty"`
	Required             []string               `json:"required,omitempty"`
	AdditionalProperties *bool                  `json:"additionalProperties,omitempty"`
	Enum                 []string               `json:"enum,omitempty"`
	Default              any                    `json:"default,omitempty"`
}

JSONSchema represents a JSON Schema object

func ArgSpecToJSONSchema

func ArgSpecToJSONSchema(argSpec *core.ArgSpec) *JSONSchema

ArgSpecToJSONSchema converts a core.ArgSpec to JSON Schema

func CommandToFlatArgsSchema

func CommandToFlatArgsSchema(cmd *core.Command) *JSONSchema

CommandToFlatArgsSchema creates a flat schema for commands that accept all args as strings

type MCPServer

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

MCPServer wraps the MCP server with CLI command integration

func NewMCPServer

func NewMCPServer(
	commands []*CommandTool,
	buildInfo core.BuildInfo,
) *MCPServer

NewMCPServer creates a new MCP server that exposes CLI commands as tools and resources Meta should be injected into the context by callers before tool/resource execution.

func (*MCPServer) ListResources

func (s *MCPServer) ListResources() []resourceInfo

ListResources returns a list of available MCP resources based on the server's configuration. Resources are read-only endpoints for list commands that can be accessed via URI.

func (*MCPServer) ListTools

func (s *MCPServer) ListTools() []toolInfo

ListTools returns a list of available MCP tools based on the server's configuration. It returns tools that match the read-only mode and enabled namespaces/resources/verbs.

func (*MCPServer) LoadResource

func (s *MCPServer) LoadResource(cmd *core.Command) error

LoadResource registers a CLI command as an MCP resource Meta is expected to be already present in the context.

func (*MCPServer) RegisteredCommands

func (s *MCPServer) RegisteredCommands() []*CommandTool

RegisteredCommands returns the list of commands registered as MCP tools

func (*MCPServer) RegisteredResources

func (s *MCPServer) RegisteredResources() []*CommandResource

RegisteredResources returns the list of commands registered as MCP resources

func (*MCPServer) Run

func (s *MCPServer) Run(ctx context.Context, transport mcp.Transport) error

Run starts the MCP server using the specified transport

func (*MCPServer) Serve

func (s *MCPServer) Serve(
	ctx context.Context,
	transportMode string,
	address string,
) (any, error)

Serve runs the MCP server with the specified transport. It handles graceful shutdown and transport selection.

func (*MCPServer) Server

func (s *MCPServer) Server() *mcp.Server

Server returns the underlying MCP server for direct transport connections

Jump to

Keyboard shortcuts

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