为 Node.js / Python MCP 服务器注入代理路由
在自定义 MCP 工具的 Http Client 内部绑定自动轮换代理实例。
example.py
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import axios from "axios";
import { HttpsProxyAgent } from "https-proxy-agent";
// 为所有 MCP 外部请求创建住宅代理客户端代理
const httpsAgent = new HttpsProxyAgent("http://user-youraccount-rotate:password@proxy.bytesflows.com:31112");
async function handleWebFetchTool(url: string) {
const response = await axios.get(url, { httpsAgent, timeout: 10000 });
return {
content: [{ type: "text", text: JSON.stringify(response.data) }]
};
}
console.log("MCP 服务器公网请求工具已挂载住宅物理代理出口。");