mcp

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package mcp provides MCP (Model Context Protocol) client support. MCP allows connecting to external tool servers.

Package mcp provides MCP (Model Context Protocol) client support.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is an MCP client that connects to tool servers.

func NewClient

func NewClient(config ServerConfig) (*Client, error)

NewClient creates a new MCP client for a server.

func (*Client) CallTool

func (c *Client) CallTool(ctx context.Context, name string, args map[string]interface{}) (*ToolCallResult, error)

CallTool invokes a tool on the server.

func (*Client) Close

func (c *Client) Close() error

Close shuts down the MCP server.

func (*Client) Initialize

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

Initialize performs the MCP initialization handshake.

func (*Client) ListTools

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

ListTools fetches available tools from the server.

func (*Client) Tools

func (c *Client) Tools() []Tool

Tools returns cached tools.

type Content

type Content struct {
	Type string `json:"type"`
	Text string `json:"text,omitempty"`
	Data string `json:"data,omitempty"` // base64 for images
}

Content represents content in a tool result.

type Manager

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

Manager manages multiple MCP server connections.

func NewManager

func NewManager() *Manager

NewManager creates a new MCP manager.

func (*Manager) AllTools

func (m *Manager) AllTools() []ToolWithServer

AllTools returns all tools from all connected servers, excluding denied tools.

func (*Manager) CallTool

func (m *Manager) CallTool(ctx context.Context, server, tool string, args map[string]interface{}) (*ToolCallResult, error)

CallTool calls a tool on a specific server.

func (*Manager) Close

func (m *Manager) Close() error

Close disconnects all servers.

func (*Manager) Connect

func (m *Manager) Connect(ctx context.Context, name string, config ServerConfig) error

Connect connects to an MCP server.

func (*Manager) Disconnect

func (m *Manager) Disconnect(name string) error

Disconnect disconnects from an MCP server.

func (*Manager) FindTool

func (m *Manager) FindTool(name string) (server string, found bool)

FindTool finds which server has a tool, excluding denied tools.

func (*Manager) ServerCount

func (m *Manager) ServerCount() int

ServerCount returns the number of connected servers.

func (*Manager) Servers

func (m *Manager) Servers() []string

Servers returns the names of connected servers.

func (*Manager) SetDeniedTools

func (m *Manager) SetDeniedTools(server string, tools []string)

SetDeniedTools sets tools to exclude from a server's tool list. These tools will not be returned by AllTools() and won't be exposed to the LLM.

type RPCError

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

RPCError represents a JSON-RPC error.

func (*RPCError) Error

func (e *RPCError) Error() string

type Request

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

Request is a JSON-RPC 2.0 request.

type Response

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

Response is a JSON-RPC 2.0 response.

type ServerConfig

type ServerConfig struct {
	Command string            `json:"command"`
	Args    []string          `json:"args,omitempty"`
	Env     map[string]string `json:"env,omitempty"`
}

ServerConfig configures an MCP server connection.

type Tool

type Tool struct {
	Name        string                 `json:"name"`
	Description string                 `json:"description"`
	InputSchema map[string]interface{} `json:"inputSchema"`
}

Tool represents an MCP tool definition.

type ToolCallParams

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

ToolCallParams are the parameters for tools/call.

type ToolCallResult

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

ToolCallResult is the result of tools/call.

type ToolWithServer

type ToolWithServer struct {
	Server string
	Tool   Tool
}

ToolWithServer pairs a tool with its server name.

type ToolsListResult

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

ToolsListResult is the result of tools/list.

Jump to

Keyboard shortcuts

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