mcphost

package
v5.0.0-...-47996ed Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2025 License: Apache-2.0 Imports: 31 Imported by: 0

README

mcphost

This package is a fork of mark3labs/mcphost, it helps HttpRunner to interact with external tools through the Model Context Protocol (MCP).

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActionToolProvider

type ActionToolProvider interface {
	GetToolByAction(actionName option.ActionName) uixt.ActionTool
}

ActionToolProvider defines the interface for MCP servers that provide ActionTool implementations

type Chat

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

Chat represents a chat session with LLM

func (*Chat) Start

func (c *Chat) Start(ctx context.Context) error

Start starts the chat session

type Connection

type Connection struct {
	Client client.MCPClient
	Config ServerConfig
}

Connection represents a connection to an MCP server

type DocStringInfo

type DocStringInfo struct {
	Description string
	Parameters  map[string]string
	Returns     map[string]string
}

DocStringInfo contains the parsed information from a Python docstring

type MCPConfig

type MCPConfig struct {
	ConfigPath string                         `json:"-"`
	MCPServers map[string]ServerConfigWrapper `json:"mcpServers"`
}

MCPConfig represents the configuration for MCP servers

func LoadMCPConfig

func LoadMCPConfig(configPath string) (*MCPConfig, error)

LoadMCPConfig loads the MCP configuration from the specified path or default location

type MCPHost

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

MCPHost manages MCP server connections and tools

func NewMCPHost

func NewMCPHost(configPath string, withUIXT bool) (*MCPHost, error)

NewMCPHost creates a new MCPHost instance

func (*MCPHost) CloseServers

func (h *MCPHost) CloseServers() error

CloseServers closes all connected MCP servers

func (*MCPHost) ConvertToolsToRecords

func (host *MCPHost) ConvertToolsToRecords(tools []MCPTools) []MCPToolRecord

ConvertToolsToRecords converts []MCPTools to a list of database records

func (*MCPHost) ExportToolsToJSON

func (h *MCPHost) ExportToolsToJSON(ctx context.Context, dumpPath string) error

ExportToolsToJSON dumps MCP tools to JSON file

func (*MCPHost) GetAllClients

func (h *MCPHost) GetAllClients() map[string]client.MCPClient

GetAllClients returns all MCP clients

func (*MCPHost) GetClient

func (h *MCPHost) GetClient(serverName string) (client.MCPClient, error)

GetClient returns the client for the specified server

func (*MCPHost) GetEinoTool

func (h *MCPHost) GetEinoTool(ctx context.Context, serverName, toolName string) (tool.BaseTool, error)

GetEinoTool returns an eino tool for the given server and tool name

func (*MCPHost) GetEinoToolInfos

func (h *MCPHost) GetEinoToolInfos(ctx context.Context) ([]*schema.ToolInfo, error)

GetEinoToolInfos convert MCP tools to eino tool infos

func (*MCPHost) GetTool

func (h *MCPHost) GetTool(ctx context.Context, serverName, toolName string) (*mcp.Tool, error)

GetTool returns a specific tool from a server

func (*MCPHost) GetTools

func (h *MCPHost) GetTools(ctx context.Context) []MCPTools

GetTools returns all tools from all MCP servers

func (*MCPHost) InitServers

func (h *MCPHost) InitServers(ctx context.Context) error

InitServers initializes all MCP servers

func (*MCPHost) InvokeTool

func (h *MCPHost) InvokeTool(ctx context.Context,
	serverName, toolName string, arguments map[string]any,
) (*mcp.CallToolResult, error)

InvokeTool calls a tool with the given arguments

func (*MCPHost) NewChat

func (h *MCPHost) NewChat(ctx context.Context) (*Chat, error)

NewChat creates a new chat session

func (*MCPHost) Shutdown

func (h *MCPHost) Shutdown()

Shutdown gracefully shuts down all MCP servers

type MCPToolRecord

type MCPToolRecord struct {
	ToolID          string    `json:"tool_id"`          // Unique identifier for the tool record
	BizID           string    `json:"biz_id"`           // Business ID of the tool
	VisibleRange    int       `json:"visible_range"`    // Visible range of the tool, 0: visible to biz, 1: visible to all
	ToolType        string    `json:"tool_type"`        // Type of the tool
	ServerName      string    `json:"mcp_server"`       // Name of the MCP server
	ToolName        string    `json:"tool_name"`        // Name of the tool
	Description     string    `json:"description"`      // Tool description
	Parameters      string    `json:"parameters"`       // Tool input parameters in JSON format
	Returns         string    `json:"return_desc"`      // Tool return value format in JSON format
	TeardownPair    string    `json:"teardown_pair"`    // Teardown pair of the tool
	Examples        string    `json:"examples"`         // Examples of the tool
	SupportPatterns string    `json:"support_patterns"` // Support pattern of the tool
	CreatedAt       time.Time `json:"created_at"`       // Record creation time
	LastUpdatedAt   time.Time `json:"last_updated_at"`  // Record last update time
}

MCPToolRecord represents a single tool record in the database Each record contains detailed information about a tool and its server

type MCPTools

type MCPTools struct {
	ServerName string
	Tools      []mcp.Tool
	Err        error
}

MCPTools represents tools from a single MCP server

type SSEServerConfig

type SSEServerConfig struct {
	Url      string   `json:"url"`
	Headers  []string `json:"headers,omitempty"`
	Disabled bool     `json:"disabled,omitempty"`
}

SSEServerConfig represents configuration for an SSE-based server

func (SSEServerConfig) GetType

func (s SSEServerConfig) GetType() string

func (SSEServerConfig) IsDisabled

func (s SSEServerConfig) IsDisabled() bool

type STDIOServerConfig

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

STDIOServerConfig represents configuration for a STDIO-based server

func (STDIOServerConfig) GetType

func (s STDIOServerConfig) GetType() string

func (STDIOServerConfig) IsDisabled

func (s STDIOServerConfig) IsDisabled() bool

type ServerConfig

type ServerConfig interface {
	GetType() string
	IsDisabled() bool
}

ServerConfig is an interface for different types of server configurations

type ServerConfigWrapper

type ServerConfigWrapper struct {
	Config ServerConfig
}

ServerConfigWrapper is a wrapper for different types of server configurations

func (ServerConfigWrapper) MarshalJSON

func (w ServerConfigWrapper) MarshalJSON() ([]byte, error)

func (*ServerConfigWrapper) UnmarshalJSON

func (w *ServerConfigWrapper) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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