mcp

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: May 25, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	JSONRPCVersion = "2.0"
)

Protocol constants

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client represents an MCP client

type ConfigLoader

type ConfigLoader struct{}

ConfigLoader loads MCP configuration

func (*ConfigLoader) LoadFromConfig

func (cl *ConfigLoader) LoadFromConfig(mgr *Manager, servers map[string]ServerConfig) error

LoadFromConfig loads MCP servers from configuration

type JSONRPCError

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

JSONRPCError represents a JSON-RPC 2.0 error

type JSONRPCMessage

type JSONRPCMessage struct {
	ID     interface{}      `json:"id"`
	Method string           `json:"method"`
	Params *json.RawMessage `json:"params,omitempty"`
}

JSONRPCMessage represents a JSON-RPC message

type JSONRPCRequest

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

JSONRPCRequest represents a JSON-RPC 2.0 request

type JSONRPCResponse

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

JSONRPCResponse represents a JSON-RPC 2.0 response

type MCPMessage

type MCPMessage struct {
	Method string          `json:"method"`
	Params json.RawMessage `json:"params,omitempty"`
}

MCPMessage represents an MCP protocol message

type MCPServer

type MCPServer struct {
	// Server configuration
	Port       int
	Path       string
	AuthToken  string
	EnableCORS bool

	// Handler for MCP requests
	Handler MCPServerHandler
	// contains filtered or unexported fields
}

MCPServer represents an MCP server that can be connected to by MCP clients

func NewMCPServer

func NewMCPServer(port int, handler MCPServerHandler) *MCPServer

NewMCPServer creates a new MCP server

func (*MCPServer) Start

func (s *MCPServer) Start() error

Start starts the MCP server

func (*MCPServer) StartTLS

func (s *MCPServer) StartTLS(certFile, keyFile string) error

StartTLS starts the MCP server with TLS

func (*MCPServer) Stop

func (s *MCPServer) Stop() error

Stop stops the MCP server

type MCPServerHandler

type MCPServerHandler interface {
	// HandleToolCall handles a tool call request
	HandleToolCall(ctx context.Context, tool string, args map[string]interface{}) (json.RawMessage, error)

	// HandleResourceRead reads a resource
	HandleResourceRead(ctx context.Context, uri string) (json.RawMessage, error)

	// HandlePromptGet retrieves a prompt
	HandlePromptGet(ctx context.Context, name string, args map[string]interface{}) (string, error)

	// ListTools returns available tools
	ListTools() []Tool

	// ListResources returns available resources
	ListResources() []Resource

	// ListPrompts returns available prompts
	ListPrompts() []Prompt

	// HandleSamplingRequest handles LLM sampling requests from MCP clients
	HandleSamplingRequest(ctx context.Context, req *SamplingRequest) (*SamplingResponse, error)
}

MCPServerHandler defines the interface for handling MCP server requests

type MCPTool

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

MCPTool wraps an MCP tool for integration with the tool registry

func (*MCPTool) Description

func (t *MCPTool) Description() string

Description returns the tool description

func (*MCPTool) Execute

func (t *MCPTool) Execute(ctx context.Context, args map[string]interface{}) (interface{}, error)

Execute executes the MCP tool

func (*MCPTool) Name

func (t *MCPTool) Name() string

Name returns the tool name

func (*MCPTool) Parameters

func (t *MCPTool) Parameters() map[string]interface{}

Parameters returns the tool parameters

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

func (m *Manager) CallTool(ctx context.Context, serverName, toolName string, arguments map[string]interface{}) (interface{}, error)

CallTool calls an MCP tool

func (*Manager) ConnectSSE

func (m *Manager) ConnectSSE(name string, config ServerConfig) error

ConnectSSE connects to an MCP server using SSE transport

func (*Manager) ConnectStdio

func (m *Manager) ConnectStdio(name string, config ServerConfig) error

ConnectStdio connects to an MCP server using stdio transport

func (*Manager) Disconnect

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

Disconnect disconnects an MCP server

func (*Manager) GetServerInfo

func (m *Manager) GetServerInfo(name string) (map[string]interface{}, error)

GetServerInfo returns information about a connected MCP server

func (*Manager) HealthCheck

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

HealthCheck checks the health of a connected MCP server

func (*Manager) ListServers

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

ListServers lists all connected MCP servers

func (*Manager) ListTools

func (m *Manager) ListTools() []Tool

ListTools lists all available tools from all connected servers

func (*Manager) ListToolsByServer

func (m *Manager) ListToolsByServer(name string) ([]Tool, error)

ListToolsByServer lists tools available from a specific server

func (*Manager) RegisterAsTools

func (m *Manager) RegisterAsTools(registry interface {
	Register(interface {
		Name() string
		Description() string
		Parameters() map[string]interface{}
		Execute(context.Context, map[string]interface{}) (interface{}, error)
	})
})

RegisterAsTools registers all MCP tools with the tool registry

type Prompt

type Prompt struct {
	Name        string           `json:"name"`
	Description string           `json:"description,omitempty"`
	Arguments   []PromptArgument `json:"arguments,omitempty"`
}

Prompt represents an MCP prompt

type PromptArgument

type PromptArgument struct {
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
	Required    bool   `json:"required,omitempty"`
}

PromptArgument represents a prompt argument

type Resource

type Resource struct {
	URI         string `json:"uri"`
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
	MimeType    string `json:"mimeType,omitempty"`
}

Resource represents an MCP resource

type SSETransport

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

SSETransport implements MCP transport over Server-Sent Events

func NewSSETransport

func NewSSETransport(url string) (*SSETransport, error)

NewSSETransport creates a new SSE transport

func (*SSETransport) Close

func (t *SSETransport) Close() error

Close closes the SSE transport

func (*SSETransport) Send

Send sends a JSON-RPC request and returns the response

type SamplingMessage

type SamplingMessage struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

SamplingMessage represents a message in a sampling request

type SamplingRequest

type SamplingRequest struct {
	Method       string            `json:"method,omitempty"`
	Messages     []SamplingMessage `json:"messages"`
	MaxTokens    int               `json:"maxTokens,omitempty"`
	Temperature  float64           `json:"temperature,omitempty"`
	SystemPrompt string            `json:"systemPrompt,omitempty"`
	Tools        []Tool            `json:"tools,omitempty"`
}

SamplingRequest represents an MCP sampling request

type SamplingResponse

type SamplingResponse struct {
	Content string `json:"content"`
	Stopped string `json:"stoppedReason,omitempty"`
}

SamplingResponse represents a sampling response

type ServerConfig

type ServerConfig struct {
	Command   string   `json:"command"`
	Args      []string `json:"args"`
	Env       []string `json:"env,omitempty"`
	Transport string   `json:"transport"`     // "stdio" or "sse"
	URL       string   `json:"url,omitempty"` // for SSE transport
}

ServerConfig represents MCP server configuration

type StdioTransport

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

StdioTransport implements MCP transport over stdio

func NewStdioTransport

func NewStdioTransport(command string, args, env []string) (*StdioTransport, error)

NewStdioTransport creates a new stdio transport

func (*StdioTransport) Close

func (t *StdioTransport) Close() error

Close closes the stdio transport

func (*StdioTransport) Send

Send sends a JSON-RPC request and returns the response

type Tool

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

Tool represents an MCP tool

type Transport

type Transport interface {
	Send(ctx context.Context, req *JSONRPCRequest) (*JSONRPCResponse, error)
	Close() error
}

Transport interface for MCP transport layers

Jump to

Keyboard shortcuts

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