googleapis/mcp-toolbox · error
unable to get logger from ctx: %s
Error message
unable to get logger from ctx: %s
What it means
Initialize calls util.LoggerFromContext(ctx) to fetch the structured logger carried in the request context; if the context has no logger, initialization aborts with this error. It indicates the toolbox was invoked without the logger-injection middleware or with a bare context.
Source
Thrown at internal/sources/falkordb/falkordb.go:87
// validateTLS rejects a TLS configuration whose settings contradict each
// other. Without TLS there is no certificate to verify, so insecureSkipVerify
// would otherwise be accepted and silently ignored.
func (r Config) validateTLS() error {
if !r.TLS.Enabled && r.TLS.InsecureSkipVerify {
return fmt.Errorf("tls.insecureSkipVerify is set on source %q but tls.enabled is false; enable TLS or remove the setting", r.Name)
}
return nil
}
func (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {
if err := r.validateTLS(); err != nil {
return nil, err
}
logger, err := util.LoggerFromContext(ctx)
if err != nil {
return nil, fmt.Errorf("unable to get logger from ctx: %s", err)
}
if r.TLS.InsecureSkipVerify {
logger.WarnContext(ctx, fmt.Sprintf("TLS certificate verification is skipped (insecureSkipVerify: true) for FalkorDB source %s. This exposes traffic for this source to man-in-the-middle attacks. Do not use in production.", r.Name))
}
client, err := initFalkorDBClient(ctx, tracer, r)
if err != nil {
return nil, fmt.Errorf("unable to create client: %w", err)
}
if err := client.Conn.Ping(ctx).Err(); err != nil {
client.Conn.Close()
return nil, fmt.Errorf("unable to connect successfully: %w", err)
}
s := &Source{
Config: r,
Client: client,View on GitHub (pinned to 8cc6e09de2)
Solutions
- Use the standard toolbox server startup path, which injects the logger into the context
- In custom code, attach a logger: `ctx = util.WithLogger(ctx, logger)` before calling Initialize
- For tests, build a context with a logger helper from internal/util
Example fix
// before src, err := cfg.Initialize(context.Background(), tracer) // after ctx := util.WithLogger(context.Background(), slog.Default()) src, err := cfg.Initialize(ctx, tracer)
Defensive patterns
Strategy: validation
Validate before calling
// Go: ensure the logger is in the context before Initialize
if _, err := util.LoggerFromContext(ctx); err != nil {
ctx = util.WithLogger(ctx, slog.Default())
} Prevention
- Use the standard toolbox server startup, which injects the logger
- In custom embedders/tests, always call util.WithLogger on the context
- Never pass bare context.Background() to source Initialize
When it happens
Trigger: Calling Initialize programmatically with a context.Context that never had a logger attached (e.g. custom embedding code, tests, or a modified main.go that skips the standard server setup).
Common situations: Custom Go embedders of mcp-toolbox constructing sources directly without using the toolbox server's context setup; unit tests passing context.Background().
Related errors
- unable to get logger from ctx: %s
- unable to get logger from ctx: %s
- unable to get logger from ctx: %s
- failed to get logger from context: %w
- unable to retrieve logger: %w
AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05).
Data as JSON: /api/errors/cd099037d85e1073.
Report an issue: GitHub.