server

package
v0.0.0-...-1267af6 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxMessageSize is the maximum size of any message in bytes (10MB)
	MaxMessageSize = 10 * 1024 * 1024
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseServer

type BaseServer struct {
	*common.Base
	transport.BaseTransport
	// contains filtered or unexported fields
}

BaseServer provides a basic implementation of the Server interface

func NewServer

func NewServer(options *InitializationOptions) *BaseServer

NewServer creates a new BaseServer instance

func (*BaseServer) ApplyResourceTemplate

func (s *BaseServer) ApplyResourceTemplate(ctx context.Context, template types.ResourceTemplate) (*types.ResourceTemplateResult, error)

ApplyResourceTemplate applies a resource template with the given parameters

func (*BaseServer) GetInitializationOptions

func (s *BaseServer) GetInitializationOptions() *InitializationOptions

GetInitializationOptions returns the server initialization options

func (*BaseServer) GetResourceTemplates

func (s *BaseServer) GetResourceTemplates() []types.Resource

GetResourceTemplates returns all registered resource templates

func (*BaseServer) GetResources

func (s *BaseServer) GetResources() []types.Resource

GetResources returns all registered resources

func (*BaseServer) GetTools

func (s *BaseServer) GetTools() []types.Tool

GetTools returns all registered tools

func (*BaseServer) HandleInitialize

func (s *BaseServer) HandleInitialize(ctx context.Context, params types.InitializeParams) (*types.InitializeResult, error)

HandleInitialize handles an initialization request

func (*BaseServer) HandleToolCall

func (s *BaseServer) HandleToolCall(ctx context.Context, call types.ToolCall) (*types.ToolResult, error)

HandleToolCall handles a tool call request

func (*BaseServer) RegisterResource

func (s *BaseServer) RegisterResource(resource types.Resource) error

RegisterResource registers a new resource

func (*BaseServer) RegisterTool

func (s *BaseServer) RegisterTool(tool types.Tool) error

RegisterTool registers a new tool with validation

func (*BaseServer) RegisterToolHandler

func (s *BaseServer) RegisterToolHandler(name string, handler ToolHandler) error

RegisterToolHandler registers a handler for a tool with validation

func (*BaseServer) Start

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

Start starts the server with the given configuration

func (*BaseServer) Stop

func (s *BaseServer) Stop(ctx context.Context) error

Stop gracefully stops the server

type Config

type Config struct {
	// MaxSessions is the maximum number of concurrent sessions allowed
	MaxSessions int
	// EnableValidation enables request/response validation
	EnableValidation bool
	// LogLevel controls the verbosity of server logging
	LogLevel string
	// ConnectionTimeout is the default timeout for operations
	ConnectionTimeout int64
}

Config represents server configuration options

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns a default server configuration

type InitializationOptions

type InitializationOptions struct {
	// Version of the MCP protocol
	Version string `json:"version"`
	// SupportedVersions is a list of supported protocol versions in order of preference
	SupportedVersions []string `json:"supportedVersions,omitempty"`
	// Capabilities supported by the server
	Capabilities map[string]interface{} `json:"capabilities"`
	// Additional configuration options
	Config map[string]interface{} `json:"config"`
}

InitializationOptions represents server initialization options

type Server

type Server interface {
	// GetTools returns the list of available tools
	GetTools() []types.Tool
	// GetResources returns the list of available resources
	GetResources() []types.Resource
	// HandleToolCall handles a tool call request
	HandleToolCall(ctx context.Context, call types.ToolCall) (*types.ToolResult, error)
	// GetInitializationOptions returns the server initialization options
	GetInitializationOptions() *InitializationOptions
	// RegisterTool registers a new tool
	RegisterTool(tool types.Tool) error
	// RegisterToolHandler registers a handler for a tool
	RegisterToolHandler(name string, handler ToolHandler) error
	// RegisterResource registers a new resource
	RegisterResource(resource types.Resource) error
	// HandleInitialize handles an initialization request
	HandleInitialize(ctx context.Context, params types.InitializeParams) (*types.InitializeResult, error)
	// GetResourceTemplates returns all registered resource templates
	GetResourceTemplates() []types.Resource
	// ApplyResourceTemplate applies a resource template with the given parameters
	ApplyResourceTemplate(ctx context.Context, template types.ResourceTemplate) (*types.ResourceTemplateResult, error)
}

Server interface defines the methods that must be implemented by an MCP server

type ToolHandler

type ToolHandler func(ctx context.Context, params map[string]any) (*types.ToolResult, error)

ToolHandler represents a function that handles a tool call

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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