Documentation
¶
Index ¶
- Constants
- func MCPMetric(base string) string
- type CallToolResult
- type ClientInfo
- type ContentItem
- type Dispatcher
- type DispatcherConfig
- type HTTPConfig
- type HTTPProvider
- type InitializeParams
- type InitializeResult
- type JSONRPCRequest
- type ListToolsResult
- type MCPProvider
- type ProviderFunc
- type ServerConfig
- type ServerInfo
- type Session
- type SessionStore
- type Tool
- type ToolsCallParams
Constants ¶
const ( ErrCodeParseError = -32700 ErrCodeInvalidRequest = -32600 ErrCodeMethodNotFound = -32601 ErrCodeInvalidParams = -32602 ErrCodeInternalError = -32603 )
JSON-RPC 2.0 standard error codes.
const ( HeaderProtocolVersion = "MCP-Protocol-Version" HeaderSessionID = "Mcp-Session-Id" HeaderAccept = "Accept" )
Streamable HTTP header names.
const DefaultProtocolVersion = "2025-06-18"
DefaultProtocolVersion is the MCP protocol version advertised by the server.
const MetricSuffix = " - mcp"
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CallToolResult ¶
type CallToolResult struct {
Content []ContentItem `json:"content"`
IsError bool `json:"isError"`
}
CallToolResult is the MCP tools/call response format.
type ClientInfo ¶
ClientInfo identifies the MCP client.
type ContentItem ¶
ContentItem is a single content item in a tool result.
type Dispatcher ¶
type Dispatcher struct {
// contains filtered or unexported fields
}
Dispatcher routes MCP JSON-RPC methods.
func NewDispatcher ¶
func NewDispatcher(cfg DispatcherConfig) *Dispatcher
NewDispatcher creates a dispatcher with the given configuration.
func (*Dispatcher) Handle ¶
func (d *Dispatcher) Handle(ctx *server.Context, req JSONRPCRequest) bool
Handle processes a single JSON-RPC request. Returns true if a JSON-RPC response was sent.
type DispatcherConfig ¶
type DispatcherConfig struct {
Provider MCPProvider
Sessions *SessionStore
Server ServerConfig
ProtocolVersion string
RequireSession bool
}
DispatcherConfig configures JSON-RPC method routing for MCP.
type HTTPConfig ¶
type HTTPConfig struct {
// Path is the MCP endpoint path (default "/mcp").
Path string
// Metric is the base controller metric name (suffix " - mcp" is applied automatically).
Metric string
// Provider handles tools/list and tools/call.
Provider MCPProvider
// AuthFunc authenticates MCP requests when IsSecured is true.
AuthFunc func(ctx *server.Context) error
// IsSecured enables AuthFunc on the MCP endpoint.
IsSecured bool
// Server identifies this MCP server in initialize responses.
Server ServerConfig
// ProtocolVersion is the default MCP protocol version (default "2025-06-18").
ProtocolVersion string
// RequireSession requires a valid Mcp-Session-Id header for tools/list and tools/call.
RequireSession bool
// EnforceProtocolHeader rejects requests when MCP-Protocol-Version header is missing
// or does not match ProtocolVersion.
EnforceProtocolHeader bool
}
HTTPConfig configures the Streamable HTTP MCP transport for SSF.
type HTTPProvider ¶
type HTTPProvider struct {
// contains filtered or unexported fields
}
HTTPProvider is an SSF ControllerProvider for Streamable HTTP MCP.
func NewHTTPProvider ¶
func NewHTTPProvider(cfg HTTPConfig) HTTPProvider
NewHTTPProvider creates a ControllerProvider that exposes MCP over Streamable HTTP.
func (HTTPProvider) GetControllers ¶
func (p HTTPProvider) GetControllers() []server.Controller
GetControllers returns SSF controllers for the MCP HTTP transport.
type InitializeParams ¶
type InitializeParams struct {
ProtocolVersion string `json:"protocolVersion"`
Capabilities map[string]interface{} `json:"capabilities"`
ClientInfo *ClientInfo `json:"clientInfo"`
}
InitializeParams is the MCP initialize request params.
type InitializeResult ¶
type InitializeResult struct {
ProtocolVersion string `json:"protocolVersion"`
Capabilities map[string]interface{} `json:"capabilities"`
ServerInfo ServerInfo `json:"serverInfo"`
}
InitializeResult is the MCP initialize response.
type JSONRPCRequest ¶
type JSONRPCRequest struct {
JSONRPC string `json:"jsonrpc"`
ID interface{} `json:"id"`
Method string `json:"method"`
Params map[string]interface{} `json:"params,omitempty"`
// contains filtered or unexported fields
}
JSONRPCRequest is a JSON-RPC 2.0 request or notification.
func (JSONRPCRequest) HasNullID ¶ added in v0.7.2
func (r JSONRPCRequest) HasNullID() bool
HasNullID reports whether the request included "id": null.
func (JSONRPCRequest) IsNotification ¶
func (r JSONRPCRequest) IsNotification() bool
IsNotification reports whether the message is a JSON-RPC notification (no id member). Explicit "id": null is not a notification; use HasNullID and reject as invalid.
type ListToolsResult ¶
type ListToolsResult struct {
Tools []Tool `json:"tools"`
NextCursor string `json:"nextCursor,omitempty"`
}
ListToolsResult is the MCP tools/list response.
type MCPProvider ¶
type MCPProvider interface {
ListTools(ctx *server.Context, cursor string) ([]Tool, string)
CallTool(ctx *server.Context, name string, arguments map[string]interface{}) (CallToolResult, error)
}
MCPProvider supplies MCP tools and handles tool execution.
type ProviderFunc ¶
type ProviderFunc struct {
ListToolsFunc func(ctx *server.Context, cursor string) ([]Tool, string)
CallToolFunc func(ctx *server.Context, name string, arguments map[string]interface{}) (CallToolResult, error)
}
ProviderFunc adapts functions to MCPProvider.
func (ProviderFunc) CallTool ¶
func (p ProviderFunc) CallTool(ctx *server.Context, name string, arguments map[string]interface{}) (CallToolResult, error)
type ServerConfig ¶
ServerConfig identifies the MCP server in initialize responses.
type ServerInfo ¶
ServerInfo identifies the MCP server.
type Session ¶
type Session struct {
ID string
ProtocolVersion string
ClientInfo *ClientInfo
CreatedAt time.Time
}
Session holds MCP session state for Streamable HTTP.
type SessionStore ¶
type SessionStore struct {
// contains filtered or unexported fields
}
SessionStore tracks active MCP sessions keyed by session ID.
func NewSessionStore ¶
func NewSessionStore() *SessionStore
NewSessionStore creates an empty session store.
func (*SessionStore) Create ¶
func (s *SessionStore) Create(protocolVersion string, clientInfo *ClientInfo) *Session
Create registers a new session and returns it.
func (*SessionStore) Get ¶
func (s *SessionStore) Get(id string) *Session
Get returns the session for the given ID, or nil if not found.
type Tool ¶
type Tool struct {
Name string `json:"name"`
Description string `json:"description"`
InputSchema interface{} `json:"inputSchema"`
}
Tool is an MCP tool definition.
type ToolsCallParams ¶
type ToolsCallParams struct {
Name string `json:"name"`
Arguments map[string]interface{} `json:"arguments"`
}
ToolsCallParams is the MCP tools/call request params.