Documentation
¶
Overview ¶
Package server provides the MCP server implementation.
Package server provides the MCP server implementation.
Index ¶
- type ClientSession
- type NotificationHandlerFunc
- type SSEContextFunc
- type Server
- func (s *Server) HandleMessage(ctx context.Context, sessionID string, rawMessage json.RawMessage) *protocol.JSONRPCResponse
- func (s *Server) NotifyResourceUpdated(resource protocol.Resource)
- func (s *Server) RegisterNotificationHandler(method string, handler NotificationHandlerFunc) error
- func (s *Server) RegisterPrompt(prompt protocol.Prompt) error
- func (s *Server) RegisterResource(resource protocol.Resource) error
- func (s *Server) RegisterSession(session ClientSession) error
- func (s *Server) RegisterTool(tool protocol.Tool, handler ToolHandlerFunc) error
- func (s *Server) ResourceRegistry() map[string]protocol.Resource
- func (s *Server) SendProgress(sessionID string, params protocol.ProgressParams) error
- func (s *Server) SendPromptsListChanged() error
- func (s *Server) SendResourcesListChanged() error
- func (s *Server) SendToolsListChanged() error
- func (s *Server) UnregisterPrompt(uri string) error
- func (s *Server) UnregisterResource(uri string) error
- func (s *Server) UnregisterSession(sessionID string)
- type ServerOptions
- type ToolHandlerFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ClientSession ¶
type ClientSession interface {
// SessionID returns a unique identifier for this session.
SessionID() string
// SendNotification sends a JSON-RPC notification to the client session.
SendNotification(notification protocol.JSONRPCNotification) error
// SendResponse sends a JSON-RPC response to the client session.
SendResponse(response protocol.JSONRPCResponse) error
// Close terminates the client session and cleans up resources.
Close() error
// Initialize marks the session as having completed the MCP handshake.
Initialize()
// Initialized returns true if the session has completed the MCP handshake.
Initialized() bool
}
ClientSession represents an active connection from a single client. The core MCPServer uses this interface to interact with connected clients, primarily for sending asynchronous messages like notifications or responses that aren't part of a direct request-response flow handled by HandleMessage.
type NotificationHandlerFunc ¶
NotificationHandlerFunc defines the signature for functions that handle client-to-server notifications.
type SSEContextFunc ¶
SSEContextFunc is a function type used by the SSEServer to allow customization of the context passed to the core MCPServer's HandleMessage method, based on the incoming HTTP request for client->server messages. This allows injecting values from HTTP headers (like auth tokens) into the context.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server represents the core MCP server logic, independent of transport.
func NewServer ¶
func NewServer(serverName string, opts ServerOptions) *Server
NewServer creates a new core MCP Server logic instance.
func (*Server) HandleMessage ¶
func (s *Server) HandleMessage(ctx context.Context, sessionID string, rawMessage json.RawMessage) *protocol.JSONRPCResponse
func (*Server) NotifyResourceUpdated ¶
func (*Server) RegisterNotificationHandler ¶
func (s *Server) RegisterNotificationHandler(method string, handler NotificationHandlerFunc) error
func (*Server) RegisterResource ¶
func (*Server) RegisterSession ¶
func (s *Server) RegisterSession(session ClientSession) error
func (*Server) RegisterTool ¶
func (s *Server) RegisterTool(tool protocol.Tool, handler ToolHandlerFunc) error
func (*Server) SendProgress ¶
func (s *Server) SendProgress(sessionID string, params protocol.ProgressParams) error
func (*Server) SendPromptsListChanged ¶
func (*Server) SendResourcesListChanged ¶
func (*Server) SendToolsListChanged ¶
func (*Server) UnregisterPrompt ¶
func (*Server) UnregisterResource ¶
func (*Server) UnregisterSession ¶
type ServerOptions ¶
type ServerOptions struct {
Logger types.Logger
ServerCapabilities protocol.ServerCapabilities
}
ServerOptions contains configuration options for creating a Server.
type ToolHandlerFunc ¶
type ToolHandlerFunc func(ctx context.Context, progressToken *protocol.ProgressToken, arguments map[string]interface{}) (content []protocol.Content, isError bool)
ToolHandlerFunc defines the signature for functions that handle tool execution.