@@ -21,6 +21,14 @@ var httpClient *http.Client
2121var localRecallURL string
2222var apiKey string
2323var defaultCollectionName string
24+ var debugMode bool
25+
26+ // debugLog prints debug messages only when DEBUG=1 is set
27+ func debugLog (format string , args ... interface {}) {
28+ if debugMode {
29+ log .Printf ("[DEBUG] " + format , args ... )
30+ }
31+ }
2432
2533// LocalRecall API response structure
2634type APIResponse struct {
@@ -601,6 +609,9 @@ func deleteEntryWithCollection(ctx context.Context, collectionName, entry string
601609}
602610
603611func main () {
612+ // Check for debug mode
613+ debugMode = os .Getenv ("DEBUG" ) == "1"
614+
604615 // Get configuration from environment variables
605616 localRecallURL = os .Getenv ("LOCALRECALL_URL" )
606617 if localRecallURL == "" {
@@ -621,13 +632,13 @@ func main() {
621632
622633 // Valid tool names
623634 validTools := map [string ]bool {
624- "search" : true ,
635+ "search" : true ,
625636 "create_collection" : true ,
626- "reset_collection" : true ,
627- "add_document" : true ,
628- "list_collections" : true ,
629- "list_files" : true ,
630- "delete_entry" : true ,
637+ "reset_collection" : true ,
638+ "add_document" : true ,
639+ "list_collections" : true ,
640+ "list_files" : true ,
641+ "delete_entry" : true ,
631642 }
632643
633644 if enabledToolsStr != "" {
@@ -641,7 +652,7 @@ func main() {
641652 if validTools [tool ] {
642653 enabledTools [tool ] = true
643654 } else {
644- log . Printf ("Warning: Unknown tool name '%s' will be ignored" , tool )
655+ debugLog ("Warning: Unknown tool name '%s' will be ignored" , tool )
645656 }
646657 }
647658 } else {
@@ -665,13 +676,13 @@ func main() {
665676 Name : "search" ,
666677 Description : desc ,
667678 }, SearchWithoutCollection )
668- log . Printf ("Tool 'search' enabled (using default collection: %s)" , defaultCollectionName )
679+ debugLog ("Tool 'search' enabled (using default collection: %s)" , defaultCollectionName )
669680 } else {
670681 mcp .AddTool (server , & mcp.Tool {
671682 Name : "search" ,
672683 Description : "Search content in a LocalRecall collection" ,
673684 }, Search )
674- log . Println ("Tool 'search' enabled" )
685+ debugLog ("Tool 'search' enabled" )
675686 }
676687 }
677688
@@ -680,15 +691,15 @@ func main() {
680691 Name : "create_collection" ,
681692 Description : "Create a new collection in LocalRecall" ,
682693 }, CreateCollection )
683- log . Println ("Tool 'create_collection' enabled" )
694+ debugLog ("Tool 'create_collection' enabled" )
684695 }
685696
686697 if enabledTools ["reset_collection" ] {
687698 mcp .AddTool (server , & mcp.Tool {
688699 Name : "reset_collection" ,
689700 Description : "Reset (clear) a collection in LocalRecall" ,
690701 }, ResetCollection )
691- log . Println ("Tool 'reset_collection' enabled" )
702+ debugLog ("Tool 'reset_collection' enabled" )
692703 }
693704
694705 if enabledTools ["add_document" ] {
@@ -698,13 +709,13 @@ func main() {
698709 Name : "add_document" ,
699710 Description : desc ,
700711 }, AddDocumentWithoutCollection )
701- log . Printf ("Tool 'add_document' enabled (using default collection: %s)" , defaultCollectionName )
712+ debugLog ("Tool 'add_document' enabled (using default collection: %s)" , defaultCollectionName )
702713 } else {
703714 mcp .AddTool (server , & mcp.Tool {
704715 Name : "add_document" ,
705716 Description : "Add a document to a LocalRecall collection" ,
706717 }, AddDocument )
707- log . Println ("Tool 'add_document' enabled" )
718+ debugLog ("Tool 'add_document' enabled" )
708719 }
709720 }
710721
@@ -713,7 +724,7 @@ func main() {
713724 Name : "list_collections" ,
714725 Description : "List all collections in LocalRecall" ,
715726 }, ListCollections )
716- log . Println ("Tool 'list_collections' enabled" )
727+ debugLog ("Tool 'list_collections' enabled" )
717728 }
718729
719730 if enabledTools ["list_files" ] {
@@ -723,13 +734,13 @@ func main() {
723734 Name : "list_files" ,
724735 Description : desc ,
725736 }, ListFilesWithoutCollection )
726- log . Printf ("Tool 'list_files' enabled (using default collection: %s)" , defaultCollectionName )
737+ debugLog ("Tool 'list_files' enabled (using default collection: %s)" , defaultCollectionName )
727738 } else {
728739 mcp .AddTool (server , & mcp.Tool {
729740 Name : "list_files" ,
730741 Description : "List files in a LocalRecall collection" ,
731742 }, ListFiles )
732- log . Println ("Tool 'list_files' enabled" )
743+ debugLog ("Tool 'list_files' enabled" )
733744 }
734745 }
735746
@@ -740,21 +751,21 @@ func main() {
740751 Name : "delete_entry" ,
741752 Description : desc ,
742753 }, DeleteEntryWithoutCollection )
743- log . Printf ("Tool 'delete_entry' enabled (using default collection: %s)" , defaultCollectionName )
754+ debugLog ("Tool 'delete_entry' enabled (using default collection: %s)" , defaultCollectionName )
744755 } else {
745756 mcp .AddTool (server , & mcp.Tool {
746757 Name : "delete_entry" ,
747758 Description : "Delete an entry from a LocalRecall collection" ,
748759 }, DeleteEntry )
749- log . Println ("Tool 'delete_entry' enabled" )
760+ debugLog ("Tool 'delete_entry' enabled" )
750761 }
751762 }
752763
753- log . Printf ("LocalRecall MCP server initialized. URL: %s" , localRecallURL )
764+ debugLog ("LocalRecall MCP server initialized. URL: %s" , localRecallURL )
754765 if len (enabledTools ) == 0 {
755- log . Println ("Warning: No tools enabled!" )
766+ debugLog ("Warning: No tools enabled!" )
756767 } else {
757- log . Printf ("Enabled %d tool(s)" , len (enabledTools ))
768+ debugLog ("Enabled %d tool(s)" , len (enabledTools ))
758769 }
759770
760771 // Run the server
0 commit comments