55 "encoding/json"
66 "fmt"
77 "io"
8- "log"
98 "net/http"
109 "sync"
1110 "time"
@@ -184,9 +183,9 @@ func NewUnified(ctx context.Context, cfg *config.Config) (*UnifiedServer, error)
184183
185184 // Log guards status early (before backend launch which may take time)
186185 if us .enableDIFC {
187- log . Printf ( "Guards enforcement enabled with mode: %s" , cfg .DIFCMode )
186+ logger . LogInfo ( "startup" , "Guards enforcement enabled with mode: %s" , cfg .DIFCMode )
188187 } else {
189- log . Println ( "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)" )
190189 }
191190
192191 // Register aggregated tools from all backends
@@ -254,7 +253,7 @@ func (g *guardBackendCaller) CallTool(ctx context.Context, toolName string, args
254253
255254 // Make a read-only call to the backend for metadata
256255 // This bypasses DIFC checks since it's internal to the guard
257- log .Printf ("[DIFC] Guard calling backend %s tool %s for metadata" , g .serverID , toolName )
256+ logUnified .Printf ("[DIFC] Guard calling backend %s tool %s for metadata" , g .serverID , toolName )
258257
259258 sessionID := SessionIDFromContext (g .ctx )
260259
@@ -413,7 +412,6 @@ func (us *UnifiedServer) isToolAllowed(serverID, toolName string) bool {
413412func (us * UnifiedServer ) callBackendTool (ctx context.Context , serverID , toolName string , args interface {}) (* sdk.CallToolResult , interface {}, error ) {
414413 // Note: Session validation happens at the tool registration level via closures
415414 // The closure captures the request and validates before calling this method
416- log .Printf ("Calling tool on %s: %s with DIFC enforcement" , serverID , toolName )
417415 logUnified .Printf ("callBackendTool: serverID=%s, toolName=%s, args=%+v" , serverID , toolName , args )
418416
419417 // Start an OTEL span for the full tool call lifecycle (spans all phases 0–6)
@@ -470,7 +468,7 @@ func (us *UnifiedServer) callBackendTool(ctx context.Context, serverID, toolName
470468 // **Phase 0: Extract agent ID and get/create agent labels**
471469 agentID := guard .GetAgentIDFromContext (ctx )
472470 agentLabels := us .agentRegistry .GetOrCreate (agentID )
473- log .Printf ("[DIFC] Agent %s | Secrecy: %v | Integrity: %v" ,
471+ logUnified .Printf ("[DIFC] Agent %s | Secrecy: %v | Integrity: %v" ,
474472 agentID , agentLabels .GetSecrecyTags (), agentLabels .GetIntegrityTags ())
475473
476474 ctx = context .WithValue (ctx , mcp .AgentTagsSnapshotContextKey , & mcp.AgentTagsSnapshot {
@@ -487,12 +485,12 @@ func (us *UnifiedServer) callBackendTool(ctx context.Context, serverID, toolName
487485 // **Phase 1: Guard labels the resource**
488486 resource , operation , err := g .LabelResource (ctx , toolName , args , backendCaller , us .capabilities )
489487 if err != nil {
490- log . Printf ( "[DIFC] Guard labeling failed: %v" , err )
488+ logger . LogWarn ( "difc" , " Guard labeling failed: %v" , err )
491489 httpStatusCode = 500
492490 return newErrorCallToolResult (fmt .Errorf ("guard labeling failed: %w" , err ))
493491 }
494492
495- log .Printf ("[DIFC] Resource: %s | Operation: %s | Secrecy: %v | Integrity: %v" ,
493+ logUnified .Printf ("[DIFC] Resource: %s | Operation: %s | Secrecy: %v | Integrity: %v" ,
496494 resource .Description , operation , resource .Secrecy .Label .GetTags (), resource .Integrity .Label .GetTags ())
497495
498496 // **Phase 2: Reference Monitor performs coarse-grained access check**
@@ -506,19 +504,19 @@ func (us *UnifiedServer) callBackendTool(ctx context.Context, serverID, toolName
506504 if isReadOperation {
507505 // Read operation in any mode - skip coarse-grained block
508506 // The guard will label response items and Phase 5 will enforce per-item policy
509- log .Printf ("[DIFC] Coarse-grained check failed for read in %s mode - proceeding to backend for response labeling" , enforcementMode )
510- log .Printf ("[DIFC] Response items will be evaluated at Phase 5 based on per-item labels from LabelResponse()" )
507+ logUnified .Printf ("[DIFC] Coarse-grained check failed for read in %s mode - proceeding to backend for response labeling" , enforcementMode )
508+ logUnified .Printf ("[DIFC] Response items will be evaluated at Phase 5 based on per-item labels from LabelResponse()" )
511509 } else {
512510 // Non-read operation - block the request
513- log . 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 )
514512 detailedErr := difc .FormatViolationError (result , agentLabels .Secrecy , agentLabels .Integrity , resource )
515513 toolSpan .RecordError (detailedErr )
516514 toolSpan .SetStatus (codes .Error , "access denied: " + result .Reason )
517515 httpStatusCode = 403
518516 return newErrorCallToolResult (detailedErr )
519517 }
520518 } else {
521- log .Printf ("[DIFC] Access ALLOWED for agent %s to %s" , agentID , resource .Description )
519+ logUnified .Printf ("[DIFC] Access ALLOWED for agent %s to %s" , agentID , resource .Description )
522520 }
523521
524522 // **Phase 3: Execute the backend call**
@@ -549,12 +547,12 @@ func (us *UnifiedServer) callBackendTool(ctx context.Context, serverID, toolName
549547 if shouldCallLabelResponse {
550548 labeledData , err = g .LabelResponse (ctx , toolName , backendResult , backendCaller , us .capabilities )
551549 if err != nil {
552- log . Printf ( "[DIFC] Response labeling failed: %v" , err )
550+ logger . LogWarn ( "difc" , " Response labeling failed: %v" , err )
553551 httpStatusCode = 500
554552 return newErrorCallToolResult (fmt .Errorf ("response labeling failed: %w" , err ))
555553 }
556554 } else {
557- log .Printf ("[DIFC] Skipping LabelResponse() for %s operation in %s mode" , operation , enforcementMode )
555+ logUnified .Printf ("[DIFC] Skipping LabelResponse() for %s operation in %s mode" , operation , enforcementMode )
558556 }
559557
560558 // **Phase 5: Reference Monitor performs fine-grained filtering (if applicable)**
@@ -566,12 +564,12 @@ func (us *UnifiedServer) callBackendTool(ctx context.Context, serverID, toolName
566564 // Filter collection based on agent labels
567565 filtered := requestEvaluator .FilterCollection (agentLabels .Secrecy , agentLabels .Integrity , collection , operation )
568566
569- log .Printf ("[DIFC] Filtered collection: %d/%d items accessible" ,
567+ logUnified .Printf ("[DIFC] Filtered collection: %d/%d items accessible" ,
570568 filtered .GetAccessibleCount (), filtered .TotalCount )
571569
572570 // **Strict mode: block entire response if ANY item is filtered**
573571 if enforcementMode == difc .EnforcementStrict && filtered .GetFilteredCount () > 0 {
574- log . 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" ,
575573 filtered .GetFilteredCount (), filtered .TotalCount )
576574 blockErr := fmt .Errorf ("DIFC policy violation: %d of %d items in response are not accessible to agent %s" ,
577575 filtered .GetFilteredCount (), filtered .TotalCount , agentID )
@@ -580,7 +578,7 @@ func (us *UnifiedServer) callBackendTool(ctx context.Context, serverID, toolName
580578 }
581579
582580 if filtered .GetFilteredCount () > 0 {
583- log .Printf ("[DIFC] Filtered out %d items due to DIFC policy" , filtered .GetFilteredCount ())
581+ logUnified .Printf ("[DIFC] Filtered out %d items due to DIFC policy" , filtered .GetFilteredCount ())
584582 logFilteredItems (serverID , toolName , filtered )
585583 difcFiltered = filtered
586584 }
@@ -606,7 +604,7 @@ func (us *UnifiedServer) callBackendTool(ctx context.Context, serverID, toolName
606604 if ! isPureWrite && enforcementMode == difc .EnforcementPropagate {
607605 overall := labeledData .Overall ()
608606 agentLabels .AccumulateFromRead (overall )
609- log .Printf ("[DIFC] Agent %s accumulated labels (propagate mode) | Secrecy: %v | Integrity: %v" ,
607+ logUnified .Printf ("[DIFC] Agent %s accumulated labels (propagate mode) | Secrecy: %v | Integrity: %v" ,
610608 agentID , agentLabels .GetSecrecyTags (), agentLabels .GetIntegrityTags ())
611609 }
612610 } else {
@@ -616,7 +614,7 @@ func (us *UnifiedServer) callBackendTool(ctx context.Context, serverID, toolName
616614 // **Phase 6: Accumulate labels from resource (for reads in PROPAGATE mode only)**
617615 if ! isPureWrite && enforcementMode == difc .EnforcementPropagate {
618616 agentLabels .AccumulateFromRead (resource )
619- log .Printf ("[DIFC] Agent %s accumulated labels (propagate mode) | Secrecy: %v | Integrity: %v" ,
617+ logUnified .Printf ("[DIFC] Agent %s accumulated labels (propagate mode) | Secrecy: %v | Integrity: %v" ,
620618 agentID , agentLabels .GetSecrecyTags (), agentLabels .GetIntegrityTags ())
621619 }
622620 }
@@ -643,7 +641,7 @@ func (us *UnifiedServer) callBackendTool(ctx context.Context, serverID, toolName
643641
644642// Run starts the unified MCP server on the specified transport
645643func (us * UnifiedServer ) Run (transport sdk.Transport ) error {
646- log . Println ( "Starting unified MCP server..." )
644+ logger . LogInfo ( "startup" , "Starting unified MCP server..." )
647645 return us .server .Run (us .ctx , transport )
648646}
649647
@@ -736,7 +734,6 @@ func (us *UnifiedServer) InitiateShutdown() int {
736734 us .isShutdown = true
737735 us .shutdownMu .Unlock ()
738736
739- log .Println ("Initiating gateway shutdown..." )
740737 logger .LogInfo ("shutdown" , "Gateway shutdown initiated" )
741738
742739 // Stop health monitor before closing connections
@@ -748,11 +745,9 @@ func (us *UnifiedServer) InitiateShutdown() int {
748745 serversTerminated = len (us .launcher .ServerIDs ())
749746
750747 // Terminate all backend servers
751- log .Printf ("Terminating %d backend server(s)..." , serversTerminated )
752748 logger .LogInfo ("shutdown" , "Terminating %d backend servers" , serversTerminated )
753749 us .launcher .Close ()
754750
755- log .Println ("Backend servers terminated" )
756751 logger .LogInfo ("shutdown" , "Backend servers terminated successfully" )
757752 })
758753 return serversTerminated
0 commit comments