dify-plugin-tools-mcp_sse icon indicating copy to clipboard operation
dify-plugin-tools-mcp_sse copied to clipboard

无法添加streamable_http服务器 Cannot add streamable_http local servers

Open cashsun opened this issue 8 months ago • 6 comments

Please confirm before submission 在提交之前,请确认

Dify version Dify版本

1.2.0

Plugin version 插件版本

0.1.0

HTTP with SSE or Streamable HTTP

Streamable HTTP

Problem description 问题描述

我的本地docker mcp servers配置文件为以下:

{
  "home-mcp": {
    "url": "http://172.17.0.1:3001/mcp",
    "headers": {
      "accept": "application/json,text/event-stream",
      "content-type": "text/event-stream"
    },
    "transport": "streamable_http"
  },
  "context7": {
    "url": "http://172.17.0.1:3002/mcp",
    "headers": {
      "accept": "application/json,text/event-stream",
      "content-type": "text/event-stream"
    },
    "transport": "streamable_http"
  }
}

点保存的时候会收到下面报错

{
  "code": "invalid_param",
  "message": "PluginInvokeError: {\"args\":{},\"error_type\":\"JSONDecodeError\",\"message\":\"Expecting value: line 1 column 1 (char 0)\"}",
  "status": 400
}

如果把配置精简为

{
  "home-mcp": {
    "url": "http://172.17.0.1:3001/mcp",
    "transport": "streamable_http"
  },
  "context7": {
    "url": "http://172.17.0.1:3002/mcp",
    "transport": "streamable_http"
  }
}

则会收到以下报错

{
  "code": "invalid_param",
  "message": "PluginInvokeError: {\"args\":{},\"error_type\":\"Exception\",\"message\":\"MCP Server initialize error: {'code': -32000, 'message': 'Not Acceptable: Client must accept both application/json and text/event-stream'}\"}",
  "status": 400
}

cashsun avatar Apr 22 '25 15:04 cashsun

你第一个问题我没法复现,我的环境下在dify1.2.0版本是没有这个问题的,至于第二个问题是由于没有设置headers头导致的,所以你还是需要先解决第一个问题。再看下你的Dify版本是否是1.2.0,还是其他的版本。

junjiem avatar Apr 23 '25 03:04 junjiem

@cashsun @junjiem 1、同样出现了第一个问题,配置为:

{ "myserver": { "transport": "streamable_http", "url": "http://172.25.126.101:9277/mcp", "headers": { "Accept": "application/json, text/event-stream" } } }

保存时提示:

PluginInvokeError: {"args":{},"error_type":"JSONDecodeError","message":"Expecting value: line 1 column 1 (char 0)"}

dify为1.2.0版本

2、使用官方client库连接该streamable_http的mcp服务,功能正常

linancn avatar Apr 23 '25 10:04 linancn

@cashsun @junjiem 1、同样出现了第一个问题,配置为:

{ "myserver": { "transport": "streamable_http", "url": "http://172.25.126.101:9277/mcp", "headers": { "Accept": "application/json, text/event-stream" } } }

保存时提示:

PluginInvokeError: {"args":{},"error_type":"JSONDecodeError","message":"Expecting value: line 1 column 1 (char 0)"}

dify为1.2.0版本

2、使用官方client库连接该streamable_http的mcp服务,功能正常

我也遇到了这个问题。mcp server 基于typescript sdk 实现 Link

client端基于{ "myserver": { "transport": "streamable_http", "url": "http://localhost:8000/mcp", "headers": { "Accept": "application/json, text/event-stream" } } } 这种配置调用后,服务端返回的数据为 {'status_code': 200, 'headers': Headers({'connection': 'close', 'transfer-encoding': 'chunked', 'cache-control': 'no-cache', 'content-type': 'text/event-stream', 'date': 'Sat, 26 Apr 2025 05:54:10 GMT', 'mcp-session-id': 'e1d53a67-5fd0-48c4-84cc-b429c7d6dd62', 'x-powered-by': 'Express'}), '_request': <Request('POST', 'http://localhost:8000/mcp')>, 'next_request': None, 'extensions': {'http_version': b'HTTP/1.1', 'reason_phrase': b'OK', 'network_stream': <httpcore._backends.sync.SyncStream object at 0x000002AD33F76600>}, 'history': [], 'is_closed': True, 'is_stream_consumed': True, 'default_encoding': 'utf-8', 'stream': <httpx._client.BoundSyncStream object at 0x000002AD3198B620>, '_num_bytes_downloaded': 164, '_decoder': <httpx._decoders.IdentityDecoder object at 0x000002AD33725700>, '_elapsed': datetime.timedelta(microseconds=4349), '_content': b'event: message\ndata: {"result":{"protocolVersion":"2024-11-05","capabilities":{},"serverInfo":{"name":"example-server","version":"1.0.0"}},"jsonrpc":"2.0","id":0}\n\n' 为SSE的格式,所以 mcp_client.py 在https://github.com/junjiem/dify-plugin-tools-mcp_sse/blob/da92970201a2c860b25fd812f23943f45ee371e5/utils/mcp_client.py#L263 读取json的时候报错了,因为 'event: message\ndata: {"result":{"protocolVersion":"2024-11-05","capabilities":{},"serverInfo":{"name":"example-server","version":"1.0.0"}},"jsonrpc":"2.0","id":0}\n\n' 明显不是json格式。

omgwtfholyshit avatar Apr 26 '25 06:04 omgwtfholyshit

对于获取工具列表和调用工具是不需要流式的,所以目前还没有支持text/event-stream。初始化这里我后续会修复

junjiem avatar Apr 27 '25 01:04 junjiem

对于获取工具列表和调用工具是不需要流式的,所以目前还没有支持text/event-stream。初始化这里我后续会修复

什么时候修复呢?现在mcp已经支持streamable http方式了,dify1.3.1配置不了

Image

kylin0 avatar May 12 '25 10:05 kylin0

我这里测试,插件最新版本可以用了,

zhyyyq avatar Jun 05 '25 06:06 zhyyyq