mcp

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 18 Imported by: 0 modules, 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CallToolResult

type CallToolResult struct {
	Content []ToolContent `json:"content"`
	IsError bool          `json:"isError"`
}

CallToolResult holds the result of a tools/call request.

type Client

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

Client manages an MCP server process communicating via stdio JSON-RPC.

func NewClient

func NewClient(command string, args []string, env map[string]string) *Client

NewClient creates a new MCP client.

func NewClientWithEnvScrub added in v0.7.4

func NewClientWithEnvScrub(command string, args []string, env map[string]string, envScrub []string) *Client

NewClientWithEnvScrub creates a new MCP client whose child process environment excludes credential-shaped variables plus envScrub names.

func (*Client) Call

func (c *Client) Call(ctx context.Context, method string, params interface{}) (json.RawMessage, error)

Call sends a JSON-RPC request and awaits the response.

func (*Client) CallTool

func (c *Client) CallTool(ctx context.Context, name string, args json.RawMessage) (CallToolResult, error)

CallTool executes a specific tool on the MCP server.

func (*Client) Close

func (c *Client) Close() error

Close gracefully terminates the child process.

func (*Client) Done added in v0.7.4

func (c *Client) Done() <-chan struct{}

Done is closed when the server process exits or Close is called.

func (*Client) Initialize

func (c *Client) Initialize(ctx context.Context) error

Initialize performs the MCP protocol handshake.

func (*Client) IsClosed added in v0.7.4

func (c *Client) IsClosed() bool

IsClosed reports whether the client is unusable because the server process exited or Close was called.

func (*Client) ListTools

func (c *Client) ListTools(ctx context.Context) ([]ToolInfo, error)

ListTools queries the available tools from the MCP server.

func (*Client) Notify

func (c *Client) Notify(method string, params interface{}) error

Notify sends a JSON-RPC notification (no response expected).

func (*Client) SetRequestTimeout added in v0.7.4

func (c *Client) SetRequestTimeout(d time.Duration)

SetRequestTimeout bounds a single JSON-RPC request. Non-positive values restore the 60s default.

func (*Client) Start

func (c *Client) Start() error

Start launches the MCP server process.

type JSONRPCError

type JSONRPCError struct {
	Code    int             `json:"code"`
	Message string          `json:"message"`
	Data    json.RawMessage `json:"data,omitempty"`
}

JSONRPCError holds JSON-RPC error payload.

func (*JSONRPCError) Error

func (e *JSONRPCError) Error() string

type JSONRPCRequest

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

JSONRPCRequest represents a standard JSON-RPC 2.0 request.

type JSONRPCResponse

type JSONRPCResponse struct {
	JSONRPC string          `json:"jsonrpc"`
	ID      *uint64         `json:"id,omitempty"`
	Result  json.RawMessage `json:"result,omitempty"`
	Error   *JSONRPCError   `json:"error,omitempty"`
}

JSONRPCResponse represents a standard JSON-RPC 2.0 response.

type MCPTool

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

MCPTool adapts an MCP tool to the tools.Tool interface.

func NewMCPTool

func NewMCPTool(serverName string, info ToolInfo, client *Client) *MCPTool

NewMCPTool creates a tools.Tool adapter for an MCP tool.

func (*MCPTool) Execute

func (m *MCPTool) Execute(ctx context.Context, args json.RawMessage) (tools.Result, error)

func (*MCPTool) Preview added in v0.7.4

func (m *MCPTool) Preview(_ context.Context, args json.RawMessage) (tools.Preview, error)

Preview shows the server, tool, and arguments awaiting approval.

func (*MCPTool) ReadOnly added in v0.7.4

func (m *MCPTool) ReadOnly() bool

ReadOnly reports the server's MCP readOnlyHint. The approval gate uses it only to honor an explicit "read-only tools this turn" choice; a server that lies about the hint is still gated by the per-call prompt otherwise.

func (*MCPTool) RequiresApproval

func (m *MCPTool) RequiresApproval() bool

func (*MCPTool) Spec

func (m *MCPTool) Spec() tools.ToolSpec

type Manager

type Manager struct {

	// EnvScrub lists additional env var names or patterns to drop from every
	// spawned MCP server, on top of the built-in credential patterns.
	EnvScrub []string
	// contains filtered or unexported fields
}

Manager coordinates all configured MCP clients.

func NewManager

func NewManager(servers map[string]config.MCPServerConfig) *Manager

NewManager creates a new MCP Manager with server configurations.

func (*Manager) AddServer

func (m *Manager) AddServer(name string, cfg config.MCPServerConfig)

AddServer saves a new server configuration.

func (*Manager) CloseAll

func (m *Manager) CloseAll()

CloseAll closes all active MCP client connections. After CloseAll, servers are never restarted on demand.

func (*Manager) EnsureClient added in v0.7.4

func (m *Manager) EnsureClient(ctx context.Context, server string) (*Client, error)

EnsureClient returns a live client for server, restarting the server process when its previous client is closed. Concurrent callers share a single restart, and the restart is serialized against CloseAll. Tools stay registered across a restart; only the client pointer moves.

func (*Manager) ListServers

func (m *Manager) ListServers() map[string]config.MCPServerConfig

ListServers returns all configured server names and configs.

func (*Manager) RemoveServer

func (m *Manager) RemoveServer(name string)

RemoveServer removes a server configuration.

func (*Manager) StartAll

func (m *Manager) StartAll(ctx context.Context, toolRegistry *tools.Registry) error

StartAll initializes all configured MCP servers and registers their tools.

type ToolContent

type ToolContent struct {
	Type string `json:"type"`
	Text string `json:"text,omitempty"`
}

ToolContent is a piece of output returned from an MCP tool call.

type ToolInfo

type ToolInfo struct {
	Name        string          `json:"name"`
	Description string          `json:"description"`
	InputSchema json.RawMessage `json:"inputSchema"`
	// Annotations carries MCP hints; readOnlyHint lets the approval gate offer
	// "read-only tools this turn" for servers that declare safe tools.
	Annotations *struct {
		ReadOnlyHint bool `json:"readOnlyHint"`
	} `json:"annotations,omitempty"`
}

ToolInfo describes an MCP tool definition.

Jump to

Keyboard shortcuts

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