server

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2025 License: MIT Imports: 8 Imported by: 1

Documentation

Overview

Package server provides the MCP server implementation.

Package server provides the MCP server implementation.

Index

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

type NotificationHandlerFunc func(ctx context.Context, params interface{}) error

NotificationHandlerFunc defines the signature for functions that handle client-to-server notifications.

type SSEContextFunc

type SSEContextFunc func(ctx context.Context, r *http.Request) context.Context

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 (s *Server) NotifyResourceUpdated(resource protocol.Resource)

func (*Server) RegisterNotificationHandler

func (s *Server) RegisterNotificationHandler(method string, handler NotificationHandlerFunc) error

func (*Server) RegisterPrompt

func (s *Server) RegisterPrompt(prompt protocol.Prompt) error

func (*Server) RegisterResource

func (s *Server) RegisterResource(resource protocol.Resource) error

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) ResourceRegistry

func (s *Server) ResourceRegistry() map[string]protocol.Resource

func (*Server) SendProgress

func (s *Server) SendProgress(sessionID string, params protocol.ProgressParams) error

func (*Server) SendPromptsListChanged

func (s *Server) SendPromptsListChanged() error

func (*Server) SendResourcesListChanged

func (s *Server) SendResourcesListChanged() error

func (*Server) SendToolsListChanged

func (s *Server) SendToolsListChanged() error

func (*Server) UnregisterPrompt

func (s *Server) UnregisterPrompt(uri string) error

func (*Server) UnregisterResource

func (s *Server) UnregisterResource(uri string) error

func (*Server) UnregisterSession

func (s *Server) UnregisterSession(sessionID string)

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 any) (content []protocol.Content, isError bool)

ToolHandlerFunc defines the signature for functions that handle tool execution.

Jump to

Keyboard shortcuts

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