Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix: fix mcp output_schema is optional (#39453)

wangxiaolei6f8ed69ee15f
diff --git a/api/core/tools/mcp_tool/tool.py b/api/core/tools/mcp_tool/tool.py
index 07c9ff63b30..d5b62a61a9c 100644
--- a/api/core/tools/mcp_tool/tool.py
+++ b/api/core/tools/mcp_tool/tool.py
@@ -107,6 +107,8 @@ class MCPTool(Tool):
if self.entity.output_schema and result.structuredContent:
for k, v in result.structuredContent.items():
yield self.create_variable_message(k, v)
+ elif result.structuredContent:
+ yield self.create_json_message(result.structuredContent)
def _process_text_content(self, content: TextContent) -> Generator[ToolInvokeMessage, None, None]:
"""Process text content and yield appropriate messages."""
diff --git a/api/tests/unit_tests/tools/test_mcp_tool.py b/api/tests/unit_tests/tools/test_mcp_tool.py
index eb7bb34dbe4..00a84f71f7f 100644
--- a/api/tests/unit_tests/tools/test_mcp_tool.py
+++ b/api/tests/unit_tests/tools/test_mcp_tool.py
@@ -135,6 +135,19 @@ class TestMCPToolInvoke:
values = {m.message.variable_name: m.message.variable_value for m in var_msgs}
assert values == {"a": 1, "b": "x"}
+ def test_invoke_yields_json_when_structured_content_has_no_output_schema(self, orm_session: Session) -> None:
+ tool = _make_mcp_tool()
+ result = CallToolResult(content=[], structuredContent={"a": 1, "b": "x"})
+
+ with patch.object(tool, "invoke_remote_mcp_tool", return_value=result):
+ messages = list(tool._invoke(session=orm_session, user_id="test_user", tool_parameters={}))
+
+ assert len(messages) == 1
+ msg = messages[0]
+ assert msg.type == ToolInvokeMessage.MessageType.JSON
+ assert isinstance(msg.message, ToolInvokeMessage.JsonMessage)
+ assert msg.message.json_object == {"a": 1, "b": "x"}
+
class TestMCPToolUsageExtraction:
"""Test usage metadata extraction from MCP tool results."""