{"record":{"id":"ba69b2d81cab4c49","repo":"sipeed/picoclaw","slug":"tool-discovery-is-enabled-but-neither-use-bm25-n","errorCode":null,"errorMessage":"tool discovery is enabled but neither 'use_bm25' nor 'use_regex' is set to true in the configuration","messagePattern":"tool discovery is enabled but neither 'use_bm25' nor 'use_regex' is set to true in the configuration","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/agent/agent_mcp.go","lineNumber":222,"sourceCode":"\t\t\t\t)\n\t\t\t}\n\t\t}\n\t\tlogger.InfoCF(\"agent\", \"MCP tools registered successfully\",\n\t\t\tmap[string]any{\n\t\t\t\t\"server_count\":        len(servers),\n\t\t\t\t\"unique_tools\":        uniqueTools,\n\t\t\t\t\"total_registrations\": totalRegistrations,\n\t\t\t\t\"agent_count\":         agentCount,\n\t\t\t})\n\n\t\t// Initializes Discovery Tools only if enabled by configuration\n\t\tif al.cfg.Tools.MCP.Enabled && al.cfg.Tools.MCP.Discovery.Enabled {\n\t\t\tuseBM25 := al.cfg.Tools.MCP.Discovery.UseBM25\n\t\t\tuseRegex := al.cfg.Tools.MCP.Discovery.UseRegex\n\n\t\t\t// Fail fast: If discovery is enabled but no search method is turned on\n\t\t\tif !useBM25 && !useRegex {\n\t\t\t\tal.mcp.setInitErr(fmt.Errorf(\n\t\t\t\t\t\"tool discovery is enabled but neither 'use_bm25' nor 'use_regex' is set to true in the configuration\",\n\t\t\t\t))\n\t\t\t\tif closeErr := mcpManager.Close(); closeErr != nil {\n\t\t\t\t\tlogger.ErrorCF(\"agent\", \"Failed to close MCP manager\",\n\t\t\t\t\t\tmap[string]any{\n\t\t\t\t\t\t\t\"error\": closeErr.Error(),\n\t\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tttl := al.cfg.Tools.MCP.Discovery.TTL\n\t\t\tif ttl <= 0 {\n\t\t\t\tttl = 5 // Default value\n\t\t\t}\n\n\t\t\tmaxSearchResults := al.cfg.Tools.MCP.Discovery.MaxSearchResults\n\t\t\tif maxSearchResults <= 0 {","sourceCodeStart":204,"sourceCodeEnd":240,"githubUrl":"https://github.com/sipeed/picoclaw/blob/49183d7e8daed0dba89ddbb6fcb60089401d9680/pkg/agent/agent_mcp.go#L204-L240","documentation":"MCP tool discovery registers hidden tools and exposes them through search backends. picoclaw supports two search methods, BM25 and regex, and this is a fail-fast config check in ensureMCPInitialized: when tools.mcp.discovery.enabled=true but both use_bm25 and use_regex are false, there is no search backend to surface deferred tools, so initialization aborts with this error.","triggerScenarios":"Setting tools.mcp.discovery.enabled=true together with use_bm25=false and use_regex=false (both default-overridden to false). Note the shipped default is use_bm25=true (pkg/config/defaults.go:436), so this only happens when BM25 is explicitly disabled without enabling regex.","commonSituations":"Copying a minimal discovery block from docs and zeroing both flags to 'save resources'; toggling use_bm25 off for CPU reasons and forgetting to enable regex; env overrides PICOCLAW_TOOLS_DISCOVERY_USE_BM25=false without PICOCLAW_TOOLS_DISCOVERY_USE_REGEX=true.","solutions":["Set at least one of use_bm25 / use_regex to true in tools.mcp.discovery (regex is the cheaper option)","If you do not want deferred tools at all, set discovery.enabled=false instead of disabling both engines","Check env overrides (PICOCLAW_TOOLS_DISCOVERY_USE_BM25 / _USE_REGEX) that may silently flip the flags","Restart picoclaw after the config change"],"exampleFix":"// config — before\n\"discovery\": { \"enabled\": true, \"use_bm25\": false, \"use_regex\": false }\n\n// after\n\"discovery\": { \"enabled\": true, \"use_bm25\": false, \"use_regex\": true }","handlingStrategy":"validation","validationCode":"if cfg.Tools.MCP.Enabled && cfg.Tools.MCP.Discovery.Enabled {\n    if !cfg.Tools.MCP.Discovery.UseBM25 && !cfg.Tools.MCP.Discovery.UseRegex {\n        return fmt.Errorf(\"tools.mcp.discovery: enable use_bm25 or use_regex (regex is cheaper)\")\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Add a config lint step that checks discovery engines whenever discovery.enabled is true","Watch env overrides PICOCLAW_TOOLS_DISCOVERY_USE_BM25/_USE_REGEX — they can flip flags silently","If neither engine is wanted, set discovery.enabled=false instead of zeroing both flags"],"tags":["go","picoclaw","mcp","tool-discovery","config","validation"],"backgroundTag":null,"analyzedSha":"49183d7e8daed0dba89ddbb6fcb60089401d9680","analyzedAt":"2026-08-15T21:55:41.315Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}