Documentation
¶
Index ¶
- func NewTestServer(server *ProxyServer, opts ...SSEOption) *httptest.Server
- func ServeStdio(server *ProxyServer, opts ...StdioOption) error
- type BaseMessage
- type ProxyServer
- type SSEContextFunc
- type SSEOption
- type SSEServer
- 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 StdioContextFunc
- type StdioOption
- type StdioServer
- type UnparseableMessageError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewTestServer ¶
func NewTestServer(server *ProxyServer, opts ...SSEOption) *httptest.Server
NewTestServer creates a test server for testing purposes
func ServeStdio ¶
func ServeStdio(server *ProxyServer, 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 BaseMessage ¶
type ProxyServer ¶
type ProxyServer struct { *server.MCPServer BaseUrl string BasePath string Status string Error string ServerInfo mcp.Implementation Client client.MCPClient Config *common.McpServerConfig }
func NewProxyServer ¶
func NewProxyServer(cfg *common.McpServerConfig) (*ProxyServer, error)
func (*ProxyServer) HandleMessage ¶
func (s *ProxyServer) HandleMessage( ctx context.Context, message json.RawMessage, ) mcp.JSONRPCMessage
HandleMessage processes an incoming JSON-RPC message and returns an appropriate response
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 ¶
func NewSSEServer(server *ProxyServer, opts ...SSEOption) *SSEServer
NewSSEServer creates a new SSE server instance with the given MCP server and options.
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 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 *ProxyServer) *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 UnparseableMessageError ¶
type UnparseableMessageError struct {
// contains filtered or unexported fields
}
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