You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MCP客户端无法通过streamable-http传输连接FastMCP服务器

MCP客户端通过streamable-http连接FastMCP服务器返回400 Bad Request问题排查

客户端代码

config = {
    "mcpServers":{
        "server name": {
            "url": "http://host.docker.internal:3002/mcp",
        }
    }
}
self.mcp_client = MCPClient.from_dict(config)
adapter = LangChainAdapter()
self.mcp_tools = await adapter.create_tools(self.mcp_client)

服务端代码

mcp = FastMCP("CyberChef API MCP Server",port=3002,host="0.0.0.0")
transport = "streamable-http"
mcp.run(transport=transport)

相关日志

INFO: mcp.server.streamable_http_manager:Created new transport with session ID: 510d091ef8fb4fb1a84e93696bed5164
cyberchef-api-mcp-server | INFO: 172.18.0.1:51336 - "GET /mcp HTTP/1.1" 400 Bad Request
packet_analyzer | DEBUG:httpcore.http11:receive_response_headers.complete return_value=(b'HTTP/1.1', 400, b'Bad Request', [(b'date', b'Thu, 16 Oct 2025 10:05:20 GMT'), (b'server', b'uvicorn'), (b'content-type', b'application/json'), (b'mcp-session-id', b'510d091ef8fb4fb1a84e93696bed5164'), (b'content-length', b'105')])
packet_analyzer | INFO:httpx:HTTP Request: GET http://host.docker.internal:3002/mcp "HTTP/1.1 400 Bad Request"

解决方向

  1. 补充客户端传输协议配置
    当前客户端配置未指定传输类型,streamable-http需要明确声明。修改config:
config = {
    "mcpServers":{
        "server name": {
            "url": "http://host.docker.internal:3002/mcp",
            "transport": "streamable-http"  # 新增传输协议指定
        }
    }
}
  1. 检查请求方法匹配性
    streamable-http传输通常要求POST请求,但日志显示客户端发起的是GET。确认MCPClient或LangChainAdapter是否自动适配传输对应的请求方法,必要时手动指定请求类型为POST。

  2. 获取详细错误信息
    服务端返回了105字节的JSON错误内容,可在客户端捕获完整响应体,或在服务端开启debug级日志,查看400错误的具体原因(如缺少必填请求头、参数格式错误等)。

  3. 验证Docker网络请求
    在客户端容器内执行curl -v http://host.docker.internal:3002/mcp,模拟请求并查看完整响应细节,排查是协议不兼容还是配置遗漏问题。

内容的提问来源于stack exchange,提问作者sk2000

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 04:42:41