mcp

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2026 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrCodeParseError     = -32700
	ErrCodeInvalidRequest = -32600
	ErrCodeMethodNotFound = -32601
	ErrCodeInvalidParams  = -32602
	ErrCodeInternalError  = -32603
)

JSON-RPC 2.0 standard error codes.

View Source
const (
	HeaderProtocolVersion = "MCP-Protocol-Version"
	HeaderSessionID       = "Mcp-Session-Id"
	HeaderAccept          = "Accept"
)

Streamable HTTP header names.

View Source
const DefaultProtocolVersion = "2025-06-18"

DefaultProtocolVersion is the MCP protocol version advertised by the server.

View Source
const MetricSuffix = " - mcp"

Variables

This section is empty.

Functions

func MCPMetric

func MCPMetric(base string) string

MCPMetric returns the status/Prometheus metric name for an MCP event.

Types

type CallToolResult

type CallToolResult struct {
	Content []ContentItem `json:"content"`
	IsError bool          `json:"isError"`
}

CallToolResult is the MCP tools/call response format.

type ClientInfo

type ClientInfo struct {
	Name    string `json:"name"`
	Version string `json:"version"`
}

ClientInfo identifies the MCP client.

type ContentItem

type ContentItem struct {
	Type string `json:"type"`
	Text string `json:"text,omitempty"`
}

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)

func (ProviderFunc) ListTools

func (p ProviderFunc) ListTools(ctx *server.Context, cursor string) ([]Tool, string)

type ServerConfig

type ServerConfig struct {
	Name    string
	Version string
}

ServerConfig identifies the MCP server in initialize responses.

type ServerInfo

type ServerInfo struct {
	Name    string `json:"name"`
	Version string `json:"version"`
}

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) Delete

func (s *SessionStore) Delete(id string)

Delete removes a session.

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.

Jump to

Keyboard shortcuts

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