Documentation
¶
Overview ¶
Package logging provides MCP protocol-level logging via ServerSession. It sends structured log messages to connected clients for server monitoring, complementing the stderr-based slog logging already in place.
Index ¶
- type SessionLogger
- func (l *SessionLogger) Debug(ctx context.Context, message string, data any)
- func (l *SessionLogger) Error(ctx context.Context, message string, data any)
- func (l *SessionLogger) Info(ctx context.Context, message string, data any)
- func (l *SessionLogger) LogToolCall(ctx context.Context, tool string, start time.Time, err error)
- func (l *SessionLogger) Warning(ctx context.Context, message string, data any)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type SessionLogger ¶
type SessionLogger struct {
// contains filtered or unexported fields
}
SessionLogger wraps a *mcp.ServerSession and provides convenience methods for sending MCP protocol log messages to the connected client.
SECURITY: All data passed to log methods is sent to the MCP client. Never pass secrets (tokens, passwords, credentials) or structs that contain them.
func FromToolRequest ¶
func FromToolRequest(req *mcp.CallToolRequest) *SessionLogger
FromToolRequest extracts the ServerSession from a CallToolRequest and returns a SessionLogger. Returns nil if the request, session, or client initialization params are nil (session not yet initialized).
func NewSessionLogger ¶
func NewSessionLogger(session *mcp.ServerSession) *SessionLogger
NewSessionLogger creates a SessionLogger from an explicit ServerSession. Returns nil if session is nil.
func (*SessionLogger) Debug ¶
func (l *SessionLogger) Debug(ctx context.Context, message string, data any)
Debug sends a debug-level log message to the client. The data parameter is sent to the MCP client as-is; do not include secrets.
func (*SessionLogger) Error ¶
func (l *SessionLogger) Error(ctx context.Context, message string, data any)
Error sends an error-level log message to the client. The data parameter is sent to the MCP client as-is; do not include secrets.
func (*SessionLogger) Info ¶
func (l *SessionLogger) Info(ctx context.Context, message string, data any)
Info sends an info-level log message to the client. The data parameter is sent to the MCP client as-is; do not include secrets.
func (*SessionLogger) LogToolCall ¶
LogToolCall sends a structured tool execution log to the client. It includes tool name, duration, and success/failure status. This complements the stderr-based logToolCall in the tools package.