Documentation
¶
Index ¶
- Variables
- func BuildResourceURI(namespace, resource string) string
- func CommandNameToToolName(cmd *core.Command) string
- func McpServer() *core.Command
- func McpServerListResources() *core.Command
- func McpServerListTools() *core.Command
- func McpServerServe() *core.Command
- func ResourceName(cmd *core.Command) string
- func RunStreamableHTTPServer(ctx context.Context, mcpServer *MCPServer, address string) error
- func ShouldLoadCommand(cmd *core.Command, config CommandFilterConfig) bool
- func SplitArg(s string) []string
- type CommandFilterConfig
- type CommandResource
- type CommandTool
- type JSONSchema
- type MCPServer
- func (s *MCPServer) ListResources() []resourceInfo
- func (s *MCPServer) ListTools() []toolInfo
- func (s *MCPServer) LoadResource(cmd *core.Command) error
- func (s *MCPServer) RegisteredCommands() []*CommandTool
- func (s *MCPServer) RegisteredResources() []*CommandResource
- func (s *MCPServer) Run(ctx context.Context, transport mcp.Transport) error
- func (s *MCPServer) Serve(ctx context.Context, transportMode string, address string) (any, error)
- func (s *MCPServer) Server() *mcp.Server
Constants ¶
This section is empty.
Variables ¶
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 ¶
BuildResourceURI creates a URI for a namespace/resource combination
func CommandNameToToolName ¶
CommandNameToToolName converts a command to an MCP tool name
func McpServerListResources ¶
func McpServerListTools ¶
func McpServerServe ¶
func ResourceName ¶
ResourceName generates a human-readable name for the resource
func RunStreamableHTTPServer ¶
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
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 ¶
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 ¶
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 ¶
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