proxy302-mcp 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -2
- package/README.zh-CN.md +2 -2
- package/dist/fetchPage.js +4 -1
- package/dist/tools.js +64 -25
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,9 +8,11 @@ Give your AI assistant a real residential-proxy toolbox. `proxy302-mcp` is a [Mo
|
|
|
8
8
|
|
|
9
9
|
[中文说明](README.zh-CN.md)
|
|
10
10
|
|
|
11
|
+
[](https://glama.ai/mcp/servers/proxy302/proxy302-mcp) [](https://glama.ai/mcp/connectors/io.github.proxy302/proxy302-mcp)
|
|
12
|
+
|
|
11
13
|
<p align="center"><img src="https://raw.githubusercontent.com/proxy302/proxy302-mcp/main/docs/images/how-it-works.svg" alt="How it works: your AI assistant talks to proxy302-mcp on your machine, which calls the Proxy302 API with your key and fetches pages through a residential IP" width="100%"></p>
|
|
12
14
|
|
|
13
|
-
> v1 is deliberately **read-only and spend-free**: it never buys, renews or tops up anything. The one write it can do (creating a dynamic proxy credential) is free
|
|
15
|
+
> v1 is deliberately **read-only and spend-free**: it never buys, renews or tops up anything. The one write it can do (creating a dynamic proxy credential) is free and only bills traffic when you actually use it: `get_dynamic_proxy` creates one only with `create_if_missing=true`; `fetch_url` with a country creates one on the budget line when you have none (pass `create_if_missing=false` to stop that).
|
|
14
16
|
|
|
15
17
|
## Hosted server (no install)
|
|
16
18
|
|
|
@@ -112,7 +114,7 @@ Bonus: Proxy302 credits **1 PTC** to paid accounts the first time a call through
|
|
|
112
114
|
| `list_isps` | ISPs the premium line can target in a country |
|
|
113
115
|
| `rotate_ip` | New exit IP for sticky proxies: returns a fresh-session URL that switches at once |
|
|
114
116
|
| `list_my_proxies` | Your dynamic proxies and static IPs, passwords masked unless asked |
|
|
115
|
-
| `fetch_url` |
|
|
117
|
+
| `fetch_url` | Fetch a URL through a residential IP in a given country and return Markdown, text or raw, in one call (creates a budget-line proxy for that country if you have none) |
|
|
116
118
|
|
|
117
119
|
Not in v1, on purpose: purchases, renewals, top-ups.
|
|
118
120
|
|
|
@@ -155,6 +157,8 @@ agent = Agent(task="Open ipinfo.io and tell me the country", llm=llm, browser=br
|
|
|
155
157
|
|
|
156
158
|
`fetch_url` is a plain HTTP request without JavaScript rendering. For JavaScript-heavy sites, hand the proxy URL to a browser as above.
|
|
157
159
|
|
|
160
|
+
Not sure which proxy type a task needs (static ISP or rotating residential, TikTok, anti-detect browsers, Claude and ChatGPT)? See the [Proxy302 guides](https://github.com/proxy302/proxy-guides).
|
|
161
|
+
|
|
158
162
|
## Configuration
|
|
159
163
|
|
|
160
164
|
| Variable | Meaning |
|
package/README.zh-CN.md
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
<p align="center"><img src="https://raw.githubusercontent.com/proxy302/proxy302-mcp/main/docs/images/how-it-works.svg" alt="工作原理:AI 助手调用你电脑上的 proxy302-mcp,它用你的密钥调用 Proxy302 接口,并通过住宅 IP 抓取网页" width="100%"></p>
|
|
12
12
|
|
|
13
|
-
> v1
|
|
13
|
+
> v1 只做只读、不花钱的功能:不购买、不续费、不充值。唯一的写操作(创建动态代理凭证)免费,只在你真正使用时才按流量计费:`get_dynamic_proxy` 只在 `create_if_missing=true` 时创建;`fetch_url` 指定国家且你还没有该国代理时,会在低价线自动建一条(传 `create_if_missing=false` 可关掉)。
|
|
14
14
|
|
|
15
15
|
## 不用安装:直接连官方托管的服务器
|
|
16
16
|
|
|
@@ -95,7 +95,7 @@ claude mcp add proxy302 -e PROXY302_API_KEY="<key id>:<secret>" -- npx -y github
|
|
|
95
95
|
| `list_isps` | 某国优质线路可指定的运营商 |
|
|
96
96
|
| `rotate_ip` | 粘性代理换出口 IP:返回一个新会话的地址,立即生效 |
|
|
97
97
|
| `list_my_proxies` | 你的动态代理和静态 IP,密码默认打码 |
|
|
98
|
-
| `fetch_url` |
|
|
98
|
+
| `fetch_url` | 用指定国家的住宅 IP 请求网址,一步返回 Markdown、纯文本或原文(没有该国代理时自动在低价线建一条) |
|
|
99
99
|
|
|
100
100
|
## 示例
|
|
101
101
|
|
package/dist/fetchPage.js
CHANGED
|
@@ -42,7 +42,10 @@ export async function fetchThroughProxy(rawUrl, proxy, opts = {}) {
|
|
|
42
42
|
catch (e) {
|
|
43
43
|
if (e instanceof Proxy302Error)
|
|
44
44
|
throw e;
|
|
45
|
-
|
|
45
|
+
// undici says only "fetch failed"; the reason (a 407 from the proxy, a reset, a timeout) is in the cause.
|
|
46
|
+
const cause = e.cause;
|
|
47
|
+
const why = [cause?.code, cause?.message].filter(Boolean).join(' ');
|
|
48
|
+
throw new Proxy302Error(`Request through the proxy failed: ${e.message}${why ? ` (${why})` : ''}`);
|
|
46
49
|
}
|
|
47
50
|
finally {
|
|
48
51
|
await agent.close().catch(() => undefined);
|
package/dist/tools.js
CHANGED
|
@@ -86,6 +86,37 @@ const NO_TRAFFIC_PACKAGE = new Set([
|
|
|
86
86
|
'No matching traffic package for this line; purchase a same-config traffic package or enable auto-refill',
|
|
87
87
|
'No unexpired traffic pool matches the selected provider configuration',
|
|
88
88
|
]);
|
|
89
|
+
/** Create a dynamic proxy (free; traffic billed per GB on use). Same idempotency key as before, so a retry never makes a second one.
|
|
90
|
+
* Like the Proxy302 console: with no traffic package for this line the wallet pays per GB (the API refuses a wallet that cannot
|
|
91
|
+
* cover the pay-as-you-go hold). */
|
|
92
|
+
async function createDynamic(client, o) {
|
|
93
|
+
const key = `mcp-${o.c.id}-${o.s?.id ?? 0}-${o.ci?.id ?? 0}-${o.protocol}-${o.line}${o.isp ? `-${o.isp}` : ''}`;
|
|
94
|
+
const body = { s: o.line === 'premium' ? 1 : 3, protocol: o.protocol, country_id: o.c.id, state_id: o.s?.id ?? 0, city_id: o.ci?.id ?? 0, ...(o.isp ? { isp: o.isp } : {}) };
|
|
95
|
+
let billedFrom = 'traffic_package';
|
|
96
|
+
const out = await client.generateDynamic({ ...body, idempotency_key: key }).catch((e) => {
|
|
97
|
+
if (!(e instanceof Proxy302Error && NO_TRAFFIC_PACKAGE.has(e.message)))
|
|
98
|
+
throw e;
|
|
99
|
+
billedFrom = 'wallet';
|
|
100
|
+
return client.generateDynamic({ ...body, billing_mode: 'payg_wallet', idempotency_key: `${key}-payg` });
|
|
101
|
+
});
|
|
102
|
+
return { out, billedFrom };
|
|
103
|
+
}
|
|
104
|
+
/** A proxy created a moment ago can be refused (407) or not answer until the gateway has picked it up: retry a few times. */
|
|
105
|
+
async function fetchFresh(url, endpoint, opts, fresh, waitMs = 3000) {
|
|
106
|
+
for (let attempt = 0;; attempt += 1) {
|
|
107
|
+
try {
|
|
108
|
+
const result = await fetchThroughProxy(url, endpoint, opts);
|
|
109
|
+
if (!fresh || result.status !== 407 || attempt >= 3)
|
|
110
|
+
return result;
|
|
111
|
+
}
|
|
112
|
+
catch (e) {
|
|
113
|
+
// An https tunnel refused by the proxy throws "Proxy response (407) …"; a timeout to the site is not retried.
|
|
114
|
+
if (!fresh || attempt >= 3 || !/\b407\b|ECONNRESET|other side closed|socket hang up/i.test(e.message))
|
|
115
|
+
throw e;
|
|
116
|
+
}
|
|
117
|
+
await new Promise(resolve => setTimeout(resolve, waitMs));
|
|
118
|
+
}
|
|
119
|
+
}
|
|
89
120
|
export function registerTools(server, client) {
|
|
90
121
|
server.registerTool('get_account_usage', {
|
|
91
122
|
title: 'Account, traffic balance and usage',
|
|
@@ -197,17 +228,7 @@ export function registerTools(server, client) {
|
|
|
197
228
|
if (!create_if_missing) {
|
|
198
229
|
throw new Proxy302Error(`No existing ${protocol} ${line} dynamic proxy for ${label}${ispOption ? ` on ${ispOption.label}` : ''}. Call again with create_if_missing=true to create one (free to create; billed per GB on use).`);
|
|
199
230
|
}
|
|
200
|
-
const
|
|
201
|
-
const body = { s: line === 'premium' ? 1 : 3, protocol, country_id: c.id, state_id: s?.id ?? 0, city_id: ci?.id ?? 0, ...(ispOption ? { isp: ispOption.key } : {}) };
|
|
202
|
-
// Like the Proxy302 console: with no traffic package for this line the wallet pays per GB (the API refuses a wallet
|
|
203
|
-
// that cannot cover the pay-as-you-go hold). A wallet-only account could never create a proxy here before.
|
|
204
|
-
let billedFrom = 'traffic_package';
|
|
205
|
-
const out = await client.generateDynamic({ ...body, idempotency_key: key }).catch((e) => {
|
|
206
|
-
if (!(e instanceof Proxy302Error && NO_TRAFFIC_PACKAGE.has(e.message)))
|
|
207
|
-
throw e;
|
|
208
|
-
billedFrom = 'wallet';
|
|
209
|
-
return client.generateDynamic({ ...body, billing_mode: 'payg_wallet', idempotency_key: `${key}-payg` });
|
|
210
|
-
});
|
|
231
|
+
const { out, billedFrom } = await createDynamic(client, { c, s, ci, protocol, line, isp: ispOption?.key });
|
|
211
232
|
return ok(withSession({
|
|
212
233
|
reused: false, token_id: out.token_id, billed_from: billedFrom, line, area: [label, ispOption?.label].filter(Boolean).join(' - '), protocol: out.protocol,
|
|
213
234
|
host: out.host, port: out.port, username: out.username, password: out.password,
|
|
@@ -273,42 +294,60 @@ export function registerTools(server, client) {
|
|
|
273
294
|
}));
|
|
274
295
|
server.registerTool('fetch_url', {
|
|
275
296
|
title: 'Fetch a web page through a Proxy302 proxy',
|
|
276
|
-
description: 'Request a URL from your machine through
|
|
297
|
+
description: 'Request a URL from your machine through a Proxy302 residential IP in a given country and return the page as Markdown, plain text or raw, in one call. '
|
|
298
|
+
+ 'Uses one of your dynamic proxies for that country; if you have none, it creates one on the budget line (free to create, like get_dynamic_proxy) unless create_if_missing=false. '
|
|
299
|
+
+ 'Traffic is billed per GB from a traffic package for that line if you have one, otherwise from the wallet. '
|
|
300
|
+
+ 'A plain HTTP request without JavaScript rendering: for JS-heavy sites use a browser with the proxy URL from get_dynamic_proxy.',
|
|
277
301
|
inputSchema: {
|
|
278
302
|
url: z.string().url(),
|
|
279
|
-
country: z.string().optional().describe('Exit country
|
|
280
|
-
token_id: z.union([z.number(), z.string()]).optional().describe('Use a specific proxy from list_my_proxies'),
|
|
303
|
+
country: z.string().optional().describe('Exit country (name, ISO code or id), e.g. "DE"'),
|
|
304
|
+
token_id: z.union([z.number(), z.string()]).optional().describe('Use a specific proxy from list_my_proxies instead'),
|
|
305
|
+
create_if_missing: z.boolean().default(true).describe('With a country and no proxy for it yet: create one on the budget line (free to create). false = only use existing proxies'),
|
|
281
306
|
format: z.enum(['markdown', 'text', 'raw']).default('markdown'),
|
|
282
307
|
max_chars: z.number().int().min(500).max(200000).default(20000),
|
|
283
308
|
},
|
|
284
|
-
annotations: { readOnlyHint: true, openWorldHint: true },
|
|
285
|
-
}, safe(async ({ url, country, token_id, format, max_chars }) => {
|
|
309
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: true },
|
|
310
|
+
}, safe(async ({ url, country, token_id, create_if_missing, format, max_chars }) => {
|
|
286
311
|
const rows = (await client.tokens('dynamic', 'traffic', { page_size: 200 })).data.filter(r => usable(r) && (r.network ?? 'http') !== 'socks5' && toEndpoint(r));
|
|
287
|
-
let
|
|
312
|
+
let via;
|
|
313
|
+
let endpoint;
|
|
288
314
|
if (token_id !== undefined) {
|
|
289
|
-
row = rows.find(r => String(r.token_id ?? r.id) === String(token_id));
|
|
315
|
+
let row = rows.find(r => String(r.token_id ?? r.id) === String(token_id));
|
|
290
316
|
if (!row) {
|
|
291
317
|
const statics = (await client.tokens('static', 'ip', { page_size: 200 })).data.filter(r => usable(r) && toEndpoint(r));
|
|
292
318
|
row = statics.find(r => String(r.token_id ?? r.id) === String(token_id));
|
|
293
319
|
}
|
|
294
320
|
if (!row)
|
|
295
321
|
throw new Proxy302Error(`Proxy ${token_id} not found, inactive or not an HTTP proxy.`);
|
|
322
|
+
via = { token_id: row.token_id ?? row.id, area: row.proxy_area || 'any' };
|
|
323
|
+
endpoint = toEndpoint(row);
|
|
296
324
|
}
|
|
297
325
|
else if (country) {
|
|
298
326
|
const c = await resolveArea(client, 'country', country);
|
|
299
|
-
row = rows.find(r => matchesCountry(r, c.name));
|
|
300
|
-
if (
|
|
301
|
-
|
|
327
|
+
const row = rows.find(r => matchesCountry(r, c.name));
|
|
328
|
+
if (row) {
|
|
329
|
+
via = { token_id: row.token_id ?? row.id, area: row.proxy_area || 'any' };
|
|
330
|
+
endpoint = toEndpoint(row);
|
|
331
|
+
}
|
|
332
|
+
else {
|
|
333
|
+
if (!create_if_missing)
|
|
334
|
+
throw new Proxy302Error(`You have no active HTTP dynamic proxy for ${c.name}. Call again with create_if_missing=true (free to create; billed per GB on use).`);
|
|
335
|
+
const { out, billedFrom } = await createDynamic(client, { c, protocol: 'http', line: 'budget' });
|
|
336
|
+
via = { token_id: out.token_id, area: c.name, created: true, billed_from: billedFrom };
|
|
337
|
+
endpoint = { host: out.host, port: Number(out.port), username: out.username, password: out.password };
|
|
338
|
+
}
|
|
302
339
|
}
|
|
303
340
|
else {
|
|
304
|
-
row = rows[0];
|
|
341
|
+
const row = rows[0];
|
|
305
342
|
if (!row)
|
|
306
|
-
throw new Proxy302Error('You have no active dynamic proxy yet.
|
|
343
|
+
throw new Proxy302Error('You have no active dynamic proxy yet. Pass a country (one is created for it), or run get_dynamic_proxy first.');
|
|
344
|
+
via = { token_id: row.token_id ?? row.id, area: row.proxy_area || 'any' };
|
|
345
|
+
endpoint = toEndpoint(row);
|
|
307
346
|
}
|
|
308
|
-
const result = await
|
|
347
|
+
const result = await fetchFresh(url, endpoint, { format, maxChars: max_chars }, via.created === true);
|
|
309
348
|
return {
|
|
310
349
|
content: [
|
|
311
|
-
{ type: 'text', text: JSON.stringify({ via
|
|
350
|
+
{ type: 'text', text: JSON.stringify({ via, status: result.status, final_url: result.finalUrl, content_type: result.contentType, truncated: result.truncated }) },
|
|
312
351
|
{ type: 'text', text: result.content },
|
|
313
352
|
],
|
|
314
353
|
};
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '0.
|
|
1
|
+
export const VERSION = '0.3.0';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "proxy302-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Official Proxy302 MCP server: check usage, browse locations, get residential proxy credentials and fetch pages through a proxy from Claude, Cursor and other AI tools.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|