logging

package
v2.0.5 Latest Latest
Warning

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

Go to latest
Published: May 22, 2026 License: MIT Imports: 5 Imported by: 0

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.

Secret Handling

Values sent through this package are visible to the MCP client. Callers must avoid passing tokens, passwords, authorization headers, or structs that may contain credentials.

Index

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

func (l *SessionLogger) Alert(ctx context.Context, message string, data any)

Alert sends an alert-level log message to the client (RFC 5424). The data parameter is sent to the MCP client as-is; do not include secrets.

func (*SessionLogger) Critical

func (l *SessionLogger) Critical(ctx context.Context, message string, data any)

Critical sends a critical-level log message to the client (RFC 5424). The data parameter is sent to the MCP client as-is; do not include secrets.

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

func (l *SessionLogger) Emergency(ctx context.Context, message string, data any)

Emergency sends an emergency-level log message to the client (RFC 5424). 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

func (l *SessionLogger) LogToolCall(ctx context.Context, tool string, start time.Time, err error)

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.

func (*SessionLogger) Notice

func (l *SessionLogger) Notice(ctx context.Context, message string, data any)

Notice sends a notice-level log message to the client (RFC 5424). The data parameter is sent to the MCP client as-is; do not include secrets.

func (*SessionLogger) Warning

func (l *SessionLogger) Warning(ctx context.Context, message string, data any)

Warning sends a warning-level log message to the client. The data parameter is sent to the MCP client as-is; do not include secrets.

Jump to

Keyboard shortcuts

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