Skip to content

Commit 2e4b69e

Browse files
committed
CONFLUENCE_URL empty string means Confluence use is disabled
1 parent 325ff82 commit 2e4b69e

1 file changed

Lines changed: 24 additions & 14 deletions

File tree

‎mcp_server.py‎

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -293,11 +293,15 @@ def _search_confluence(query: str) -> list[NodeWithScore]:
293293
Search Confluence for documents matching the query using CQL.
294294
Returns a list of NodeWithScore objects compatible with the reranker.
295295
"""
296+
base_url = os.getenv("CONFLUENCE_URL")
297+
# If CONFLUENCE_URL is unset or empty, disable search completely
298+
if not base_url:
299+
return []
300+
296301
if ConfluenceReader is None:
297302
logger.warning("llama-index-readers-confluence not installed, skipping Confluence search")
298303
return []
299304

300-
base_url = os.getenv("CONFLUENCE_URL")
301305
username = os.getenv("CONFLUENCE_USERNAME")
302306
api_token = os.getenv("CONFLUENCE_API_TOKEN")
303307

@@ -407,19 +411,25 @@ async def retrieve_docs(query: str) -> dict[str, Any]:
407411
nodes = retriever.retrieve(enhanced_query)
408412

409413
# Search Confluence in parallel (with timeout)
410-
try:
411-
# Run blocking generic search in executor
412-
loop = asyncio.get_running_loop()
413-
confluence_nodes = await asyncio.wait_for(
414-
loop.run_in_executor(None, _search_confluence, query),
415-
timeout=CONFLUENCE_TIMEOUT
416-
)
417-
if confluence_nodes:
418-
nodes.extend(confluence_nodes)
419-
except asyncio.TimeoutError:
420-
logger.warning(f"Confluence search timed out after {CONFLUENCE_TIMEOUT}s")
421-
except Exception as e:
422-
logger.error(f"Error during Confluence search: {e}")
414+
# Optimization: Check if CONFLUENCE_URL is set before even attempting it
415+
confluence_nodes = []
416+
if os.getenv("CONFLUENCE_URL"):
417+
try:
418+
# Run blocking generic search in executor
419+
loop = asyncio.get_running_loop()
420+
result = await asyncio.wait_for(
421+
loop.run_in_executor(None, _search_confluence, query),
422+
timeout=CONFLUENCE_TIMEOUT
423+
)
424+
if result:
425+
confluence_nodes = result
426+
except asyncio.TimeoutError:
427+
logger.warning(f"Confluence search timed out after {CONFLUENCE_TIMEOUT}s")
428+
except Exception as e:
429+
logger.error(f"Error during Confluence search: {e}")
430+
431+
if confluence_nodes:
432+
nodes.extend(confluence_nodes)
423433

424434
# Rerank the retrieved nodes with FlashRank (CPU-only, ONNX-based) and trim to the
425435
# configured final Top K for the tool response.

0 commit comments

Comments
 (0)