mcphost

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package mcphost provides MCP (Model Context Protocol) host management for TokMan

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientInfo

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

ClientInfo represents client information

type Error

type Error struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data,omitempty"`
}

Error represents an MCP error

type EventHandler

type EventHandler func(event HostEvent)

EventHandler handles host events

type EventType

type EventType string

EventType represents event types

const (
	EventServerConnected    EventType = "server_connected"
	EventServerDisconnected EventType = "server_disconnected"
	EventServerError        EventType = "server_error"
	EventSessionCreated     EventType = "session_created"
	EventSessionClosed      EventType = "session_closed"
	EventToolCalled         EventType = "tool_called"
	EventResourceAccessed   EventType = "resource_accessed"
)

type Host

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

Host manages MCP server connections

func NewHost

func NewHost(config HostConfig) *Host

NewHost creates a new MCP host

func (*Host) CallTool

func (h *Host) CallTool(ctx context.Context, serverID string, toolName string, arguments map[string]interface{}) (json.RawMessage, error)

CallTool invokes a tool on a server

func (*Host) CloseSession

func (h *Host) CloseSession(sessionID string) error

CloseSession closes a session

func (*Host) ConnectServer

func (h *Host) ConnectServer(ctx context.Context, serverID string) error

ConnectServer connects to an MCP server

func (*Host) CreateSession

func (h *Host) CreateSession(clientInfo ClientInfo, serverID string) (*Session, error)

CreateSession creates a new client session

func (*Host) DisconnectServer

func (h *Host) DisconnectServer(serverID string) error

DisconnectServer disconnects from a server

func (*Host) GetServer

func (h *Host) GetServer(id string) (*Server, error)

GetServer returns a server by ID

func (*Host) ID

func (h *Host) ID() string

ID returns the host ID

func (*Host) ListServers

func (h *Host) ListServers() []*Server

ListServers returns all registered servers

func (*Host) ListTools

func (h *Host) ListTools(serverID string) ([]Tool, error)

ListTools returns all tools from a server

func (*Host) Name

func (h *Host) Name() string

Name returns the host name

func (*Host) ReadResource

func (h *Host) ReadResource(ctx context.Context, serverID string, uri string) (json.RawMessage, error)

ReadResource reads a resource from a server

func (*Host) RegisterServer

func (h *Host) RegisterServer(id string, name string, transport Transport) (*Server, error)

RegisterServer registers an MCP server

func (*Host) SetEventHandler

func (h *Host) SetEventHandler(handler EventHandler)

SetEventHandler sets the event handler

func (*Host) Shutdown

func (h *Host) Shutdown() error

Shutdown gracefully shuts down the host

type HostCapabilities

type HostCapabilities struct {
	Tools     bool
	Resources bool
	Prompts   bool
	Logging   bool
}

HostCapabilities defines what the host supports

type HostConfig

type HostConfig struct {
	Name              string
	Version           string
	MaxConnections    int
	ConnectionTimeout time.Duration
	RequestTimeout    time.Duration
	AutoReconnect     bool
	Capabilities      HostCapabilities
}

HostConfig holds host configuration

type HostEvent

type HostEvent struct {
	Type      EventType
	Timestamp time.Time
	ServerID  string
	SessionID string
	Message   string
	Data      interface{}
}

HostEvent represents a host event

type LoggingCapability

type LoggingCapability struct {
}

LoggingCapability defines logging support

type Message

type Message struct {
	JSONRPC string          `json:"jsonrpc"`
	ID      interface{}     `json:"id,omitempty"`
	Method  string          `json:"method,omitempty"`
	Params  json.RawMessage `json:"params,omitempty"`
	Result  json.RawMessage `json:"result,omitempty"`
	Error   *Error          `json:"error,omitempty"`
}

Message represents an MCP protocol message

type Prompt

type Prompt struct {
	Name        string
	Description string
	Arguments   []PromptArgument
}

Prompt represents an MCP prompt

type PromptArgument

type PromptArgument struct {
	Name        string
	Description string
	Required    bool
}

PromptArgument represents a prompt argument

type PromptsCapability

type PromptsCapability struct {
	ListChanged bool
}

PromptsCapability defines prompt support

type Resource

type Resource struct {
	URI         string
	Name        string
	Description string
	MimeType    string
}

Resource represents an MCP resource

type ResourcesCapability

type ResourcesCapability struct {
	Subscribe   bool
	ListChanged bool
}

ResourcesCapability defines resource support

type Server

type Server struct {
	ID           string
	Name         string
	Version      string
	Transport    Transport
	Status       ServerStatus
	Capabilities ServerCapabilities
	Tools        []Tool
	Resources    []Resource
	Prompts      []Prompt
	LastPing     time.Time
	ConnectTime  time.Time
	// contains filtered or unexported fields
}

Server represents a connected MCP server

type ServerCapabilities

type ServerCapabilities struct {
	Tools     *ToolsCapability
	Resources *ResourcesCapability
	Prompts   *PromptsCapability
	Logging   *LoggingCapability
}

ServerCapabilities defines what a server supports

type ServerStatus

type ServerStatus string

ServerStatus represents server connection status

const (
	ServerStatusDisconnected ServerStatus = "disconnected"
	ServerStatusConnecting   ServerStatus = "connecting"
	ServerStatusConnected    ServerStatus = "connected"
	ServerStatusError        ServerStatus = "error"
)

type Session

type Session struct {
	ID           string
	ClientInfo   ClientInfo
	ServerID     string
	Status       SessionStatus
	CreatedAt    time.Time
	LastActivity time.Time
	// contains filtered or unexported fields
}

Session represents a client session

type SessionStatus

type SessionStatus string

SessionStatus represents session status

const (
	SessionStatusActive   SessionStatus = "active"
	SessionStatusInactive SessionStatus = "inactive"
	SessionStatusClosed   SessionStatus = "closed"
)

type Tool

type Tool struct {
	Name        string
	Description string
	InputSchema json.RawMessage
}

Tool represents an MCP tool

type ToolsCapability

type ToolsCapability struct {
	ListChanged bool
}

ToolsCapability defines tool support

type Transport

type Transport interface {
	Connect(ctx context.Context) error
	Disconnect() error
	Send(message Message) error
	Receive() (Message, error)
	IsConnected() bool
}

Transport defines the interface for MCP transports

Jump to

Keyboard shortcuts

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