server

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const MCPGatewaySpecVersion = "1.5.0"

MCPGatewaySpecVersion is the MCP Gateway Specification version this implementation conforms to

View Source
const MCPProtocolVersion = "2024-11-05"

MCPProtocolVersion is the MCP protocol version supported by this gateway

View Source
const SessionIDContextKey = mcp.SessionIDContextKey

SessionIDContextKey is used to store MCP session ID in context This is re-exported from mcp package for backward compatibility

Variables

This section is empty.

Functions

func CreateHTTPServerForMCP

func CreateHTTPServerForMCP(addr string, unifiedServer *UnifiedServer, apiKey string) *http.Server

CreateHTTPServerForMCP creates an HTTP server that handles MCP over streamable HTTP transport If apiKey is provided, all requests except /health require authentication (spec 7.1)

func CreateHTTPServerForRoutedMode

func CreateHTTPServerForRoutedMode(addr string, unifiedServer *UnifiedServer, apiKey string) *http.Server

CreateHTTPServerForRoutedMode creates an HTTP server for routed mode In routed mode, each backend is accessible at /mcp/<server> Multiple routes from the same Authorization header share a session If apiKey is provided, all requests except /health require authentication (spec 7.1)

func HandleHealth

func HandleHealth(unifiedServer *UnifiedServer) http.HandlerFunc

HandleHealth returns an http.HandlerFunc that handles the /health endpoint This function is used by both routed and unified modes to ensure consistent behavior

func WithSDKLogging

func WithSDKLogging(handler http.Handler, mode string) http.Handler

WithSDKLogging wraps an SDK StreamableHTTPHandler to log JSON-RPC translation results This captures the request/response at the HTTP boundary to understand what the SDK sees and what it returns, particularly for debugging protocol state issues

Types

type HTTPTransport

type HTTPTransport struct {
	Addr string
}

HTTPTransport wraps the SDK's HTTP transport

func (*HTTPTransport) Close

func (t *HTTPTransport) Close() error

Close implements sdk.Transport interface

func (*HTTPTransport) Recv

func (t *HTTPTransport) Recv() (interface{}, error)

Recv implements sdk.Transport interface

func (*HTTPTransport) Send

func (t *HTTPTransport) Send(msg interface{}) error

Send implements sdk.Transport interface

func (*HTTPTransport) Start

func (t *HTTPTransport) Start(ctx context.Context) error

Start implements sdk.Transport interface

type HealthResponse

type HealthResponse struct {
	Status         string                  `json:"status"`         // "healthy" or "unhealthy"
	SpecVersion    string                  `json:"specVersion"`    // MCP Gateway Specification version
	GatewayVersion string                  `json:"gatewayVersion"` // Gateway implementation version
	Servers        map[string]ServerStatus `json:"servers"`        // Map of server names to their health status
}

HealthResponse represents the JSON structure for the /health endpoint response as defined in MCP Gateway Specification section 8.1.1

func BuildHealthResponse

func BuildHealthResponse(unifiedServer *UnifiedServer) HealthResponse

BuildHealthResponse constructs a HealthResponse from the unified server's status

type JSONRPCError

type JSONRPCError struct {
	Code    int             `json:"code"`
	Message string          `json:"message"`
	Data    json.RawMessage `json:"data,omitempty"`
}

JSONRPCError represents a JSON-RPC error

type JSONRPCRequest

type JSONRPCRequest struct {
	JSONRPC string          `json:"jsonrpc"`
	ID      interface{}     `json:"id,omitempty"`
	Method  string          `json:"method"`
	Params  json.RawMessage `json:"params,omitempty"`
}

JSONRPCRequest represents an incoming JSON-RPC request

type JSONRPCResponse

type JSONRPCResponse struct {
	JSONRPC string          `json:"jsonrpc"`
	ID      interface{}     `json:"id,omitempty"`
	Result  json.RawMessage `json:"result,omitempty"`
	Error   *JSONRPCError   `json:"error,omitempty"`
}

JSONRPCResponse represents a JSON-RPC response

type Server

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

