mcp

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const ProtocolVersion = "2024-11-05"

ProtocolVersion is the MCP protocol version reported by SetupMCP.

Variables

This section is empty.

Functions

This section is empty.

Types

type CommandFactory added in v0.15.0

type CommandFactory func(argv []string, stdout io.Writer, stderr io.Writer) (*cobra.Command, error)

CommandFactory builds a fresh Cobra command tree for a single MCP tools/call.

Use this when a CLI captures output streams into closures at construction time, or when reusing and resetting the same Cobra tree is unsafe.

Parameters:

  • argv: the command path and flag arguments (excluding the root command name). Provided for informational use or conditional subtree building. The factory must not call SetArgs; the caller handles that.
  • stdout, stderr: writers that must receive all command output. Wire these into any closures that capture output streams at construction time.

After the factory returns, the caller configures the returned command: SetArgs, SetIn, SetOut, SetErr, SilenceErrors, and SilenceUsage. The factory must not set these. The caller's SetOut/SetErr use the same buffers passed as stdout/stderr, ensuring cmd.OutOrStdout() works alongside closure-captured writers.

The returned command tree must have the same structure and flags as the root command passed to [SetupMCP]. The MCP tool registry is built from the original tree; the factory tree is only used for execution.

type InitializeResult

type InitializeResult struct {
	ProtocolVersion string         `json:"protocolVersion"`
	ServerInfo      ServerInfo     `json:"serverInfo"`
	Capabilities    map[string]any `json:"capabilities"`
}

InitializeResult is returned from the initialize request.

type Options

type Options struct {
	FlagName       string         // Name of the persistent flag (defaults to "mcp")
	Name           string         // Server name reported during initialize (defaults to root command name)
	Version        string         // Server version reported during initialize (defaults to structcli.Version)
	Separator      string         // Tool name separator for nested commands (defaults to "-")
	AllCommands    bool           // Include runnable parent/root commands. By default MCP exposes runnable leaves only.
	Exclude        []string       // Exclude tool names or full command paths from tools/list and tools/call
	CommandFactory CommandFactory // Optional fresh command factory for each MCP tools/call execution.
}

Options configures the --mcp flag for command-line applications.

type Request

type Request struct {
	JSONRPC string          `json:"jsonrpc"`
	Method  string          `json:"method"`
	ID      json.RawMessage `json:"id,omitempty"`
	Params  json.RawMessage `json:"params,omitempty"`
}

Request is a JSON-RPC request sent over MCP stdio.

type Response

type Response struct {
	JSONRPC string          `json:"jsonrpc"`
	ID      json.RawMessage `json:"id,omitempty"`
	Result  any             `json:"result,omitempty"`
	Error   *ResponseError  `json:"error,omitempty"`
}

Response is a JSON-RPC response sent over MCP stdio.

type ResponseError

type ResponseError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

ResponseError is a JSON-RPC error object.

type ServerInfo

type ServerInfo struct {
	Name    string `json:"name"`
	Version string `json:"version"`
}

ServerInfo describes the MCP server.

type Tool

type Tool struct {
	Name        string          `json:"name"`
	Description string          `json:"description,omitempty"`
	InputSchema json.RawMessage `json:"inputSchema"`
}

Tool is exposed by tools/list.

type ToolCallContent

type ToolCallContent struct {
	Type string `json:"type"`
	Text string `json:"text"`
}

ToolCallContent is a single text content part in a tools/call result.

type ToolCallParams

type ToolCallParams struct {
	Name      string         `json:"name"`
	Arguments map[string]any `json:"arguments,omitempty"`
}

ToolCallParams are provided to tools/call.

type ToolCallResult

type ToolCallResult struct {
	Content []ToolCallContent `json:"content"`
	IsError bool              `json:"isError,omitempty"`
}

ToolCallResult is returned from tools/call.

type ToolsListResult

type ToolsListResult struct {
	Tools []Tool `json:"tools"`
}

ToolsListResult is returned from tools/list.

Jump to

Keyboard shortcuts

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