mcp

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2026 License: MIT Imports: 14 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 (*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) Initialize

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

Initialize performs the MCP protocol handshake.

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) 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) RequiresApproval

func (m *MCPTool) RequiresApproval() bool

func (*MCPTool) Spec

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

type Manager

type Manager struct {
	// 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.

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"`
}

ToolInfo describes an MCP tool definition.

Jump to

Keyboard shortcuts

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