mcp

package
v1.10.8 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ParseError     = -32700
	InvalidRequest = -32600
	MethodNotFound = -32601
	InvalidParams  = -32602
	InternalError  = -32603
)

Standard JSON-RPC error codes

View Source
const MCPVersion = "2024-11-05"

MCP 协议版本

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientCapabilities

type ClientCapabilities struct {
	Roots        *RootsCapability       `json:"roots,omitempty"`
	Sampling     *SamplingCapability    `json:"sampling,omitempty"`
	Experimental map[string]interface{} `json:"experimental,omitempty"`
}

ClientCapabilities 客户端能力

type ClientInfo

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

ClientInfo 客户端信息

type Connection

type Connection struct {
	ID       string
	Reader   *bufio.Scanner
	Writer   io.Writer
	Context  context.Context
	Cancel   context.CancelFunc
	Metadata map[string]interface{}
}

Connection 连接对象

type Content

type Content struct {
	Type string `json:"type"`
	Text string `json:"text,omitempty"`
	Data string `json:"data,omitempty"`
	URI  string `json:"uri,omitempty"`
}

Content 内容

func TextContent

func TextContent(text string) Content

TextContent 文本内容

type FileCodeBoxMCPServer

type FileCodeBoxMCPServer struct {
	*Server
	// contains filtered or unexported fields
}

FileCodeBoxMCPServer FileCodeBox MCP 服务器

func NewFileCodeBoxMCPServer

func NewFileCodeBoxMCPServer(
	manager *config.ConfigManager,
	repositoryManager *repository.RepositoryManager,
	storageManager *storage.StorageManager,
	shareService *services.ShareService,
	adminService *services.AdminService,
	userService *services.UserService,
) *FileCodeBoxMCPServer

NewFileCodeBoxMCPServer 创建 FileCodeBox MCP 服务器

type InitializeRequest

type InitializeRequest struct {
	ProtocolVersion string                 `json:"protocolVersion"`
	Capabilities    ClientCapabilities     `json:"capabilities"`
	ClientInfo      ClientInfo             `json:"clientInfo"`
	Meta            map[string]interface{} `json:"meta,omitempty"`
}

InitializeRequest 初始化请求

type InitializeResult

type InitializeResult struct {
	ProtocolVersion string             `json:"protocolVersion"`
	Capabilities    ServerCapabilities `json:"capabilities"`
	ServerInfo      ServerInfo         `json:"serverInfo"`
	Instructions    string             `json:"instructions,omitempty"`
}

InitializeResult 初始化结果

type JSONRPCMessage

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

JSONRPCMessage JSON-RPC 2.0 消息

func NewJSONRPCError

func NewJSONRPCError(id interface{}, code int, message string, data interface{}) *JSONRPCMessage

NewJSONRPCError 创建 JSON-RPC 错误响应

func NewJSONRPCNotification

func NewJSONRPCNotification(method string, params interface{}) *JSONRPCMessage

NewJSONRPCNotification 创建 JSON-RPC 通知

func NewJSONRPCRequest

func NewJSONRPCRequest(id interface{}, method string, params interface{}) *JSONRPCMessage

NewJSONRPCRequest 创建 JSON-RPC 请求

func NewJSONRPCResponse

func NewJSONRPCResponse(id interface{}, result interface{}) *JSONRPCMessage

NewJSONRPCResponse 创建 JSON-RPC 响应

func (*JSONRPCMessage) MarshalJSON

func (msg *JSONRPCMessage) MarshalJSON() ([]byte, error)

MarshalJSON 自定义 JSON 序列化

type LogLevel

type LogLevel string

LogLevel 日志级别

const (
	LogLevelDebug   LogLevel = "debug"
	LogLevelInfo    LogLevel = "info"
	LogLevelNotice  LogLevel = "notice"
	LogLevelWarning LogLevel = "warning"
	LogLevelError   LogLevel = "error"
	LogLevelCrit    LogLevel = "crit"
	LogLevelAlert   LogLevel = "alert"
	LogLevelEmerg   LogLevel = "emerg"
)

type LoggingCapability

type LoggingCapability struct{}

LoggingCapability 日志能力

type LoggingMessageNotification

type LoggingMessageNotification struct {
	Level  LogLevel               `json:"level"`
	Data   interface{}            `json:"data"`
	Logger string                 `json:"logger,omitempty"`
	Meta   map[string]interface{} `json:"meta,omitempty"`
}

LoggingMessageNotification 日志消息通知

type MCPManager

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

MCPManager MCP 服务器管理器

func NewMCPManager

func NewMCPManager(
	manager *config.ConfigManager,
	daoManager *repository.RepositoryManager,
	storageManager *storage.StorageManager,
	shareService *services.ShareService,
	adminService *services.AdminService,
	userService *services.UserService,
) *MCPManager

NewMCPManager 创建新的 MCP 管理器

func (*MCPManager) ApplyConfig

func (m *MCPManager) ApplyConfig(enableMCP bool, port string) error

ApplyConfig 应用配置更改

func (*MCPManager) GetStatus

func (m *MCPManager) GetStatus() MCPStatus

GetStatus 获取 MCP 服务器状态

func (*MCPManager) IsRunning

