Skip to content

Commit 0f9a06e

Browse files
Copilotlpcox
andauthored
Use always-on loggers for operational and security messages
Promote DEBUG-gated logUnified.Printf calls to always-on loggers where the messages are operationally important or security-relevant: - logger.LogInfo("startup", ...) for DIFC enable/disable status and server start messages - logger.LogInfo("backend", ...) for tool registration lifecycle - logger.LogWarn("difc", ...) for DIFC access denials, guard labeling failures, response labeling failures, and strict-mode blocks Keep logUnified.Printf for verbose debug traces (agent labels, resource details, filtering counts, etc.). Agent-Logs-Url: https://github.com/github/gh-aw-mcpg/sessions/1dd01357-8468-43c0-a1a8-f79af584b3fa Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
1 parent a8e1cf1 commit 0f9a06e

2 files changed

Lines changed: 11 additions & 11 deletions

File tree

internal/server/tool_registry.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,17 @@ func registerToolWithoutValidation(server *sdk.Server, tool *sdk.Tool, handler f
5656

5757
// registerAllTools fetches and registers tools from all backend servers
5858
func (us *UnifiedServer) registerAllTools() error {
59-
logUnified.Printf("Starting tool registration for %d backends", len(us.launcher.ServerIDs()))
59+
logger.LogInfo("backend", "Starting tool registration for %d backends", len(us.launcher.ServerIDs()))
6060

6161
// Only register sys tools if DIFC is enabled
6262
// When DIFC is disabled (default), sys tools are not needed
6363
if us.enableDIFC {
64-
logUnified.Printf("DIFC enabled: registering sys tools...")
64+
logger.LogInfo("backend", "DIFC enabled: registering sys tools...")
6565
if err := us.registerSysTools(); err != nil {
6666
logger.LogWarn("backend", "Failed to register sys tools: %v", err)
6767
}
6868
} else {
69-
logUnified.Printf("DIFC disabled: skipping sys tools registration")
69+
logger.LogInfo("backend", "DIFC disabled: skipping sys tools registration")
7070
}
7171

7272
serverIDs := us.launcher.ServerIDs()
@@ -139,7 +139,7 @@ func (us *UnifiedServer) registerAllToolsParallel(serverIDs []string) error {
139139
}
140140
}
141141

142-
logUnified.Printf("Tool registration complete: %d succeeded, %d failed, total tools=%d", successCount, failureCount, len(us.tools))
142+
logger.LogInfo("backend", "Tool registration complete: %d succeeded, %d failed, total tools=%d", successCount, failureCount, len(us.tools))
143143
return nil
144144
}
145145

internal/server/unified.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,9 @@ func NewUnified(ctx context.Context, cfg *config.Config) (*UnifiedServer, error)
183183

184184
// Log guards status early (before backend launch which may take time)
185185
if us.enableDIFC {
186-
logUnified.Printf("Guards enforcement enabled with mode: %s", cfg.DIFCMode)
186+
logger.LogInfo("startup", "Guards enforcement enabled with mode: %s", cfg.DIFCMode)
187187
} else {
188-
logUnified.Printf("Guards enforcement disabled (sessions auto-created for standard MCP client compatibility)")
188+
logger.LogInfo("startup", "Guards enforcement disabled (sessions auto-created for standard MCP client compatibility)")
189189
}
190190

191191
// Register aggregated tools from all backends
@@ -485,7 +485,7 @@ func (us *UnifiedServer) callBackendTool(ctx context.Context, serverID, toolName
485485
// **Phase 1: Guard labels the resource**
486486
resource, operation, err := g.LabelResource(ctx, toolName, args, backendCaller, us.capabilities)
487487
if err != nil {
488-
logUnified.Printf("[DIFC] Guard labeling failed: %v", err)
488+
logger.LogWarn("difc", "Guard labeling failed: %v", err)
489489
httpStatusCode = 500
490490
return newErrorCallToolResult(fmt.Errorf("guard labeling failed: %w", err))
491491
}
@@ -508,7 +508,7 @@ func (us *UnifiedServer) callBackendTool(ctx context.Context, serverID, toolName
508508
logUnified.Printf("[DIFC] Response items will be evaluated at Phase 5 based on per-item labels from LabelResponse()")
509509
} else {
510510
// Non-read operation - block the request
511-
logUnified.Printf("[DIFC] Access DENIED for agent %s to %s: %s", agentID, resource.Description, result.Reason)
511+
logger.LogWarn("difc", "Access DENIED for agent %s to %s: %s", agentID, resource.Description, result.Reason)
512512
detailedErr := difc.FormatViolationError(result, agentLabels.Secrecy, agentLabels.Integrity, resource)
513513
toolSpan.RecordError(detailedErr)
514514
toolSpan.SetStatus(codes.Error, "access denied: "+result.Reason)
@@ -547,7 +547,7 @@ func (us *UnifiedServer) callBackendTool(ctx context.Context, serverID, toolName
547547
if shouldCallLabelResponse {
548548
labeledData, err = g.LabelResponse(ctx, toolName, backendResult, backendCaller, us.capabilities)
549549
if err != nil {
550-
logUnified.Printf("[DIFC] Response labeling failed: %v", err)
550+
logger.LogWarn("difc", "Response labeling failed: %v", err)
551551
httpStatusCode = 500
552552
return newErrorCallToolResult(fmt.Errorf("response labeling failed: %w", err))
553553
}
@@ -569,7 +569,7 @@ func (us *UnifiedServer) callBackendTool(ctx context.Context, serverID, toolName
569569

570570
// **Strict mode: block entire response if ANY item is filtered**
571571
if enforcementMode == difc.EnforcementStrict && filtered.GetFilteredCount() > 0 {
572-
logUnified.Printf("[DIFC] STRICT MODE: Blocking entire response - %d/%d items violate DIFC policy",
572+
logger.LogWarn("difc", "STRICT MODE: Blocking entire response - %d/%d items violate DIFC policy",
573573
filtered.GetFilteredCount(), filtered.TotalCount)
574574
blockErr := fmt.Errorf("DIFC policy violation: %d of %d items in response are not accessible to agent %s",
575575
filtered.GetFilteredCount(), filtered.TotalCount, agentID)
@@ -641,7 +641,7 @@ func (us *UnifiedServer) callBackendTool(ctx context.Context, serverID, toolName
641641

642642
// Run starts the unified MCP server on the specified transport
643643
func (us *UnifiedServer) Run(transport sdk.Transport) error {
644-
logUnified.Printf("Starting unified MCP server...")
644+
logger.LogInfo("startup", "Starting unified MCP server...")
645645
return us.server.Run(us.ctx, transport)
646646
}
647647

0 commit comments

Comments
 (0)