Documentation
¶
Index ¶
- Constants
- func CreateHTTPServerForMCP(addr string, unifiedServer *UnifiedServer, apiKey string) *http.Server
- func CreateHTTPServerForRoutedMode(addr string, unifiedServer *UnifiedServer, apiKey string) *http.Server
- func HandleHealth(unifiedServer *UnifiedServer) http.HandlerFunc
- func WithSDKLogging(handler http.Handler, mode string) http.Handler
- type HTTPTransport
- type HealthResponse
- type JSONRPCError
- type JSONRPCRequest
- type JSONRPCResponse
- type Server
- type ServerStatus
- type Session
- type ToolInfo
- type UnifiedServer
- func (us *UnifiedServer) Close() error
- func (us *UnifiedServer) GetPayloadSizeThreshold() int
- func (us *UnifiedServer) GetServerIDs() []string
- func (us *UnifiedServer) GetServerStatus() map[string]ServerStatus
- func (us *UnifiedServer) GetToolHandler(backendID string, toolName string) ...
- func (us *UnifiedServer) GetToolsForBackend(backendID string) []ToolInfo
- func (us *UnifiedServer) InitiateShutdown() int
- func (us *UnifiedServer) IsDIFCEnabled() bool
- func (us *UnifiedServer) IsShutdown() bool
- func (us *UnifiedServer) RegisterTestTool(name string, tool *ToolInfo)
- func (us *UnifiedServer) Run(transport sdk.Transport) error
- func (us *UnifiedServer) SetTestMode(enabled bool)
- func (us *UnifiedServer) ShouldExit() bool
Constants ¶
const MCPGatewaySpecVersion = "1.5.0"
MCPGatewaySpecVersion is the MCP Gateway Specification version this implementation conforms to
const MCPProtocolVersion = "2024-11-05"
MCPProtocolVersion is the MCP protocol version supported by this gateway
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 ¶
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
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 (*Server) ListenAndServe ¶
ListenAndServe starts the HTTP server
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 ¶
Session represents a MCPG session
func NewSession ¶
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 ¶
NewUnified creates a new unified MCP server
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