mirror of
https://gitee.com/wanwujie/deer-flow
synced 2026-04-03 06:12:14 +08:00
feat: polish the mcp-server configure feature (#447)
* feat: disable the MCP server configuation by default * Fixed the lint and test errors * fix the lint error * feat:update the mcp config documents and tests * fixed the lint errors
This commit is contained in:
@@ -13,7 +13,8 @@ AGENT_RECURSION_LIMIT=30
|
|||||||
ALLOWED_ORIGINS=http://localhost:3000
|
ALLOWED_ORIGINS=http://localhost:3000
|
||||||
|
|
||||||
# Enable or disable MCP server configuration, the default is false.
|
# 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.
|
# Otherwise, you system could be compromised.
|
||||||
ENABLE_MCP_SERVER_CONFIGURATION=false
|
ENABLE_MCP_SERVER_CONFIGURATION=false
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
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
|
Please enable this feature before securing your frond-end and back-end in an internal environment.q
|
||||||
|
|||||||
@@ -385,7 +385,7 @@ async def mcp_server_metadata(request: MCPServerMetadataRequest):
|
|||||||
]:
|
]:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=403,
|
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:
|
try:
|
||||||
|
|||||||
@@ -346,7 +346,7 @@ class TestMCPEndpoint:
|
|||||||
assert response.status_code == 403
|
assert response.status_code == 403
|
||||||
assert (
|
assert (
|
||||||
response.json()["detail"]
|
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.status_code == 200
|
||||||
assert response.headers["content-type"] == "text/event-stream; charset=utf-8"
|
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:
|
class TestAstreamWorkflowGenerator:
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
|
|||||||
Reference in New Issue
Block a user