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 AuthContext
- 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 LogEntry
- type LogLevel
- type LoggerOptions
- type McpEventDirection
- type McpMessageType
- type McpTransportType
- type MetaContext
- type RoutingContext
- 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 AuthContext ¶ added in v0.0.5
type AuthContext struct {
Authenticated bool `json:"authenticated"`
PrincipalID string `json:"principal_id,omitempty"`
PrincipalType string `json:"principal_type,omitempty"` // e.g. "api_key"
KeyID string `json:"key_id,omitempty"`
Gateway string `json:"gateway,omitempty"`
AuthHeader string `json:"auth_header,omitempty"`
CredentialFingerprint string `json:"credential_fingerprint,omitempty"`
InternalSessionID string `json:"internal_session_id,omitempty"`
TransportSessionID string `json:"transport_session_id,omitempty"`
}
AuthContext captures authenticated principal information for a request.
This context is intended for policy, compliance, and processor-level decisions. It must never include raw credentials.
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 LogEntry ¶ added in v0.1.0
type LogEntry struct {
BaseMcpEvent
Routing RoutingContext `json:"routing"`
ToolCall *ToolCallLog `json:"tool_call,omitempty"`
}
LogEntry is the enriched log payload written to the Centian JSONL log.
func (*LogEntry) GetBaseEvent ¶ added in v0.1.0
func (e *LogEntry) GetBaseEvent() BaseMcpEvent
GetBaseEvent returns the BaseMcpEvent.
func (*LogEntry) WithToolRequest ¶ added in v0.1.0
func (e *LogEntry) WithToolRequest(name, originalName string, args json.RawMessage) *LogEntry
WithToolRequest attaches name, originalName and args on ToolCall of this LogEntry.
func (*LogEntry) WithToolResult ¶ added in v0.1.0
func (e *LogEntry) WithToolResult(result json.RawMessage, isError bool) *LogEntry
WithToolResult attaches provided result and isError status on ToolCall of this LogEntry.
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 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 MetaContext ¶ added in v0.1.0
type MetaContext struct {
BaseMcpEvent
}
MetaContext contains processor-facing event metadata.
func NewMetaContext ¶ added in v0.1.0
func NewMetaContext( transport string, direction McpEventDirection, messageType McpMessageType, ) *MetaContext
NewMetaContext creates a new MetaContext with required fields initialized.
func NewRequestMetaContext ¶ added in v0.1.0
func NewRequestMetaContext(transport string) *MetaContext
NewRequestMetaContext creates a MetaContext for a request (client → server).
func (*MetaContext) GetBaseEvent ¶ added in v0.1.0
func (e *MetaContext) GetBaseEvent() BaseMcpEvent
GetBaseEvent returns the BaseMcpEvent.
func (*MetaContext) SetStatus ¶ added in v0.1.0
func (e *MetaContext) SetStatus(status int)
SetStatus sets the status code for this event.
func (*MetaContext) WithRequestID ¶ added in v0.1.0
func (e *MetaContext) WithRequestID(id string) *MetaContext
WithRequestID sets the request ID.
func (*MetaContext) WithServerID ¶ added in v0.1.0
func (e *MetaContext) WithServerID(id string) *MetaContext
WithServerID sets the server ID.
func (*MetaContext) WithSessionID ¶ added in v0.1.0
func (e *MetaContext) WithSessionID(id string) *MetaContext
WithSessionID sets the session ID.
type RoutingContext ¶
type RoutingContext 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"`
}
RoutingContext 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 only filled for logging.