feat: disable the MCP server configuation by default (#444)

* feat: disable the MCP server configuation by default

* Fixed the lint and test errors

* fix the lint error
This commit is contained in:
Willem Jiang
2025-07-19 08:39:42 +08:00
committed by GitHub
parent dbb24d7d14
commit 75ad3e0dc6
4 changed files with 70 additions and 1 deletions

View File

@@ -71,6 +71,20 @@ graph = build_graph_with_memory()
@app.post("/api/chat/stream")
async def chat_stream(request: ChatRequest):
# Check if MCP server configuration is enabled
mcp_enabled = os.getenv("ENABLE_MCP_SERVER_CONFIGURATION", "false").lower() in [
"true",
"1",
"yes",
]
# Validate MCP settings if provided
if request.mcp_settings and not mcp_enabled:
raise HTTPException(
status_code=403,
detail="MCP server configuration is disabled. Set ENABLE_MCP_SERVER_CONFIGURATION=true to enable MCP features.",
)
thread_id = request.thread_id
if thread_id == "__default__":
thread_id = str(uuid4())
@@ -84,7 +98,7 @@ async def chat_stream(request: ChatRequest):
request.max_search_results,
request.auto_accepted_plan,
request.interrupt_feedback,
request.mcp_settings,
request.mcp_settings if mcp_enabled else {},
request.enable_background_investigation,
request.report_style,
request.enable_deep_thinking,
@@ -363,6 +377,17 @@ async def enhance_prompt(request: EnhancePromptRequest):
@app.post("/api/mcp/server/metadata", response_model=MCPServerMetadataResponse)
async def mcp_server_metadata(request: MCPServerMetadataRequest):
"""Get information about an MCP server."""
# Check if MCP server configuration is enabled
if os.getenv("ENABLE_MCP_SERVER_CONFIGURATION", "false").lower() not in [
"true",
"1",
"yes",
]:
raise HTTPException(
status_code=403,
detail="MCP server configuration is disabled. Set ENABLE_MCP_SERVER_CONFIGURATION=true to enable.",
)
try:
# Set default timeout with a longer value for this endpoint
timeout = 300 # Default to 300 seconds for this endpoint