Documentation
¶
Overview ¶
Package server provides the MCP server implementation.
Package server provides the MCP server implementation.
Index ¶
- type Embeddable
- type HTTPAdapter
- type HTTPAdapterOption
- type MCPServer
- func (s *MCPServer) AddTool(ctx context.Context, tool *types.Tool, handler ToolHandler) error
- func (s *MCPServer) ExecuteTool(ctx context.Context, request ToolCallRequest) (interface{}, error)
- func (s *MCPServer) GetAddress() string
- func (s *MCPServer) GetServerInfo() ServerInfo
- func (s *MCPServer) GetTools() map[string]*types.Tool
- func (s *MCPServer) RegisterProvider(ctx context.Context, provider plugin.Provider) error
- func (s *MCPServer) RegisterSession(sessionID string, userAgent string, callback func([]byte) error) error
- func (s *MCPServer) SendToSession(sessionID string, message []byte) error
- func (s *MCPServer) ServeHTTP() error
- func (s *MCPServer) ServeStdio() error
- func (s *MCPServer) SetAddress(addr string)
- func (s *MCPServer) SetEmbedMode(embed bool)
- func (s *MCPServer) Shutdown(ctx context.Context) error
- func (s *MCPServer) ToHTTPHandler() http.Handler
- func (s *MCPServer) UnregisterProvider(ctx context.Context, providerID string) error
- func (s *MCPServer) UnregisterSession(sessionID string) error
- type ServerInfo
- type SessionCallback
- type ToolCallRequest
- type ToolHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Embeddable ¶ added in v1.1.0
type Embeddable interface { // ToHTTPHandler returns an http.Handler that can be used to integrate // the MCP server with any standard Go HTTP server ToHTTPHandler() http.Handler // AddTool adds a tool to the MCP server AddTool(ctx context.Context, tool *types.Tool, handler ToolHandler) error // GetServerInfo returns basic information about the server GetServerInfo() ServerInfo // RegisterSession registers a new client session with the server // This allows sending messages to specific clients RegisterSession(sessionID string, userAgent string, callback func([]byte) error) error // UnregisterSession removes a client session from the server UnregisterSession(sessionID string) error // ExecuteTool executes a tool with the given request ExecuteTool(ctx context.Context, request ToolCallRequest) (interface{}, error) // SendToSession sends a message to a specific session SendToSession(sessionID string, message []byte) error // GetTools returns all registered tools GetTools() map[string]*types.Tool }
Embeddable defines an interface for MCP servers that can be embedded in other applications like PocketBase, standard HTTP servers, etc.
type HTTPAdapter ¶ added in v1.1.0
type HTTPAdapter struct {
// contains filtered or unexported fields
}
HTTPAdapter adapts an Embeddable to be used in an HTTP server.
func NewHTTPAdapter ¶ added in v1.1.0
func NewHTTPAdapter(embeddable Embeddable, opts ...HTTPAdapterOption) *HTTPAdapter
NewHTTPAdapter creates a new HTTPAdapter.
func (*HTTPAdapter) Handler ¶ added in v1.1.0
func (a *HTTPAdapter) Handler() http.Handler
Handler returns an http.Handler that can be registered with an HTTP server.
type HTTPAdapterOption ¶ added in v1.1.0
type HTTPAdapterOption func(*HTTPAdapter)
HTTPAdapterOption is a function that configures an HTTP adapter.
func WithPath ¶ added in v1.1.0
func WithPath(basePath string) HTTPAdapterOption
WithPath sets the base path for the HTTP adapter.
type MCPServer ¶
type MCPServer struct {
// contains filtered or unexported fields
}
MCPServer represents an MCP server that can be used to handle MCP protocol messages. It supports both static tool registration and dynamic provider-based tools.
func NewMCPServer ¶
NewMCPServer creates a new MCP server with the specified name and version.
func (*MCPServer) ExecuteTool ¶ added in v1.1.0
func (s *MCPServer) ExecuteTool(ctx context.Context, request ToolCallRequest) (interface{}, error)
ExecuteTool executes a tool with the given request.
func (*MCPServer) GetAddress ¶
GetAddress returns the HTTP address for the server.
func (*MCPServer) GetServerInfo ¶ added in v1.1.0
func (s *MCPServer) GetServerInfo() ServerInfo
GetServerInfo returns basic information about the server
func (*MCPServer) RegisterProvider ¶
RegisterProvider registers a tool provider with the server.
func (*MCPServer) RegisterSession ¶ added in v1.1.0
func (s *MCPServer) RegisterSession(sessionID string, userAgent string, callback func([]byte) error) error
RegisterSession registers a new client session with the server. It returns an error if the session already exists.
func (*MCPServer) SendToSession ¶ added in v1.1.0
SendToSession sends a message to a specific session.
func (*MCPServer) ServeStdio ¶
ServeStdio serves the MCP server over standard I/O.
func (*MCPServer) SetAddress ¶
SetAddress sets the HTTP address for the server.
func (*MCPServer) SetEmbedMode ¶ added in v1.1.0
SetEmbedMode configures the MCPServer to work in embedded mode, which prevents it from binding to a port when ToHTTPHandler is called.
func (*MCPServer) ToHTTPHandler ¶ added in v1.1.0
ToHTTPHandler returns an http.Handler for the MCP server
func (*MCPServer) UnregisterProvider ¶
UnregisterProvider removes a tool provider from the server.
func (*MCPServer) UnregisterSession ¶ added in v1.1.0
UnregisterSession removes a client session from the server. It returns an error if the session does not exist.
type ServerInfo ¶ added in v1.1.0
type ServerInfo struct { // Name is the name of the server Name string // Version is the version of the server Version string // Address is the address the server is listening on Address string }
ServerInfo contains basic information about the MCP server
type SessionCallback ¶ added in v1.1.0
SessionCallback is a function that is called when messages need to be sent to a client.
type ToolCallRequest ¶
type ToolCallRequest struct { Name string Parameters map[string]interface{} Session *types.ClientSession }
ToolCallRequest represents a request to execute a tool.
type ToolHandler ¶
type ToolHandler func(ctx context.Context, request ToolCallRequest) (interface{}, error)
ToolHandler is a function that handles tool calls.