server

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

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 WithLogger

func WithLogger(l logger.Logger) Option

WithLogger sets the logger for the server

func WithPrompts

func WithPrompts(initialPrompts []types.Prompt) Option

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

func WithTools

func WithTools(initialTools ...types.McpTool) Option

WithTools enables tools functionality on the server

type Server

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

Server represents a Model Context Protocol server

func NewDefaultServer

func NewDefaultServer(opts ...Option) *Server

NewDefaultServer creates an MCP server with default settings

func NewServer

func NewServer(transport transport.Transport, opts ...Option) *Server

NewServer creates a new MCP server

func NewSseServer added in v0.2.0

func NewSseServer(listenAddr string, opts ...Option) *Server

NewSseServer creates an MCP server listening on `listenAddr` (e.g. ":8080") via SSE.

func (*Server) Close

func (s *Server) Close() error

Close shuts down the server

func (*Server) CreateMessage

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

func (s *Server) ListRoots(ctx context.Context) ([]types.Root, error)

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

func (s *Server) NotifyResourceUpdated(ctx context.Context, uri string) error

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

func (s *Server) SetPrompts(ctx context.Context, prompts []types.Prompt) error

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

func (s *Server) SetResources(ctx context.Context, resources []types.Resource) error

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

func (s *Server) SetTools(ctx context.Context, newTools []types.McpTool) error

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

func (s *Server) Start(ctx context.Context) error

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

func (s *Server) SupportsPrompts() bool

SupportsPrompts returns whether the server supports prompts functionality

func (*Server) SupportsResources

func (s *Server) SupportsResources() bool

SupportsResources returns whether the server supports resources functionality

func (*Server) SupportsRoots

func (s *Server) SupportsRoots() bool

SupportsRoots returns whether the client supports roots functionality

func (*Server) SupportsSampling

func (s *Server) SupportsSampling() bool

SupportsSampling returns whether the client supports sampling functionality

func (*Server) SupportsTools

func (s *Server) SupportsTools() bool

SupportsTools returns whether the server supports tools functionality

Jump to

Keyboard shortcuts

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