Documentation
¶
Overview ¶
Package mcp provides MCP message types and JSON-RPC codec utilities for the sentinel-gate proxy.
Index ¶
- func DecodeMessage(data []byte) (jsonrpc.Message, error)
- func EncodeMessage(msg jsonrpc.Message) ([]byte, error)
- type Direction
- type Message
- func (m *Message) ExtractAPIKey() string
- func (m *Message) HasAPIKey() bool
- func (m *Message) HasFrameworkContext() bool
- func (m *Message) IsAuthenticated() bool
- func (m *Message) IsRequest() bool
- func (m *Message) IsResponse() bool
- func (m *Message) IsToolCall() bool
- func (m *Message) Method() string
- func (m *Message) ParseParams() map[string]interface{}
- func (m *Message) RawID() json.RawMessage
- func (m *Message) Request() *jsonrpc.Request
- func (m *Message) Response() *jsonrpc.Response
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeMessage ¶
DecodeMessage deserializes JSON-RPC wire format data into a Message. It returns either a *jsonrpc.Request or *jsonrpc.Response based on the message content. This delegates to the MCP SDK's jsonrpc package.
Types ¶
type Direction ¶
type Direction int
Direction indicates the flow direction of a message through the proxy.
type Message ¶
type Message struct {
// Raw contains the original bytes of the message.
// Used for passthrough when no modification is needed.
Raw []byte
// Direction indicates whether this message is flowing from
// client to server or server to client.
Direction Direction
// Decoded contains the parsed JSON-RPC message.
// May be nil if parsing failed but passthrough is still desired.
// The concrete type is either *jsonrpc.Request or *jsonrpc.Response.
Decoded jsonrpc.Message
// Timestamp records when the message was received by the proxy.
Timestamp time.Time
// APIKey contains the raw API key extracted from the message.
// Extracted from JSON-RPC params by ExtractAPIKey().
// Used by AuthInterceptor for initial authentication.
APIKey string
// Session contains the authenticated user's session context.
// Set by AuthInterceptor after successful authentication.
// Used by policy engine for RBAC evaluation.
Session *session.Session
// FrameworkContext is nil in OSS (framework context is a PRO feature).
// Field retained for interface compatibility with PRO.
FrameworkContext interface{}
// ParsedParams contains the parsed params from a JSON-RPC request.
// Set by ParseParams() for reuse across interceptors.
// Nil if not a request or parsing failed.
ParsedParams map[string]interface{}
}
Message wraps a decoded JSON-RPC message with proxy metadata. It stores both the raw bytes (for efficient passthrough) and the decoded message (for policy inspection).
func WrapMessage ¶
WrapMessage decodes raw JSON-RPC bytes and wraps them in a Message struct with the specified direction and current timestamp.
If decoding fails, returns an error. For passthrough scenarios where the raw bytes should be preserved even on decode failure, callers can construct a Message manually.
func (*Message) ExtractAPIKey ¶
ExtractAPIKey extracts the API key from JSON-RPC params. MCP doesn't use HTTP headers, so API key is passed in JSON-RPC params. Looks in these locations (in priority order): 1. params._meta.apiKey (MCP standard metadata location) 2. params.apiKey (top-level for simplicity) Returns empty string if not found (not an error - may use cached session).
func (*Message) HasFrameworkContext ¶
HasFrameworkContext returns true if the message has framework context.
func (*Message) IsAuthenticated ¶
IsAuthenticated returns true if the message has a valid session.
func (*Message) IsResponse ¶
IsResponse returns true if the message is a JSON-RPC response.
func (*Message) IsToolCall ¶
IsToolCall returns true if this is a tools/call request. This is the primary method for identifying tool invocations that need policy evaluation.
func (*Message) Method ¶
Method returns the method name if this is a request, empty string otherwise.
func (*Message) ParseParams ¶
ParseParams parses the request params and stores in ParsedParams. Safe to call multiple times (no-op if already parsed). Returns the parsed params or nil if not a request or parsing fails.
func (*Message) RawID ¶
func (m *Message) RawID() json.RawMessage
RawID extracts the request ID from the raw message bytes as json.RawMessage. This is needed because the SDK's jsonrpc.ID type doesn't marshal correctly through interface{}, so we extract the ID directly from the raw JSON. Returns nil if no ID is found or if the message is not a request.