service

package
v0.26.2 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildMCPToolName

func BuildMCPToolName(toolName, serverName string) string

BuildMCPToolName 构建完整的工具名称

func McpService

func McpService() *mcpService

func ParseMCPToolName

func ParseMCPToolName(fullToolName string) (toolName, serverName string, err error)

ParseMCPToolName 从完整的工具名称中解析出服务器名称

Types

type MCPHost

type MCPHost struct {

	// 记录每个服务器的工具列表
	Tools map[string][]mcp.Tool
	// 记录每个服务器的资源能力
	Resources map[string][]mcp.Resource
	// 记录每个服务器的提示能力
	Prompts map[string][]mcp.Prompt
	// contains filtered or unexported fields
}

MCPHost MCP服务器管理器

func NewMCPHost

func NewMCPHost() *MCPHost

NewMCPHost 创建新的MCP管理器

func (*MCPHost) AddServer

func (m *MCPHost) AddServer(config ServerConfig) error

AddServer 添加服务器配置

func (*MCPHost) Close

func (m *MCPHost) Close()

Close 关闭所有连接

func (*MCPHost) ConnectServer

func (m *MCPHost) ConnectServer(ctx context.Context, serverName string) error

ConnectServer 连接到指定服务器

func (*MCPHost) ExecTools

func (m *MCPHost) ExecTools(ctx context.Context, toolCalls []openai.ToolCall) []models.MCPToolCallResult

func (*MCPHost) GetAllTools

func (m *MCPHost) GetAllTools(ctx context.Context) []openai.Tool

func (*MCPHost) GetClient

func (m *MCPHost) GetClient(ctx context.Context, serverName string) (*client.Client, error)

GetClient 获取指定服务器的客户端

func (*MCPHost) GetPrompts

func (m *MCPHost) GetPrompts(ctx context.Context, serverName string) ([]mcp.Prompt, error)

GetPrompts 获取指定服务器的提示能力

func (*MCPHost) GetResources

func (m *MCPHost) GetResources(ctx context.Context, serverName string) ([]mcp.Resource, error)

GetResources 获取指定服务器的资源能力

func (*MCPHost) GetServerNameByToolName

func (m *MCPHost) GetServerNameByToolName(toolName string) string

GetServerNameByToolName 根据工具名称获取对应的服务器名称 如果多个服务器都提供了相同的工具,返回第一个找到的服务器名称,有一定的随机性 如果没有找到对应的服务器,返回空字符串

func (*MCPHost) GetTools

func (m *MCPHost) GetTools(ctx context.Context, serverName string) ([]mcp.Tool, error)

GetTools 获取指定服务器的工具列表

func (*MCPHost) ListServers

func (m *MCPHost) ListServers() []MCPServer

func (*MCPHost) LogToolExecution

func (m *MCPHost) LogToolExecution(ctx context.Context, toolName, serverName string, parameters any, result models.MCPToolCallResult, executeTime int64)

LogToolExecution 记录工具执行日志

func (*MCPHost) RemoveServer

func (m *MCPHost) RemoveServer(config ServerConfig)

func (*MCPHost) RemoveServerById

func (m *MCPHost) RemoveServerById(id uint)

func (*MCPHost) SyncServerCapabilities

func (m *MCPHost) SyncServerCapabilities(ctx context.Context, serverName string) error

SyncServerCapabilities 同步服务器的工具、资源和提示能力

type MCPServer

type MCPServer struct {
	ServerConfig
	Config            ServerConfig          `json:"config,omitempty"`
	Tools             []mcp.Tool            `json:"tools,omitempty"`
	Resources         []mcp.Resource        `json:"resources,omitempty"`
	Prompts           []mcp.Prompt          `json:"prompts,omitempty"`
	InitializeResults *mcp.InitializeResult `json:"initialize_results,omitempty"`
}

type ServerConfig

type ServerConfig struct {
	ID      uint   `json:"id"`
	URL     string `json:"url,omitempty"`
	Name    string `json:"name,omitempty"`
	Enabled bool   `json:"enabled,omitempty"`
}

ServerConfig 服务器配置

Jump to

Keyboard shortcuts

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