func (m *MCPManager) IsRunning() bool

IsRunning 检查 MCP 服务器是否在运行

func (*MCPManager) RestartMCPServer

func (m *MCPManager) RestartMCPServer(port string) error

RestartMCPServer 重启 MCP 服务器

func (*MCPManager) StartMCPServer

func (m *MCPManager) StartMCPServer(port string) error

StartMCPServer 启动 MCP 服务器

func (*MCPManager) StopMCPServer

func (m *MCPManager) StopMCPServer() error

StopMCPServer 停止 MCP 服务器

type MCPStatus added in v1.7.1

type MCPStatus struct {
	Running    bool       `json:"running"`
	Timestamp  string     `json:"timestamp"`
	ServerInfo ServerInfo `json:"server_info,omitempty"`
}

MCPStatus MCP服务器状态

type PromptsCapability

type PromptsCapability struct {
	ListChanged bool `json:"listChanged,omitempty"`
}

PromptsCapability 提示能力

type RPCError

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

RPCError JSON-RPC 错误

func (*RPCError) Error

func (e *RPCError) Error() string

Error 实现 error 接口

type Resource

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

Resource 资源定义

type ResourceContents

type ResourceContents struct {
	URI      string `json:"uri"`
	MimeType string `json:"mimeType,omitempty"`
	Text     string `json:"text,omitempty"`
	Blob     string `json:"blob,omitempty"` // Base64 encoded
}

ResourceContents 资源内容

type ResourceReader

type ResourceReader func(ctx context.Context, uri string) (*ResourcesReadResult, error)

ResourceReader 资源读取器函数

type ResourcesCapability

type ResourcesCapability struct {
	Subscribe   bool `json:"subscribe,omitempty"`
	ListChanged bool `json:"listChanged,omitempty"`
}

ResourcesCapability 资源能力

type ResourcesListRequest

type ResourcesListRequest struct {
	Cursor string `json:"cursor,omitempty"`
}

ResourcesListRequest 资源列表请求

type ResourcesListResult

type ResourcesListResult struct {
	Resources  []Resource `json:"resources"`
	NextCursor *string    `json:"nextCursor,omitempty"`
}

ResourcesListResult 资源列表结果

type ResourcesReadRequest

type ResourcesReadRequest struct {
	URI string `json:"uri"`
}

ResourcesReadRequest 资源读取请求

type ResourcesReadResult

type ResourcesReadResult struct {
	Contents []ResourceContents `json:"contents"`
}

ResourcesReadResult 资源读取结果

type RootsCapability

type RootsCapability struct {
	ListChanged bool `json:"listChanged,omitempty"`
}

RootsCapability 根目录能力

type SamplingCapability

type SamplingCapability struct{}

SamplingCapability 采样能力

type Server

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

Server MCP 服务器

func NewServer

func NewServer(name, version string) *Server

NewServer 创建新的 MCP 服务器

func (*Server) AddResource

func (s *Server) AddResource(resource Resource, reader ResourceReader)

AddResource 添加资源

func (*Server) AddTool

func (s *Server) AddTool(tool Tool, handler ToolHandler)

AddTool 添加工具

func (*Server) IsInitialized

func (s *Server) IsInitialized() bool

IsInitialized 检查是否已初始化

func (*Server) LogMessage

func (s *Server) LogMessage(level LogLevel, data interface{}, logger string)

LogMessage 发送日志消息到客户端

func (*Server) ServeStdio

func (s *Server) ServeStdio() error

ServeStdio 通过 stdio 提供服务

func (*Server) ServeTCP

func (s *Server) ServeTCP(addr string) error

ServeTCP 通过 TCP 提供服务

func (*Server) SetInstructions

func (s *Server) SetInstructions(instructions string)

SetInstructions 设置服务器说明

type ServerCapabilities

type ServerCapabilities struct {
	Logging      *LoggingCapability     `json:"logging,omitempty"`
	Prompts      *PromptsCapability     `json:"prompts,omitempty"`
	Resources    *ResourcesCapability   `json:"resources,omitempty"`
	Tools        *ToolsCapability       `json:"tools,omitempty"`
	Experimental map[string]interface{} `json:"experimental,omitempty"`
}

ServerCapabilities 服务器能力

type ServerInfo

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

ServerInfo 服务器信息

type Tool

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

Tool 工具定义

type ToolCallRequest

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

ToolCallRequest 工具调用请求

type ToolCallResult

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

ToolCallResult 工具调用结果

type ToolHandler

type ToolHandler func(ctx context.Context, arguments map[string]interface{}) (*ToolCallResult, error)

ToolHandler 工具处理器函数

type ToolsCapability

type ToolsCapability struct {
	ListChanged bool `json:"listChanged,omitempty"`
}

ToolsCapability 工具能力

type ToolsListRequest

type ToolsListRequest struct {
	Cursor string `json:"cursor,omitempty"`
}

ToolsListRequest 工具列表请求

type ToolsListResult

type ToolsListResult struct {
	Tools      []Tool  `json:"tools"`
	NextCursor *string `json:"nextCursor,omitempty"`
}

ToolsListResult 工具列表结果

Jump to

Keyboard shortcuts

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