Documentation
¶
Overview ¶
Package common holds functions and structs that are used throughout all other packages in this repository. It mainly provides utils functions, and MCP models.
Index ¶
- func CloseLogger() error
- func DebugLoggingEnabled() bool
- func GetCurrentWorkingDir() string
- func GetSecondsFromInt(i int) time.Duration
- func InitInternalLogger(options LoggerOptions) error
- func IsURLCompliant(name string) bool
- func LogDebug(message string, args ...interface{})
- func LogError(message string, args ...interface{})
- func LogInfo(message string, args ...interface{})
- func LogWarn(message string, args ...interface{})
- func PressEnterToContinue(message string)
- type BaseMcpEvent
- type InternalLogger
- func (l *InternalLogger) Close() error
- func (l *InternalLogger) Debug(message string, args ...interface{})
- func (l *InternalLogger) Error(message string, args ...interface{})
- func (l *InternalLogger) Info(message string, args ...interface{})
- func (l *InternalLogger) Warn(message string, args ...interface{})
- type LogLevel
- type LoggerOptions
- type MCPEvent
- func (e *MCPEvent) GetBaseEvent() BaseMcpEvent
- func (e *MCPEvent) SetStatus(status int)
- func (e *MCPEvent) WithRequestID(id string) *MCPEvent
- func (e *MCPEvent) WithServerID(id string) *MCPEvent
- func (e *MCPEvent) WithSessionID(id string) *MCPEvent
- func (e *MCPEvent) WithToolRequest(name, originalName string, args json.RawMessage) *MCPEvent
- func (e *MCPEvent) WithToolResult(result json.RawMessage, isError bool) *MCPEvent
- type McpEventDirection
- type McpMessageType
- type McpTransportType
- type RoutingLog
- type ToolCallLog
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DebugLoggingEnabled ¶ added in v0.0.4
func DebugLoggingEnabled() bool
DebugLoggingEnabled returns true when the global logger will emit debug logs.
func GetCurrentWorkingDir ¶
func GetCurrentWorkingDir() string
GetCurrentWorkingDir gets the current working directory.
func GetSecondsFromInt ¶
GetSecondsFromInt returns a duration (in seconds) for a provided int value.
func InitInternalLogger ¶ added in v0.0.4
func InitInternalLogger(options LoggerOptions) error
InitInternalLogger initializes or replaces the global logger.
func IsURLCompliant ¶
IsURLCompliant checks if a name is URL-safe (alphanumeric, dash, underscore only). Names must start with alphanumeric character and can contain alphanumeric, dash, or underscore. This ensures names can be safely used in URL paths like /mcp/<gateway>/<server>.
func LogDebug ¶
func LogDebug(message string, args ...interface{})
LogDebug logs a debug message using the global logger.
func LogError ¶
func LogError(message string, args ...interface{})
LogError logs an error message using the global logger.
func LogInfo ¶
func LogInfo(message string, args ...interface{})
LogInfo logs an info message using the global logger.
func LogWarn ¶
func LogWarn(message string, args ...interface{})
LogWarn logs a warning message using the global logger.
func PressEnterToContinue ¶ added in v0.0.2
func PressEnterToContinue(message string)
PressEnterToContinue prints the text "Press enter to continue..." and waits for an enter to continue the program flow.
Types ¶
type BaseMcpEvent ¶
type BaseMcpEvent struct {
// Indicates the event status - is related to http status codes:
// 20x - ok
// 40x - expected error - client might be able to resolve it by rephrasing the query
// 50x - unexpected error - proxy ran into unexpected error.
Status int `json:"status"`
// Timestamp is the exact time when the log entry was created.
Timestamp time.Time `json:"timestamp"`
// Transport identifies the proxy type: "stdio", "http", "websocket".
Transport string `json:"transport"`
// RequestID uniquely identifies a single request/response pair.
RequestID string `json:"request_id"`
// SessionID groups multiple requests within the same proxy session.
SessionID string `json:"session_id,omitempty"`
// ServerID uniquely identifies the MCP server instance handling this request.
ServerID string `json:"server_id,omitempty"`
// Direction indicates the communication flow perspective:
// "request" (client→server),
// "response" (server→client), or
// "system" (proxy lifecycle events).
// This field remains stable regardless of success/failure status.
Direction McpEventDirection `json:"direction"`
// MessageType categorizes the content/outcome: "request", "response", "error", or "system".
// Unlike Direction, this changes to "error" for failed responses, enabling filtering.
// by operational status (e.g., "all errors" vs "all responses regardless of success").
// This orthogonal design supports both flow analysis (Direction) and status monitoring (MessageType).
MessageType McpMessageType `json:"message_type"`
// Success indicates whether the operation completed successfully.
Success bool `json:"success"`
// Error contains error details if Success is false.
Error string `json:"error,omitempty"`
// ProcessingErrors indicate errors during processing of this event.
ProcessingErrors map[string]error `json:"-"`
// Metadata holds additional context-specific key-value pairs.
Metadata map[string]string `json:"metadata,omitempty"`
// Modified indicates that the event has been modified at least once since being received.
Modified bool `json:"modified"`
}
BaseMcpEvent holds the core metadata common to all MCP events regardless of transport type.
This struct contains fields for tracking request flow, timing, status, and contextual information that apply universally across stdio, HTTP, and other transport mechanisms.
type InternalLogger ¶
type InternalLogger struct {
// contains filtered or unexported fields
}
InternalLogger provides basic logging functionality to .centian folder.
func (*InternalLogger) Debug ¶
func (l *InternalLogger) Debug(message string, args ...interface{})
Debug logs a debug message.
func (*InternalLogger) Error ¶
func (l *InternalLogger) Error(message string, args ...interface{})
Error logs an error message.
func (*InternalLogger) Info ¶
func (l *InternalLogger) Info(message string, args ...interface{})
Info logs an info message.
func (*InternalLogger) Warn ¶
func (l *InternalLogger) Warn(message string, args ...interface{})
Warn logs a warning message.
type LogLevel ¶ added in v0.0.4
type LogLevel int
LogLevel defines the minimum severity that is written by the internal logger.
type LoggerOptions ¶ added in v0.0.4
LoggerOptions configures the global internal logger.
type MCPEvent ¶
type MCPEvent struct {
BaseMcpEvent
// Routing context (always present)
Routing RoutingLog `json:"routing"`
// Tool call context (optional - only for tool call events)
ToolCall *ToolCallLog `json:"tool_call,omitempty"`
}
MCPEvent is a unified event type for all MCP transports. It provides a transport-agnostic structure that can represent events from HTTP, stdio, SDK-based proxies, or any future transport mechanism.
It is mainly used to hold event metadata for the CallContext interface.
func NewMCPEvent ¶
func NewMCPEvent( transport string, direction McpEventDirection, messageType McpMessageType, ) *MCPEvent
NewMCPEvent creates a new MCPEvent with required fields initialized.
func NewMCPRequestEvent ¶
NewMCPRequestEvent creates an MCPEvent for a request (client → server).
func (*MCPEvent) GetBaseEvent ¶
func (e *MCPEvent) GetBaseEvent() BaseMcpEvent
GetBaseEvent returns the BaseMcpEvent.
func (*MCPEvent) WithRequestID ¶
WithRequestID sets the request ID.
func (*MCPEvent) WithServerID ¶
WithServerID sets the server ID.
func (*MCPEvent) WithSessionID ¶
WithSessionID sets the session ID.
func (*MCPEvent) WithToolRequest ¶ added in v0.0.3
func (e *MCPEvent) WithToolRequest(name, originalName string, args json.RawMessage) *MCPEvent
WithToolRequest attaches name, originalName and args on ToolCall of this MCPEvent.
func (*MCPEvent) WithToolResult ¶
func (e *MCPEvent) WithToolResult(result json.RawMessage, isError bool) *MCPEvent
WithToolResult attaches provided result and isError status on ToolCall of this MCPEvent.
type McpEventDirection ¶
type McpEventDirection string
McpEventDirection represents the event direction, e.g. CLIENT to SERVER, CENTIAN to CLIENT etc.
const ( // DirectionClientToServer represents the direction: CLIENT -> SERVER. DirectionClientToServer McpEventDirection = "[CLIENT -> SERVER]" // DirectionServerToClient represents the direction: SERVER -> CLIENT. DirectionServerToClient McpEventDirection = "[SERVER -> CLIENT]" // DirectionCentianToClient represents the direction: CENTIAN -> CLIENT, // e.g. when a response is returned early before being forwarded to. // the downstream MCP server. DirectionCentianToClient McpEventDirection = "[CENTIAN -> CLIENT]" // DirectionSystem represents a system event, not intended // to be forwarded to either CLIENT or SERVER. DirectionSystem McpEventDirection = "[SYSTEM]" // DirectionUnknown represents an unknown direction and is used // in case the direction is not one of the above!. DirectionUnknown McpEventDirection = "[UNKNOWN]" )
func (McpEventDirection) MarshalJSON ¶
func (m McpEventDirection) MarshalJSON() ([]byte, error)
MarshalJSON returns the JSON encoding of McpEventDirection.
It maps the value to one of the allowed directions:
- [CLIENT -> SERVER]
- [SERVER -> CLIENT]
- [CENTIAN -> CLIENT]
- [SYSTEM]
- [UNKNOWN] - in case none of the above fit
func (*McpEventDirection) UnmarshalJSON ¶
func (m *McpEventDirection) UnmarshalJSON(b []byte) error
UnmarshalJSON parses the JSON-encoded data of McpEventDirection.
It maps the value to one of the allowed directions:
- [CLIENT -> SERVER]
- [SERVER -> CLIENT]
- [CENTIAN -> CLIENT]
- [SYSTEM]
- [UNKNOWN] - in case none of the above fit
type McpMessageType ¶
type McpMessageType string
McpMessageType represents the type if an MCP event, can be request, response, system, or unknown.
const ( // MessageTypeRequest represents a request message type. MessageTypeRequest McpMessageType = "request" // MessageTypeResponse represents a response message type. MessageTypeResponse McpMessageType = "response" // MessageTypeSystem represents a system message type. MessageTypeSystem McpMessageType = "system" // MessageTypeUnknown represents a unknown message type. MessageTypeUnknown McpMessageType = "unknown" )
func (McpMessageType) MarshalJSON ¶
func (m McpMessageType) MarshalJSON() ([]byte, error)
MarshalJSON returns the JSON encoding of McpMessageType.
func (*McpMessageType) UnmarshalJSON ¶
func (m *McpMessageType) UnmarshalJSON(b []byte) error
UnmarshalJSON parses the JSON-encoded data of McpMessageType.
type McpTransportType ¶
type McpTransportType string
McpTransportType represents a valid MCP transport - either stdio or http.
const ( // HTTPTransport represents HTTP transport -> "http". HTTPTransport McpTransportType = "http" // StdioTransport represents stdio transport -> "stdio". StdioTransport McpTransportType = "stdio" // UnknownTransport represents an unknown transport (e.g. error case). UnknownTransport McpTransportType = "unknown" // InvalidTransport represents a transport configuration that is invalid (e.g. URL and CMD are set). InvalidTransport McpTransportType = "invalid" )
func GetTransport ¶ added in v0.0.3
func GetTransport(url, cmd string) (McpTransportType, error)
GetTransport returns the McpTransportType based on provided url and cmd fields.
type RoutingLog ¶ added in v0.0.3
type RoutingLog struct {
// Transport describes the used transport for this connection (http or stdio)
Transport McpTransportType `json:"transport,omitempty"`
// Gateway is the logical grouping of MCP servers
Gateway string `json:"gateway,omitempty"`
// ServerName identifies the specific MCP server
ServerName string `json:"server_name,omitempty"`
// Endpoint is the HTTP path or identifier for this proxy
Endpoint string `json:"endpoint,omitempty"`
// DownstreamURL is the target MCP server URL being proxied to
DownstreamURL string `json:"downstream_url,omitempty"`
// DownstreamCommand is the target MCP server command being proxied to
DownstreamCommand string `json:"downstream_cmd,omitempty"`
// Args is the target MCP server command args being used
Args []string `json:"args,omitempty"`
}
RoutingLog captures where the request is going.
type ToolCallLog ¶ added in v0.0.3
type ToolCallLog struct {
// Name is the tool name being called
Name string `json:"name"`
// OriginalName is the tool name before any namespace transformations
OriginalName string `json:"original_name,omitempty"`
// Arguments contains the tool call arguments as raw JSON
Arguments json.RawMessage `json:"arguments,omitempty"`
// Result contains the tool call result as raw JSON (for responses)
Result json.RawMessage `json:"result,omitempty"`
// IsError indicates if the tool call resulted in an error
IsError bool `json:"is_error,omitempty"`
}
ToolCallLog captures tool call specific details.
Note: this is typically only filled for logging MCPEvents.