wsl-round-mcp:修复代理劫持导致的 502 + 输入嗅探增强

- 两个脚本的 HTTP 请求改为 ProxyHandler({}) 强制绕过系统代理:
  环境有 HTTP_PROXY/HTTPS_PROXY 时,urllib 会把 localhost 请求也丢给代理,
  结果代理回 502,看起来像 OC 挂了其实是被劫走(本轮实测复现)
  需要走代理时用 MCPCTL_USE_PROXY=1 / OCSKILL_USE_PROXY=1 显式开启
- ocskill 输入嗅探增强:未知后缀按魔数/内容识别 .b64、zip、markdown
- frontmatter 支持 YAML 块标量(description: > |),中文折行不补空格
- 新增子仓库自身 .gitignore(父仓库的 ignore 对子仓库无效,__pycache__ 曾被误提交)
- README 补充代理 502 与 401 随机密码的排查说明
This commit is contained in:
ypshidifu
2026-09-23 12:24:31 +08:00
parent 873d965ef3
commit 35513f1cdf
3 changed files with 33 additions and 6 deletions
+10 -2
View File
@@ -167,6 +167,14 @@ def _wsl_ip(distro: str) -> str:
return ""
# 关键:本机/WSL 的 OC 绝不能走系统代理。
# 环境里若有 HTTP_PROXY/HTTPS_PROXY,urlopen 会把 localhost 请求丢给代理,
# 结果是代理回 502 —— 看起来像 OC 挂了,其实是被劫走了。
_NO_PROXY_OPENER = urllib.request.build_opener(urllib.request.ProxyHandler({}))
if os.environ.get("MCPCTL_USE_PROXY"):
_NO_PROXY_OPENER = urllib.request.build_opener()
def _post(url: str, password: str, timeout: float) -> tuple[int, str]:
req = urllib.request.Request(url, method="POST", data=b"{}")
req.add_header("content-type", "application/json")
@@ -174,7 +182,7 @@ def _post(url: str, password: str, timeout: float) -> tuple[int, str]:
if password:
req.add_header("authorization", f"Bearer {password}")
try:
with urllib.request.urlopen(req, timeout=timeout) as resp:
with _NO_PROXY_OPENER.open(req, timeout=timeout) as resp:
return resp.status, resp.read().decode("utf-8", "replace")
except urllib.error.HTTPError as exc:
if exc.code == 401 and password:
@@ -183,7 +191,7 @@ def _post(url: str, password: str, timeout: float) -> tuple[int, str]:
req2.add_header("content-type", "application/json")
req2.add_header("authorization", f"Basic {raw}")
try:
with urllib.request.urlopen(req2, timeout=timeout) as resp:
with _NO_PROXY_OPENER.open(req2, timeout=timeout) as resp:
return resp.status, resp.read().decode("utf-8", "replace")
except urllib.error.HTTPError as exc2:
return exc2.code, str(exc2)