Server represents the MCPG HTTP server

func New

func New(ctx context.Context, l *launcher.Launcher, mode string) *Server

New creates a new Server

func (*Server) ListenAndServe

func (s *Server) ListenAndServe(addr string) error

ListenAndServe starts the HTTP server

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler

type ServerStatus

type ServerStatus struct {
	Status string `json:"status"` // "running" | "stopped" | "error"
	Uptime int    `json:"uptime"` // seconds since server was launched
}

ServerStatus represents the health status of a backend server

type Session

type Session struct {
	Token     string
	SessionID string
	StartTime time.Time
}

Session represents a MCPG session

func NewSession

func NewSession(sessionID, token string) *Session

NewSession creates a new Session with the given session ID and optional token

type ToolInfo

type ToolInfo struct {
	Name        string
	Description string
	InputSchema map[string]interface{}
	BackendID   string // Which backend this tool belongs to
	Handler     func(context.Context, *sdk.CallToolRequest, interface{}) (*sdk.CallToolResult, interface{}, error)
}

ToolInfo stores metadata about a registered tool

type UnifiedServer

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

UnifiedServer implements a unified MCP server that aggregates multiple backend servers

func NewUnified

func NewUnified(ctx context.Context, cfg *config.Config) (*UnifiedServer, error)

NewUnified creates a new unified MCP server

func (*UnifiedServer) Close

func (us *UnifiedServer) Close() error

Close cleans up resources

func (*UnifiedServer) GetPayloadSizeThreshold added in v0.0.108

func (us *UnifiedServer) GetPayloadSizeThreshold() int

GetPayloadSizeThreshold returns the configured payload size threshold (in bytes). Payloads larger than this threshold are stored to disk, smaller ones are returned inline. This getter allows other modules to access the threshold configuration.

func (*UnifiedServer) GetServerIDs

func (us *UnifiedServer) GetServerIDs() []string

GetServerIDs returns the list of backend server IDs

func (*UnifiedServer) GetServerStatus

func (us *UnifiedServer) GetServerStatus() map[string]ServerStatus

GetServerStatus returns the status of all configured backend servers

func (*UnifiedServer) GetToolHandler

func (us *UnifiedServer) GetToolHandler(backendID string, toolName string) func(context.Context, *sdk.CallToolRequest, interface{}) (*sdk.CallToolResult, interface{}, error)

GetToolHandler returns the handler for a specific backend tool This allows routed mode to reuse the unified server's tool handlers

func (*UnifiedServer) GetToolsForBackend

func (us *UnifiedServer) GetToolsForBackend(backendID string) []ToolInfo

GetToolsForBackend returns tools for a specific backend with prefix stripped

func (*UnifiedServer) InitiateShutdown

func (us *UnifiedServer) InitiateShutdown() int

InitiateShutdown initiates graceful shutdown and returns the number of servers terminated This method is idempotent - subsequent calls will return 0 servers terminated

func (*UnifiedServer) IsDIFCEnabled

func (us *UnifiedServer) IsDIFCEnabled() bool

IsDIFCEnabled returns whether DIFC is enabled

func (*UnifiedServer) IsShutdown

func (us *UnifiedServer) IsShutdown() bool

IsShutdown returns true if the gateway has been shut down

func (*UnifiedServer) RegisterTestTool

func (us *UnifiedServer) RegisterTestTool(name string, tool *ToolInfo)

RegisterTestTool registers a tool for testing purposes This method is used by integration tests to inject mock tools into the gateway

func (*UnifiedServer) Run

func (us *UnifiedServer) Run(transport sdk.Transport) error

Run starts the unified MCP server on the specified transport

func (*UnifiedServer) SetTestMode

func (us *UnifiedServer) SetTestMode(enabled bool)

SetTestMode enables test mode which prevents os.Exit() calls This should only be used in unit tests

func (*UnifiedServer) ShouldExit

func (us *UnifiedServer) ShouldExit() bool

ShouldExit returns whether the gateway should exit after shutdown Returns false in test mode to prevent actual process exit

Jump to

Keyboard shortcuts

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