feat: 代理支持 --upstream-proxy,修复 MCP 外部数据库国内直连不可达#14
Open
estelledc wants to merge 1 commit into
Open
Conversation
问题:Streamable HTTP MCP 服务器(PubMed/ChEMBL/clinical-trials/biorxiv) 在国内网络环境下直连不可达。CSswitch 代理的 CONNECT 隧道直连目标, 不经过用户的翻墙代理,导致连接超时/失败。 修改: - csswitch_proxy.py:新增 --upstream-proxy 参数(host:port) 非 Anthropic 域的 CONNECT 隧道经上游代理建立,而非直连 - config.rs:新增 upstream_proxy 配置字段(持久化) - lib.rs:ensure_proxy() 传递 --upstream-proxy 给代理进程 - launch-virtual-sandbox.sh:支持 --upstream-proxy 参数, 同时设 http_proxy 指向上游代理(MCP HTTP 请求出墙) 用法: 代理: python3 csswitch_proxy.py --upstream-proxy 127.0.0.1:7890 沙箱: launch-virtual-sandbox.sh --upstream-proxy http://127.0.0.1:7890 Closes SuperJJ007#11
Owner
|
牛逼。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
解决的问题
Closes #11
问题描述
Streamable HTTP MCP 服务器(PubMed、ChEMBL、clinical-trials、biorxiv)在国内网络环境下直连不可达。CSswitch 代理的 CONNECT 隧道目前是直连目标
socket.create_connection((host, port)),不经过用户的翻墙代理。错误日志:
注意:本地 stdio MCP 服务器(genes-ontologies、drug-regulatory 等 11 个)全部正常——只有需要出墙的 Streamable HTTP 类型失败。
根因
launch-virtual-sandbox.sh刻意不设http_proxy(因为代理未实现普通 HTTP 转发,设了反而会让 HTTP 请求撞代理拿 404)https_proxy指向 CSswitch 代理(18991),但do_CONNECT对非 Anthropic 域名是直连目标,不经翻墙代理eutils.ncbi.nlm.nih.gov、clinicaltrials.gov等域名直连超时修改
代理(csswitch_proxy.py)
--upstream-proxy host:port参数桌面端(config.rs + lib.rs)
upstream_proxy字段(持久化到~/.csswitch/config.json)ensure_proxy()启动代理进程时传递--upstream-proxy启动脚本(launch-virtual-sandbox.sh)
--upstream-proxy参数http_proxy指向上游代理(HTTP 的 MCP/包源请求走此通道)https_proxy仍指向 CSswitch 代理(Anthropic fast-fail + CONNECT 隧道经上游)使用方式
在 CSSwitch GUI 面板的
config.json中添加"upstream_proxy": "127.0.0.1:7890"后,点「一键开始」自动生效。验证
向后兼容
--upstream-proxy时行为不变(直连目标)config.json缺upstream_proxy字段时默认空字符串,走原有逻辑