Agent App registered as an MCP server: every tools/call fails

未关闭
#42,380 2 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
58/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
api, backend

调研方向

Start in api/core/mcp/server/streamable_http.py and trace handle_mcp_request, process_mapping_response, and extract_structured_output for AppMode.AGENT. Compare the Agent App stream in AgentAppRunner._publish_terminal_answer with legacy agent-chat events, then verify tools/call returns the persisted answer, structuredContent, and errors for failed runs without changing existing agent-chat results.

由索引模型根据 Issue 内容生成。

描述

What happens

An Agent App (AppMode.AGENT, the app type backed by an Agent Soul) can be published as an MCP server from the console. tools/list works and returns the tool, but every tools/call fails. The client receives:

{"jsonrpc": "2.0", "id": 1, "error": {"code": -32602, "message": "Agent App only supports streaming mode"}}
Steps to reproduce
  1. Create and publish an Agent App.
  2. Register it as an MCP server. The console endpoint (api/controllers/console/app/mcp_server.py) has no app-mode filter, so Agent Apps are accepted.
  3. Call the tool from any MCP client.
Where it comes from

api/core/mcp/server/streamable_http.py never requests a streaming run for this mode:

streaming=app.mode == AppMode.AGENT_CHAT,

Agent Apps reject blocking generation (api/core/app/apps/agent_app/app_generator.py:89), so the call stops there.

Streaming mode alone is not enough

The stream parser only accumulates agent_thought events. Agent Apps publish their answer on the chat message channel instead (AgentAppRunner._publish_terminal_answer -> publish_text_answer -> QueueLLMChunkEvent), so just enabling streaming produces a successful tool result with an empty answer, which is worse than a visible error. Two details matter for whoever picks this up:

  • Agent App agent_message events carry in-progress stream text that can differ from the terminal answer, and their agent_thought rows hold reasoning, so neither channel is the answer.
  • Legacy agent-chat sends the same text through both agent_thought and agent_message. Accumulating both by event name doubles every existing agent-chat answer.

extract_structured_output and process_mapping_response in the same file also have no AppMode.AGENT arm: the former returns None (so 2025-06-18 clients get no structuredContent), the latter raises ValueError: Invalid app mode: agent.

Executed evidence

Probing the module's public entry points on main (fea6b6e9), no server needed:

1) process_mapping_response(app, {'answer': ...})
   -> ValueError: Invalid app mode: agent
2) extract_structured_output(app, {'answer': 'hi'}, 'hi')
   -> None
3) answer extracted from a real Agent App stream
   -> answer=''
4) AgentAppGenerator.generate(streaming=False)
   -> AgentAppGeneratorError: Agent App only supports streaming mode
5) tools/call through handle_mcp_request
   -> {'jsonrpc': '2.0', 'id': 1, 'error': {'code': -32602, 'message': 'Agent App only supports streaming mode'}}

Probe 3 feeds the real SSE shape the app emits (agent_message deltas plus a terminal message chunk) and shows the answer would be empty even once streaming is enabled.

Expected behavior

tools/call returns the answer the app itself persists for the message, plus structuredContent for 2025-06-18 clients. A failed run should reach the client as an error rather than as an empty successful result.

主要语言
TypeScript
星标
157k
派生
24.7k
平均合并
22 小时 32 分钟
30 天内合并 PR
611

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

langgenius/dify 的其他 Issue

查看 langgenius/dify 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。