Documentation
¶
Overview ¶
Code generated by `go generate`. DO NOT EDIT. source: server/internal/gen/hooks.go.tmpl
Code generated by `go generate`. DO NOT EDIT. source: server/internal/gen/request_handler.go.tmpl
Package server provides MCP (Model Control Protocol) server implementations.
Index ¶
- Variables
- func GetUrlPath(input string) (string, error)
- func NewTestServer(server *MCPServer, opts ...SSEOption) *httptest.Server
- func ServeStdio(server *MCPServer, opts ...StdioOption) error
- type BeforeAnyHookFunc
- type ClientSession
- type Hooks
- func (c *Hooks) AddAfterCallTool(hook OnAfterCallToolFunc)
- func (c *Hooks) AddAfterGetPrompt(hook OnAfterGetPromptFunc)
- func (c *Hooks) AddAfterInitialize(hook OnAfterInitializeFunc)
- func (c *Hooks) AddAfterListPrompts(hook OnAfterListPromptsFunc)
- func (c *Hooks) AddAfterListResourceTemplates(hook OnAfterListResourceTemplatesFunc)
- func (c *Hooks) AddAfterListResources(hook OnAfterListResourcesFunc)
- func (c *Hooks) AddAfterListTools(hook OnAfterListToolsFunc)
- func (c *Hooks) AddAfterPing(hook OnAfterPingFunc)
- func (c *Hooks) AddAfterReadResource(hook OnAfterReadResourceFunc)
- func (c *Hooks) AddBeforeAny(hook BeforeAnyHookFunc)
- func (c *Hooks) AddBeforeCallTool(hook OnBeforeCallToolFunc)
- func (c *Hooks) AddBeforeGetPrompt(hook OnBeforeGetPromptFunc)
- func (c *Hooks) AddBeforeInitialize(hook OnBeforeInitializeFunc)
- func (c *Hooks) AddBeforeListPrompts(hook OnBeforeListPromptsFunc)
- func (c *Hooks) AddBeforeListResourceTemplates(hook OnBeforeListResourceTemplatesFunc)
- func (c *Hooks) AddBeforeListResources(hook OnBeforeListResourcesFunc)
- func (c *Hooks) AddBeforeListTools(hook OnBeforeListToolsFunc)
- func (c *Hooks) AddBeforePing(hook OnBeforePingFunc)
- func (c *Hooks) AddBeforeReadResource(hook OnBeforeReadResourceFunc)
- func (c *Hooks) AddOnError(hook OnErrorHookFunc)
- func (c *Hooks) AddOnSuccess(hook OnSuccessHookFunc)
- type MCPServer
- func (s *MCPServer) AddNotificationHandler(method string, handler NotificationHandlerFunc)
- func (s *MCPServer) AddPrompt(prompt mcp.Prompt, handler PromptHandlerFunc)
- func (s *MCPServer) AddResource(resource mcp.Resource, handler ResourceHandlerFunc)
- func (s *MCPServer) AddResourceTemplate(template mcp.ResourceTemplate, handler ResourceTemplateHandlerFunc)
- func (s *MCPServer) AddTool(tool mcp.Tool, handler ToolHandlerFunc)
- func (s *MCPServer) AddTools(tools ...ServerTool)
- func (s *MCPServer) DeleteTools(names ...string)
- func (s *MCPServer) HandleMessage(ctx context.Context, message json.RawMessage) mcp.JSONRPCMessage
- func (s *MCPServer) RegisterSession(session session.Session) error
- func (s *MCPServer) SendNotificationToClient(ctx context.Context, method string, params map[string]any) error
- func (s *MCPServer) SetTools(tools ...ServerTool)
- func (s *MCPServer) UnregisterSession(sessionID string)
- func (s *MCPServer) WithContext(ctx context.Context, session ClientSession) context.Context
- type MCSSEOption
- func WithMCBasePath(basePath string) MCSSEOption
- func WithMCBaseURL(baseURL string) MCSSEOption
- func WithMCMessageEndpoint(endpoint string) MCSSEOption
- func WithMCSSEContextFunc(fn SSEContextFunc) MCSSEOption
- func WithMCSSEEndpoint(endpoint string) MCSSEOption
- func WithMCTTPServer(srv *http.Server) MCSSEOption
- type MCSSEServer
- func (s *MCSSEServer) AddMuxRoutes(mux *mux.Router)
- func (s *MCSSEServer) Clean(ctx context.Context, removeAll bool)
- func (s *MCSSEServer) CleanAuto(ctx context.Context)
- func (s *MCSSEServer) CompleteMessageEndpoint() string
- func (s *MCSSEServer) CompleteMessagePath() string
- func (s *MCSSEServer) CompleteSseEndpoint() string
- func (s *MCSSEServer) CompleteSsePath() string
- func (s *MCSSEServer) DoesSessionExist(ctx context.Context, sessionID string) (bool, bool)
- func (s *MCSSEServer) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (s *MCSSEServer) Shutdown(ctx context.Context) error
- func (s *MCSSEServer) Start(addr string) error
- type NotificationHandlerFunc
- type OnAfterCallToolFunc
- type OnAfterGetPromptFunc
- type OnAfterInitializeFunc
- type OnAfterListPromptsFunc
- type OnAfterListResourceTemplatesFunc
- type OnAfterListResourcesFunc
- type OnAfterListToolsFunc
- type OnAfterPingFunc
- type OnAfterReadResourceFunc
- type OnBeforeCallToolFunc
- type OnBeforeGetPromptFunc
- type OnBeforeInitializeFunc
- type OnBeforeListPromptsFunc
- type OnBeforeListResourceTemplatesFunc
- type OnBeforeListResourcesFunc
- type OnBeforeListToolsFunc
- type OnBeforePingFunc
- type OnBeforeReadResourceFunc
- type OnErrorHookFunc
- type OnSuccessHookFunc
- type PromptHandlerFunc
- type ResourceHandlerFunc
- type ResourceTemplateHandlerFunc
- type SSEContextFunc
- type SSEOption
- type SSEServer
- func (s *SSEServer) AddMuxRoutes(mux *mux.Router)
- func (s *SSEServer) CompleteMessageEndpoint() string
- func (s *SSEServer) CompleteMessagePath() string
- func (s *SSEServer) CompleteSseEndpoint() string
- func (s *SSEServer) CompleteSsePath() string
- func (s *SSEServer) GetUrlPath(input string) (string, error)
- func (s *SSEServer) SendEventToSession(sessionID string, event interface{}) error
- func (s *SSEServer) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (s *SSEServer) Shutdown(ctx context.Context) error
- func (s *SSEServer) Start(addr string) error
- type ServerOption
- func WithHooks(hooks *Hooks) ServerOption
- func WithInstructions(instructions string) ServerOption
- func WithLogging() ServerOption
- func WithPromptCapabilities(listChanged bool) ServerOption
- func WithResourceCapabilities(subscribe, listChanged bool) ServerOption
- func WithToolCapabilities(listChanged bool) ServerOption
- type ServerTool
- type StdioContextFunc
- type StdioOption
- type StdioServer
- type ToolHandlerFunc
- type UnparseableMessageError
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func GetUrlPath ¶ added in v1.0.2
func NewTestServer ¶
NewTestServer creates a test server for testing purposes
func ServeStdio ¶
func ServeStdio(server *MCPServer, opts ...StdioOption) error
ServeStdio is a convenience function that creates and starts a StdioServer with os.Stdin and os.Stdout. It sets up signal handling for graceful shutdown on SIGTERM and SIGINT. Returns an error if the server encounters any issues during operation.
Types ¶
type BeforeAnyHookFunc ¶
BeforeAnyHookFunc is a function that is called after the request is parsed but before the method is called.
type ClientSession ¶
type ClientSession interface { // Initialize marks session as fully initialized and ready for notifications Initialize() // Initialized returns if session is ready to accept notifications Initialized() bool // NotificationChannel provides a channel suitable for sending notifications to client. NotificationChannel() chan<- mcp.JSONRPCNotification // SessionID is a unique identifier used to track user session. SessionID() string }
ClientSession represents an active session that can be used by MCPServer to interact with client.
func ClientSessionFromContext ¶
func ClientSessionFromContext(ctx context.Context) ClientSession
ClientSessionFromContext retrieves current client notification context from context.
type Hooks ¶
type Hooks struct { OnBeforeAny []BeforeAnyHookFunc OnSuccess []OnSuccessHookFunc OnError []OnErrorHookFunc OnBeforeInitialize []OnBeforeInitializeFunc OnAfterInitialize []OnAfterInitializeFunc OnBeforePing []OnBeforePingFunc OnAfterPing []OnAfterPingFunc OnBeforeListResources []OnBeforeListResourcesFunc OnAfterListResources []OnAfterListResourcesFunc OnBeforeListResourceTemplates []OnBeforeListResourceTemplatesFunc OnAfterListResourceTemplates []OnAfterListResourceTemplatesFunc OnBeforeReadResource []OnBeforeReadResourceFunc OnAfterReadResource []OnAfterReadResourceFunc OnBeforeListPrompts []OnBeforeListPromptsFunc OnAfterListPrompts []OnAfterListPromptsFunc OnBeforeGetPrompt []OnBeforeGetPromptFunc OnAfterGetPrompt []OnAfterGetPromptFunc OnBeforeListTools []OnBeforeListToolsFunc OnAfterListTools []OnAfterListToolsFunc OnBeforeCallTool []OnBeforeCallToolFunc OnAfterCallTool []OnAfterCallToolFunc }
func (*Hooks) AddAfterCallTool ¶
func (c *Hooks) AddAfterCallTool(hook OnAfterCallToolFunc)
func (*Hooks) AddAfterGetPrompt ¶
func (c *Hooks) AddAfterGetPrompt(hook OnAfterGetPromptFunc)
func (*Hooks) AddAfterInitialize ¶
func (c *Hooks) AddAfterInitialize(hook OnAfterInitializeFunc)
func (*Hooks) AddAfterListPrompts ¶
func (c *Hooks) AddAfterListPrompts(hook OnAfterListPromptsFunc)
func (*Hooks) AddAfterListResourceTemplates ¶
func (c *Hooks) AddAfterListResourceTemplates(hook OnAfterListResourceTemplatesFunc)
func (*Hooks) AddAfterListResources ¶
func (c *Hooks) AddAfterListResources(hook OnAfterListResourcesFunc)
func (*Hooks) AddAfterListTools ¶
func (c *Hooks) AddAfterListTools(hook OnAfterListToolsFunc)
func (*Hooks) AddAfterPing ¶
func (c *Hooks) AddAfterPing(hook OnAfterPingFunc)
func (*Hooks) AddAfterReadResource ¶
func (c *Hooks) AddAfterReadResource(hook OnAfterReadResourceFunc)
func (*Hooks) AddBeforeAny ¶
func (c *Hooks) AddBeforeAny(hook BeforeAnyHookFunc)
func (*Hooks) AddBeforeCallTool ¶
func (c *Hooks) AddBeforeCallTool(hook OnBeforeCallToolFunc)
func (*Hooks) AddBeforeGetPrompt ¶
func (c *Hooks) AddBeforeGetPrompt(hook OnBeforeGetPromptFunc)
func (*Hooks) AddBeforeInitialize ¶
func (c *Hooks) AddBeforeInitialize(hook OnBeforeInitializeFunc)
func (*Hooks) AddBeforeListPrompts ¶
func (c *Hooks) AddBeforeListPrompts(hook OnBeforeListPromptsFunc)
func (*Hooks) AddBeforeListResourceTemplates ¶
func (c *Hooks) AddBeforeListResourceTemplates(hook OnBeforeListResourceTemplatesFunc)
func (*Hooks) AddBeforeListResources ¶
func (c *Hooks) AddBeforeListResources(hook OnBeforeListResourcesFunc)
func (*Hooks) AddBeforeListTools ¶
func (c *Hooks) AddBeforeListTools(hook OnBeforeListToolsFunc)
func (*Hooks) AddBeforePing ¶
func (c *Hooks) AddBeforePing(hook OnBeforePingFunc)
func (*Hooks) AddBeforeReadResource ¶
func (c *Hooks) AddBeforeReadResource(hook OnBeforeReadResourceFunc)
func (*Hooks) AddOnError ¶
func (c *Hooks) AddOnError(hook OnErrorHookFunc)
AddOnError registers a hook function that will be called when an error occurs. The error parameter contains the actual error object, which can be interrogated using Go's error handling patterns like errors.Is and errors.As.
Example: ``` // Create a channel to receive errors for testing errChan := make(chan error, 1)
// Register hook to capture and inspect errors hooks := &Hooks{}
hooks.AddOnError(func(id any, method mcp.MCPMethod, message any, err error) { // For capability-related errors if errors.Is(err, ErrUnsupported) { // Handle capability not supported errChan <- err return } // For parsing errors var parseErr = &UnparseableMessageError{} if errors.As(err, &parseErr) { // Handle unparseable message errors fmt.Printf("Failed to parse %s request: %v\n", parseErr.GetMethod(), parseErr.Unwrap()) errChan <- parseErr return } // For resource/prompt/tool not found errors if errors.Is(err, ErrResourceNotFound) || errors.Is(err, ErrPromptNotFound) || errors.Is(err, ErrToolNotFound) { // Handle not found errors errChan <- err return } // For other errors errChan <- err })
server := NewMCPServer("test-server", "1.0.0", WithHooks(hooks)) ```
func (*Hooks) AddOnSuccess ¶
func (c *Hooks) AddOnSuccess(hook OnSuccessHookFunc)
type MCPServer ¶
type MCPServer struct {
// contains filtered or unexported fields
}
MCPServer implements a Model Control Protocol server that can handle various types of requests including resources, prompts, and tools.
func NewMCPServer ¶
func NewMCPServer( name, version string, opts ...ServerOption, ) *MCPServer
NewMCPServer creates a new MCP server instance with the given name, version and options
func ServerFromContext ¶
ServerFromContext retrieves the MCPServer instance from a context
func (*MCPServer) AddNotificationHandler ¶
func (s *MCPServer) AddNotificationHandler( method string, handler NotificationHandlerFunc, )
AddNotificationHandler registers a new handler for incoming notifications
func (*MCPServer) AddPrompt ¶
func (s *MCPServer) AddPrompt(prompt mcp.Prompt, handler PromptHandlerFunc)
AddPrompt registers a new prompt handler with the given name
func (*MCPServer) AddResource ¶
func (s *MCPServer) AddResource( resource mcp.Resource, handler ResourceHandlerFunc, )
AddResource registers a new resource and its handler
func (*MCPServer) AddResourceTemplate ¶
func (s *MCPServer) AddResourceTemplate( template mcp.ResourceTemplate, handler ResourceTemplateHandlerFunc, )
AddResourceTemplate registers a new resource template and its handler
func (*MCPServer) AddTool ¶
func (s *MCPServer) AddTool(tool mcp.Tool, handler ToolHandlerFunc)
AddTool registers a new tool and its handler
func (*MCPServer) AddTools ¶
func (s *MCPServer) AddTools(tools ...ServerTool)
AddTools registers multiple tools at once
func (*MCPServer) DeleteTools ¶
DeleteTools removes a tool from the server
func (*MCPServer) HandleMessage ¶
func (s *MCPServer) HandleMessage( ctx context.Context, message json.RawMessage, ) mcp.JSONRPCMessage
HandleMessage processes an incoming JSON-RPC message and returns an appropriate response
func (*MCPServer) RegisterSession ¶
RegisterSession saves session that should be notified in case if some server attributes changed.
func (*MCPServer) SendNotificationToClient ¶
func (s *MCPServer) SendNotificationToClient( ctx context.Context, method string, params map[string]any, ) error
SendNotificationToClient sends a notification to the current client
func (*MCPServer) SetTools ¶
func (s *MCPServer) SetTools(tools ...ServerTool)
SetTools replaces all existing tools with the provided list
func (*MCPServer) UnregisterSession ¶
UnregisterSession removes from storage session that is shut down.
func (*MCPServer) WithContext ¶
WithContext sets the current client session and returns the provided context
type MCSSEOption ¶ added in v1.0.3
type MCSSEOption func(*MCSSEServer)
func WithMCBasePath ¶ added in v1.0.3
func WithMCBasePath(basePath string) MCSSEOption
Add a new option for setting base path
func WithMCBaseURL ¶ added in v1.0.3
func WithMCBaseURL(baseURL string) MCSSEOption
WithBaseURL sets the base URL for the SSE server
func WithMCMessageEndpoint ¶ added in v1.0.3
func WithMCMessageEndpoint(endpoint string) MCSSEOption
WithMessageEndpoint sets the message endpoint path
func WithMCSSEContextFunc ¶ added in v1.0.3
func WithMCSSEContextFunc(fn SSEContextFunc) MCSSEOption
WithContextFunc sets a function that will be called to customise the context to the server using the incoming request.
func WithMCSSEEndpoint ¶ added in v1.0.3
func WithMCSSEEndpoint(endpoint string) MCSSEOption
WithSSEEndpoint sets the SSE endpoint path
func WithMCTTPServer ¶ added in v1.0.3
func WithMCTTPServer(srv *http.Server) MCSSEOption
WithHTTPServer sets the HTTP server instance
type MCSSEServer ¶ added in v1.0.2
type MCSSEServer struct {
// contains filtered or unexported fields
}
todo update this to use mCMCPSession
func NewMCSSEServer ¶ added in v1.0.2
func NewMCSSEServer(server *MCPServer, redisClient redis.Cmdable, opts ...MCSSEOption) *MCSSEServer
func (*MCSSEServer) AddMuxRoutes ¶ added in v1.0.2
func (s *MCSSEServer) AddMuxRoutes(mux *mux.Router)
func (*MCSSEServer) Clean ¶ added in v1.0.2
func (s *MCSSEServer) Clean(ctx context.Context, removeAll bool)
func (*MCSSEServer) CleanAuto ¶ added in v1.0.2
func (s *MCSSEServer) CleanAuto(ctx context.Context)
func (*MCSSEServer) CompleteMessageEndpoint ¶ added in v1.0.2
func (s *MCSSEServer) CompleteMessageEndpoint() string
func (*MCSSEServer) CompleteMessagePath ¶ added in v1.0.2
func (s *MCSSEServer) CompleteMessagePath() string
func (*MCSSEServer) CompleteSseEndpoint ¶ added in v1.0.2
func (s *MCSSEServer) CompleteSseEndpoint() string
func (*MCSSEServer) CompleteSsePath ¶ added in v1.0.2
func (s *MCSSEServer) CompleteSsePath() string
func (*MCSSEServer) DoesSessionExist ¶ added in v1.0.2
func (*MCSSEServer) ServeHTTP ¶ added in v1.0.2
func (s *MCSSEServer) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements the http.Handler interface.
func (*MCSSEServer) Shutdown ¶ added in v1.0.2
func (s *MCSSEServer) Shutdown(ctx context.Context) error
func (*MCSSEServer) Start ¶ added in v1.0.2
func (s *MCSSEServer) Start(addr string) error
Start begins serving SSE connections on the specified address. It sets up HTTP handlers for SSE and message endpoints.
type NotificationHandlerFunc ¶
type NotificationHandlerFunc func(ctx context.Context, notification mcp.JSONRPCNotification)
NotificationHandlerFunc handles incoming notifications.
type OnAfterCallToolFunc ¶
type OnAfterCallToolFunc func(id any, message *mcp.CallToolRequest, result *mcp.CallToolResult)
type OnAfterGetPromptFunc ¶
type OnAfterGetPromptFunc func(id any, message *mcp.GetPromptRequest, result *mcp.GetPromptResult)
type OnAfterInitializeFunc ¶
type OnAfterInitializeFunc func(id any, message *mcp.InitializeRequest, result *mcp.InitializeResult)
type OnAfterListPromptsFunc ¶
type OnAfterListPromptsFunc func(id any, message *mcp.ListPromptsRequest, result *mcp.ListPromptsResult)
type OnAfterListResourceTemplatesFunc ¶
type OnAfterListResourceTemplatesFunc func(id any, message *mcp.ListResourceTemplatesRequest, result *mcp.ListResourceTemplatesResult)
type OnAfterListResourcesFunc ¶
type OnAfterListResourcesFunc func(id any, message *mcp.ListResourcesRequest, result *mcp.ListResourcesResult)
type OnAfterListToolsFunc ¶
type OnAfterListToolsFunc func(id any, message *mcp.ListToolsRequest, result *mcp.ListToolsResult)
type OnAfterPingFunc ¶
type OnAfterPingFunc func(id any, message *mcp.PingRequest, result *mcp.EmptyResult)
type OnAfterReadResourceFunc ¶
type OnAfterReadResourceFunc func(id any, message *mcp.ReadResourceRequest, result *mcp.ReadResourceResult)
type OnBeforeCallToolFunc ¶
type OnBeforeCallToolFunc func(id any, message *mcp.CallToolRequest)
type OnBeforeGetPromptFunc ¶
type OnBeforeGetPromptFunc func(id any, message *mcp.GetPromptRequest)
type OnBeforeInitializeFunc ¶
type OnBeforeInitializeFunc func(id any, message *mcp.InitializeRequest)
type OnBeforeListPromptsFunc ¶
type OnBeforeListPromptsFunc func(id any, message *mcp.ListPromptsRequest)
type OnBeforeListResourceTemplatesFunc ¶
type OnBeforeListResourceTemplatesFunc func(id any, message *mcp.ListResourceTemplatesRequest)
type OnBeforeListResourcesFunc ¶
type OnBeforeListResourcesFunc func(id any, message *mcp.ListResourcesRequest)
type OnBeforeListToolsFunc ¶
type OnBeforeListToolsFunc func(id any, message *mcp.ListToolsRequest)
type OnBeforePingFunc ¶
type OnBeforePingFunc func(id any, message *mcp.PingRequest)
type OnBeforeReadResourceFunc ¶
type OnBeforeReadResourceFunc func(id any, message *mcp.ReadResourceRequest)
type OnErrorHookFunc ¶
OnErrorHookFunc is a hook that will be called when an error occurs, either during the request parsing or the method execution.
Example usage: ```
hooks.AddOnError(func(id any, method mcp.MCPMethod, message any, err error) { // Check for specific error types using errors.Is if errors.Is(err, ErrUnsupported) { // Handle capability not supported errors log.Printf("Capability not supported: %v", err) } // Use errors.As to get specific error types var parseErr = &UnparseableMessageError{} if errors.As(err, &parseErr) { // Access specific methods/fields of the error type log.Printf("Failed to parse message for method %s: %v", parseErr.GetMethod(), parseErr.Unwrap()) // Access the raw message that failed to parse rawMsg := parseErr.GetMessage() } // Check for specific resource/prompt/tool errors switch { case errors.Is(err, ErrResourceNotFound): log.Printf("Resource not found: %v", err) case errors.Is(err, ErrPromptNotFound): log.Printf("Prompt not found: %v", err) case errors.Is(err, ErrToolNotFound): log.Printf("Tool not found: %v", err) } })
type OnSuccessHookFunc ¶
OnSuccessHookFunc is a hook that will be called after the request successfully generates a result, but before the result is sent to the client.
type PromptHandlerFunc ¶
type PromptHandlerFunc func(ctx context.Context, request mcp.GetPromptRequest) (*mcp.GetPromptResult, error)
PromptHandlerFunc handles prompt requests with given arguments.
type ResourceHandlerFunc ¶
type ResourceHandlerFunc func(ctx context.Context, request mcp.ReadResourceRequest) ([]mcp.ResourceContents, error)
ResourceHandlerFunc is a function that returns resource contents.
type ResourceTemplateHandlerFunc ¶
type ResourceTemplateHandlerFunc func(ctx context.Context, request mcp.ReadResourceRequest) ([]mcp.ResourceContents, error)
ResourceTemplateHandlerFunc is a function that returns a resource template.
type SSEContextFunc ¶
SSEContextFunc is a function that takes an existing context and the current request and returns a potentially modified context based on the request content. This can be used to inject context values from headers, for example.
type SSEOption ¶
type SSEOption func(*SSEServer)
SSEOption defines a function type for configuring SSEServer
func WithBasePath ¶
Add a new option for setting base path
func WithBaseURL ¶
WithBaseURL sets the base URL for the SSE server
func WithHTTPServer ¶
WithHTTPServer sets the HTTP server instance
func WithMessageEndpoint ¶
WithMessageEndpoint sets the message endpoint path
func WithSSEContextFunc ¶
func WithSSEContextFunc(fn SSEContextFunc) SSEOption
WithContextFunc sets a function that will be called to customise the context to the server using the incoming request.
func WithSSEEndpoint ¶
WithSSEEndpoint sets the SSE endpoint path
type SSEServer ¶
type SSEServer struct {
// contains filtered or unexported fields
}
SSEServer implements a Server-Sent Events (SSE) based MCP server. It provides real-time communication capabilities over HTTP using the SSE protocol.
func NewSSEServer ¶
NewSSEServer creates a new SSE server instance with the given MCP server and options.
func (*SSEServer) AddMuxRoutes ¶
func (*SSEServer) CompleteMessageEndpoint ¶
func (*SSEServer) CompleteMessagePath ¶
func (*SSEServer) CompleteSseEndpoint ¶
func (*SSEServer) CompleteSsePath ¶
func (*SSEServer) SendEventToSession ¶
SendEventToSession sends an event to a specific SSE session identified by sessionID. Returns an error if the session is not found or closed.
func (*SSEServer) ServeHTTP ¶
func (s *SSEServer) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements the http.Handler interface.
type ServerOption ¶
type ServerOption func(*MCPServer)
ServerOption is a function that configures an MCPServer.
func WithHooks ¶
func WithHooks(hooks *Hooks) ServerOption
WithHooks allows adding hooks that will be called before or after either [all] requests or before / after specific request methods, or else prior to returning an error to the client.
func WithInstructions ¶
func WithInstructions(instructions string) ServerOption
WithInstructions sets the server instructions for the client returned in the initialize response
func WithLogging ¶
func WithLogging() ServerOption
WithLogging enables logging capabilities for the server
func WithPromptCapabilities ¶
func WithPromptCapabilities(listChanged bool) ServerOption
WithPromptCapabilities configures prompt-related server capabilities
func WithResourceCapabilities ¶
func WithResourceCapabilities(subscribe, listChanged bool) ServerOption
WithResourceCapabilities configures resource-related server capabilities
func WithToolCapabilities ¶
func WithToolCapabilities(listChanged bool) ServerOption
WithToolCapabilities configures tool-related server capabilities
type ServerTool ¶
type ServerTool struct { Tool mcp.Tool Handler ToolHandlerFunc }
ServerTool combines a Tool with its ToolHandlerFunc.
type StdioContextFunc ¶
StdioContextFunc is a function that takes an existing context and returns a potentially modified context. This can be used to inject context values from environment variables, for example.
type StdioOption ¶
type StdioOption func(*StdioServer)
StdioOption defines a function type for configuring StdioServer
func WithErrorLogger ¶
func WithErrorLogger(logger *log.Logger) StdioOption
WithErrorLogger sets the error logger for the server
func WithStdioContextFunc ¶
func WithStdioContextFunc(fn StdioContextFunc) StdioOption
WithContextFunc sets a function that will be called to customise the context to the server. Note that the stdio server uses the same context for all requests, so this function will only be called once per server instance.
type StdioServer ¶
type StdioServer struct {
// contains filtered or unexported fields
}
StdioServer wraps a MCPServer and handles stdio communication. It provides a simple way to create command-line MCP servers that communicate via standard input/output streams using JSON-RPC messages.
func NewStdioServer ¶
func NewStdioServer(server *MCPServer) *StdioServer
NewStdioServer creates a new stdio server wrapper around an MCPServer. It initializes the server with a default error logger that discards all output.
func (*StdioServer) Listen ¶
Listen starts listening for JSON-RPC messages on the provided input and writes responses to the provided output. It runs until the context is cancelled or an error occurs. Returns an error if there are issues with reading input or writing output.
func (*StdioServer) SetContextFunc ¶
func (s *StdioServer) SetContextFunc(fn StdioContextFunc)
SetContextFunc sets a function that will be called to customise the context to the server. Note that the stdio server uses the same context for all requests, so this function will only be called once per server instance.
func (*StdioServer) SetErrorLogger ¶
func (s *StdioServer) SetErrorLogger(logger *log.Logger)
SetErrorLogger configures where error messages from the StdioServer are logged. The provided logger will receive all error messages generated during server operation.
type ToolHandlerFunc ¶
type ToolHandlerFunc func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error)
ToolHandlerFunc handles tool calls with given arguments.
type UnparseableMessageError ¶
type UnparseableMessageError struct {
// contains filtered or unexported fields
}
UnparseableMessageError is attached to the RequestError when json.Unmarshal fails on the request.
func (*UnparseableMessageError) Error ¶
func (e *UnparseableMessageError) Error() string
func (*UnparseableMessageError) GetMessage ¶
func (e *UnparseableMessageError) GetMessage() json.RawMessage
func (*UnparseableMessageError) GetMethod ¶
func (e *UnparseableMessageError) GetMethod() mcp.MCPMethod
func (*UnparseableMessageError) Unwrap ¶
func (e *UnparseableMessageError) Unwrap() error