diff --git a/.env.example b/.env.example index 4b655ff..89bb6b4 100644 --- a/.env.example +++ b/.env.example @@ -13,7 +13,8 @@ AGENT_RECURSION_LIMIT=30 ALLOWED_ORIGINS=http://localhost:3000 # Enable or disable MCP server configuration, the default is false. -# Please enable this feature before securing your front-end and back-end in an internal environment. +# Please enable this feature before securing your front-end and back-end in a managed environment. + # Otherwise, you system could be compromised. ENABLE_MCP_SERVER_CONFIGURATION=false diff --git a/docs/mcp_integrations.md b/docs/mcp_integrations.md index 76bb773..9ccf6fe 100644 --- a/docs/mcp_integrations.md +++ b/docs/mcp_integrations.md @@ -1,4 +1,10 @@ -# MCP Integrations +# MCP Integrations(Beta) + +Now This feature is diabled by default. You can enable it by setting the environment ENABLE_MCP_SERVER_CONFIGURATION to be true + +> [!WARNING] +> Please enable this feature before securing your frond-end and back-end in a managed environment. +> Otherwise, you system could be compromised. This feature is diabled by default. You can enable it by setting the environment ENABLE_MCP_SERVER_CONFIGURATION Please enable this feature before securing your frond-end and back-end in an internal environment.q diff --git a/src/server/app.py b/src/server/app.py index b457e3c..69cc9ca 100644 --- a/src/server/app.py +++ b/src/server/app.py @@ -385,7 +385,7 @@ async def mcp_server_metadata(request: MCPServerMetadataRequest): ]: raise HTTPException( status_code=403, - detail="MCP server configuration is disabled. Set ENABLE_MCP_SERVER_CONFIGURATION=true to enable.", + detail="MCP server configuration is disabled. Set ENABLE_MCP_SERVER_CONFIGURATION=true to enable MCP features.", ) try: diff --git a/tests/unit/server/test_app.py b/tests/unit/server/test_app.py index e72cb48..3df498d 100644 --- a/tests/unit/server/test_app.py +++ b/tests/unit/server/test_app.py @@ -346,7 +346,7 @@ class TestMCPEndpoint: assert response.status_code == 403 assert ( response.json()["detail"] - == "MCP server configuration is disabled. Set ENABLE_MCP_SERVER_CONFIGURATION=true to enable." + == "MCP server configuration is disabled. Set ENABLE_MCP_SERVER_CONFIGURATION=true to enable MCP features." ) @@ -413,6 +413,89 @@ class TestChatStreamEndpoint: assert response.status_code == 200 assert response.headers["content-type"] == "text/event-stream; charset=utf-8" + @patch("src.server.app.graph") + def test_chat_stream_with_mcp_settings(self, mock_graph, client): + # Mock the async stream + async def mock_astream(*args, **kwargs): + yield ("agent1", "step1", {"test": "data"}) + + mock_graph.astream = mock_astream + + request_data = { + "thread_id": "__default__", + "messages": [{"role": "user", "content": "Hello"}], + "resources": [], + "max_plan_iterations": 3, + "max_step_num": 10, + "max_search_results": 5, + "auto_accepted_plan": True, + "interrupt_feedback": "", + "mcp_settings": { + "servers": { + "mcp-github-trending": { + "transport": "stdio", + "command": "uvx", + "args": ["mcp-github-trending"], + "env": {"MCP_SERVER_ID": "mcp-github-trending"}, + "enabled_tools": ["get_github_trending_repositories"], + "add_to_agents": ["researcher"], + } + } + }, + "enable_background_investigation": False, + "report_style": "academic", + } + + response = client.post("/api/chat/stream", json=request_data) + + assert response.status_code == 403 + assert ( + response.json()["detail"] + == "MCP server configuration is disabled. Set ENABLE_MCP_SERVER_CONFIGURATION=true to enable MCP features." + ) + + @patch("src.server.app.graph") + @patch.dict( + os.environ, + {"ENABLE_MCP_SERVER_CONFIGURATION": "true"}, + ) + def test_chat_stream_with_mcp_settings_enabled(self, mock_graph, client): + # Mock the async stream + async def mock_astream(*args, **kwargs): + yield ("agent1", "step1", {"test": "data"}) + + mock_graph.astream = mock_astream + + request_data = { + "thread_id": "__default__", + "messages": [{"role": "user", "content": "Hello"}], + "resources": [], + "max_plan_iterations": 3, + "max_step_num": 10, + "max_search_results": 5, + "auto_accepted_plan": True, + "interrupt_feedback": "", + "mcp_settings": { + "servers": { + "mcp-github-trending": { + "transport": "stdio", + "command": "uvx", + "args": ["mcp-github-trending"], + "env": {"MCP_SERVER_ID": "mcp-github-trending"}, + "enabled_tools": ["get_github_trending_repositories"], + "add_to_agents": ["researcher"], + } + } + }, + "enable_background_investigation": False, + "report_style": "academic", + } + + response = client.post("/api/chat/stream", json=request_data) + + assert response.status_code == 200 + assert response.headers["content-type"] == "text/event-stream; charset=utf-8" + class TestAstreamWorkflowGenerator: @pytest.mark.asyncio