Documentation
¶
Index ¶
- type Option
- type Server
- func (s *Server) Close() error
- func (s *Server) CreateMessage(ctx context.Context, req *types.CreateMessageRequest) (*types.CreateMessageResult, error)
- func (s *Server) Done() <-chan struct{}
- func (s *Server) ListRoots(ctx context.Context) ([]types.Root, error)
- func (s *Server) NotifyResourceUpdated(ctx context.Context, uri string) error
- func (s *Server) OnRootsChanged(callback func())
- func (s *Server) RegisterContentHandler(uriPrefix string, handler resources.ContentHandler)
- func (s *Server) RegisterPromptGetter(name string, getter prompts.PromptGetter)
- func (s *Server) SetPrompts(ctx context.Context, prompts []types.Prompt) error
- func (s *Server) SetResourceTemplates(ctx context.Context, templates []types.ResourceTemplate)
- func (s *Server) SetResources(ctx context.Context, resources []types.Resource) error
- func (s *Server) SetTools(ctx context.Context, newTools []types.McpTool) error
- func (s *Server) Start(ctx context.Context) error
- func (s *Server) SupportsPrompts() bool
- func (s *Server) SupportsResources() bool
- func (s *Server) SupportsRoots() bool
- func (s *Server) SupportsSampling() bool
- func (s *Server) SupportsTools() bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*Server)
Option is a function that configures a Server
func WithPrompts ¶
WithPrompts enables prompts functionality on the server
func WithResources ¶
func WithResources(initialResources []types.Resource, initialTemplates []types.ResourceTemplate) Option
WithResources enables resources functionality on the server
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server represents a Model Context Protocol server
func NewDefaultServer ¶
NewDefaultServer creates an MCP server with default settings
func NewSseServer ¶ added in v0.2.0
NewSseServer creates an MCP server listening on `listenAddr` (e.g. ":8080") via SSE.
func (*Server) CreateMessage ¶
func (s *Server) CreateMessage(ctx context.Context, req *types.CreateMessageRequest) (*types.CreateMessageResult, error)
CreateMessage requests a sample from the language model. Returns an error if sampling is not supported.
func (*Server) Done ¶
func (s *Server) Done() <-chan struct{}
Done returns a channel that is closed when the transport is closed
func (*Server) ListRoots ¶
ListRoots requests the list of available roots from the connected client. Returns an error if roots are not supported by the client.
func (*Server) NotifyResourceUpdated ¶
NotifyResourceUpdated notifies subscribed clients that a resource has changed. Returns an error if resources are not supported or if notification fails.
func (*Server) OnRootsChanged ¶
func (s *Server) OnRootsChanged(callback func())
OnRootsChanged registers a callback for when the client's root list changes. The callback is not invoked if roots are not supported.
func (*Server) RegisterContentHandler ¶
func (s *Server) RegisterContentHandler(uriPrefix string, handler resources.ContentHandler)
RegisterContentHandler registers a handler for reading resource contents. The handler is called when clients request to read resources with URIs matching the given prefix.
func (*Server) RegisterPromptGetter ¶
func (s *Server) RegisterPromptGetter(name string, getter prompts.PromptGetter)
RegisterPromptGetter registers a handler for retrieving prompt contents. The handler is called when clients request prompts by the given name.
func (*Server) SetPrompts ¶
SetPrompts updates the list of available prompts and notifies connected clients. Returns an error if prompts are not supported or if the update fails.
func (*Server) SetResourceTemplates ¶
func (s *Server) SetResourceTemplates(ctx context.Context, templates []types.ResourceTemplate)
SetResourceTemplates updates the list of available resource templates.
func (*Server) SetResources ¶
SetResources updates the list of available resources and notifies connected clients. Returns an error if resources are not supported or if the update fails.
func (*Server) SetTools ¶
SetTools updates the list of available tools and notifies connected clients. Returns an error if tools are not supported or if the update fails.
func (*Server) Start ¶
Start begins processing messages but also makes sure that the server's ctx is canceled if the transport closes, so you can shut down everything automatically.
func (*Server) SupportsPrompts ¶
SupportsPrompts returns whether the server supports prompts functionality
func (*Server) SupportsResources ¶
SupportsResources returns whether the server supports resources functionality
func (*Server) SupportsRoots ¶
SupportsRoots returns whether the client supports roots functionality
func (*Server) SupportsSampling ¶
SupportsSampling returns whether the client supports sampling functionality
func (*Server) SupportsTools ¶
SupportsTools returns whether the server supports tools functionality