@mrfentmen/httpbin-mcp 1.0.0 → 1.0.1
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 +20 -0
- package/dist/api.js +63 -0
- package/dist/license.js +80 -0
- package/dist/server.js +56 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -20,3 +20,23 @@ node dist/index.js
|
|
|
20
20
|
```
|
|
21
21
|
|
|
22
22
|
Data comes from the public HTTPBin API.
|
|
23
|
+
|
|
24
|
+
<!-- paywall -->
|
|
25
|
+
## Premium tools
|
|
26
|
+
|
|
27
|
+
These tools need a license key:
|
|
28
|
+
|
|
29
|
+
* `base64_decode`
|
|
30
|
+
* `echo_anything`
|
|
31
|
+
* `status_check`
|
|
32
|
+
|
|
33
|
+
Buy a key at https://mcp-marketplace.io/server/io-github-mrfentmen-httpbin-mcp and set it in your MCP client config:
|
|
34
|
+
|
|
35
|
+
```json
|
|
36
|
+
"env": { "MCP_LICENSE_KEY": "mcp_live_..." }
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
The key is checked against MCP Marketplace, cached for 24 hours, and keeps
|
|
40
|
+
working offline once one check has succeeded. Every other tool on this server
|
|
41
|
+
stays free.
|
|
42
|
+
<!-- /paywall -->
|
package/dist/api.js
CHANGED
|
@@ -33,3 +33,66 @@ export async function headers(_args) {
|
|
|
33
33
|
const h = d.headers ?? {};
|
|
34
34
|
return 'Request headers:\n' + Object.entries(h).map(([k, v]) => `${k}: ${String(v)}`).join('\n');
|
|
35
35
|
}
|
|
36
|
+
// ---- muxC tools:
|
|
37
|
+
const HB_UA = "mrfentmen-httpbin-mcp/1.0 (https://github.com/mrfentmen)";
|
|
38
|
+
class HttpbinError extends Error {
|
|
39
|
+
}
|
|
40
|
+
const HB = "https://httpbin.org";
|
|
41
|
+
async function hbText(path, ms = 25000) {
|
|
42
|
+
const res = await fetch(`${HB}${path}`, {
|
|
43
|
+
headers: { "User-Agent": HB_UA, Accept: "*/*" },
|
|
44
|
+
signal: AbortSignal.timeout(ms),
|
|
45
|
+
});
|
|
46
|
+
if (!res.ok)
|
|
47
|
+
throw new HttpbinError(`httpbin returned ${res.status} for ${path}`);
|
|
48
|
+
return await res.text();
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* httpbin.org only exposes /base64/<value>, which decodes; there is no encode
|
|
52
|
+
* route. On bad input it answers 200 with a "try: ..." correction, so that hint
|
|
53
|
+
* is passed through instead of being hidden.
|
|
54
|
+
*/
|
|
55
|
+
export async function base64Decode(args) {
|
|
56
|
+
const value = (args.value ?? "").trim();
|
|
57
|
+
if (!value)
|
|
58
|
+
throw new HttpbinError("Provide the base64 text to decode");
|
|
59
|
+
if (!/^[A-Za-z0-9+/]+={0,2}$/.test(value)) {
|
|
60
|
+
throw new HttpbinError(`"${value}" is not valid base64: only the standard alphabet and trailing padding are allowed`);
|
|
61
|
+
}
|
|
62
|
+
const body = await hbText(`/base64/${encodeURIComponent(value)}`);
|
|
63
|
+
if (/^Incorrect Base64 data/i.test(body)) {
|
|
64
|
+
const hint = body.match(/try:\s*(\S+)/)?.[1];
|
|
65
|
+
throw new HttpbinError(`httpbin could not decode that value.${hint ? ` It suggested trying ${hint}.` : ""}`);
|
|
66
|
+
}
|
|
67
|
+
return `httpbin decoded ${value} to: ${body}`;
|
|
68
|
+
}
|
|
69
|
+
/** httpbin's /anything: the request it received, reflected back. */
|
|
70
|
+
export async function echoAnything(args) {
|
|
71
|
+
const path = (args.path ?? "").trim();
|
|
72
|
+
if (path && !/^\/[a-z0-9/_.-]*$/i.test(path))
|
|
73
|
+
throw new HttpbinError("Give a simple path such as /probe/check, with letters, digits, slash, underscore, dot or hyphen");
|
|
74
|
+
const url = `${HB}/anything${path}`;
|
|
75
|
+
const res = await fetch(url, {
|
|
76
|
+
headers: { "User-Agent": HB_UA, Accept: "application/json", "X-Probe-Tag": "muxC" },
|
|
77
|
+
signal: AbortSignal.timeout(20000),
|
|
78
|
+
});
|
|
79
|
+
if (!res.ok)
|
|
80
|
+
throw new HttpbinError(`httpbin returned ${res.status}`);
|
|
81
|
+
const d = (await res.json());
|
|
82
|
+
return [
|
|
83
|
+
`httpbin reflected ${d.method ?? "GET"} ${d.url ?? url}`,
|
|
84
|
+
Object.keys(d.args ?? {}).length ? `query: ${Object.entries(d.args ?? {}).map(([k, v]) => `${k}=${v}`).join(" | ")}` : "query: none",
|
|
85
|
+
`content type: ${d.headers?.["Content-Type"] ?? "none"} | user agent: ${d.headers?.["User-Agent"] ?? "not reported"}`,
|
|
86
|
+
`probe header echoed: ${d.headers?.["X-Probe-Tag"] ?? "no"}`,
|
|
87
|
+
d.json ? `json body: ${JSON.stringify(d.json)}` : d.data ? `body: ${d.data}` : "body: empty",
|
|
88
|
+
].join("\n");
|
|
89
|
+
}
|
|
90
|
+
/** httpbin's /status endpoint, which is the honest way to test non-2xx handling. */
|
|
91
|
+
export async function statusCheck(args) {
|
|
92
|
+
const code = args.code ?? 200;
|
|
93
|
+
if (!Number.isInteger(code) || code < 100 || code > 599)
|
|
94
|
+
throw new HttpbinError("Give an HTTP status code between 100 and 599");
|
|
95
|
+
const res = await fetch(`${HB}/status/${code}`, { headers: { "User-Agent": HB_UA }, signal: AbortSignal.timeout(20000) });
|
|
96
|
+
const body = (await res.text()).trim();
|
|
97
|
+
return `httpbin /status/${code} answered ${res.status} ${res.statusText}${body ? ` with body: ${body}` : " with an empty body"}.`;
|
|
98
|
+
}
|
package/dist/license.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// Premium tools on this server need a license key bought from MCP Marketplace.
|
|
2
|
+
// Buyers put the key in their MCP client config as MCP_LICENSE_KEY. Every tool
|
|
3
|
+
// that is not listed in PREMIUM keeps working without a key.
|
|
4
|
+
const SLUG = "httpbin-mcp";
|
|
5
|
+
// Tools that need a key. Everything else is free.
|
|
6
|
+
const PREMIUM = new Set([
|
|
7
|
+
"base64_decode",
|
|
8
|
+
"echo_anything",
|
|
9
|
+
"status_check",
|
|
10
|
+
]);
|
|
11
|
+
const BUY_URL = `https://mcp-marketplace.io/server/io-github-mrfentmen-${SLUG}`;
|
|
12
|
+
// The license check calls the marketplace's verify endpoint directly instead of
|
|
13
|
+
// using @mcp_marketplace/license. That SDK sends no `apikey` header, so every
|
|
14
|
+
// check it makes is rejected by Supabase before it reaches the function. The
|
|
15
|
+
// publishable key below is public by design - it ships in mcp-marketplace.io's
|
|
16
|
+
// own JavaScript and only ever reaches their licence check.
|
|
17
|
+
const DEFAULT_VERIFY_URL = "https://virupvwhtkpkjsiskckg.supabase.co/functions/v1/verify-key";
|
|
18
|
+
const PUBLISHABLE_KEY = "sb_publishable_BuqlW96Ke8C_zzJG-LQv1Q_YHi_r_4h";
|
|
19
|
+
const OK_CACHE_MS = 60 * 60 * 1000;
|
|
20
|
+
const BAD_CACHE_MS = 60 * 1000;
|
|
21
|
+
const seen = new Map();
|
|
22
|
+
const REASONS = {
|
|
23
|
+
missing_key: "no key is set",
|
|
24
|
+
invalid_format: "that key is not a valid MCP Marketplace key",
|
|
25
|
+
not_found: "that key was not found",
|
|
26
|
+
revoked: "that key has been revoked",
|
|
27
|
+
rotated: "that key was rotated, use your new one",
|
|
28
|
+
expired: "that key has expired, renew it",
|
|
29
|
+
rate_limited: "there were too many checks just now, try again shortly",
|
|
30
|
+
network_error: "the license server could not be reached",
|
|
31
|
+
};
|
|
32
|
+
function blocked(tool, reason) {
|
|
33
|
+
const why = REASONS[reason] ?? `the license server answered "${reason}"`;
|
|
34
|
+
return `"${tool}" needs a license key, but ${why}. ` +
|
|
35
|
+
`Set MCP_LICENSE_KEY in your MCP client config. Get a key: ${BUY_URL}`;
|
|
36
|
+
}
|
|
37
|
+
async function verify(key) {
|
|
38
|
+
const res = await fetch(process.env.MCP_LICENSE_VERIFY_URL || DEFAULT_VERIFY_URL, {
|
|
39
|
+
method: "POST",
|
|
40
|
+
headers: {
|
|
41
|
+
apikey: PUBLISHABLE_KEY,
|
|
42
|
+
Authorization: `Bearer ${PUBLISHABLE_KEY}`,
|
|
43
|
+
"Content-Type": "application/json",
|
|
44
|
+
},
|
|
45
|
+
body: JSON.stringify({ key, slug: SLUG }),
|
|
46
|
+
// an unusable key answers 400 with a JSON body, so read the body either way
|
|
47
|
+
signal: AbortSignal.timeout(15000),
|
|
48
|
+
});
|
|
49
|
+
const data = (await res.json());
|
|
50
|
+
if (typeof data?.valid !== "boolean")
|
|
51
|
+
return { valid: false, reason: "unexpected_response" };
|
|
52
|
+
return data;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Returns null when the caller may run the tool, or a short message telling
|
|
56
|
+
* them how to get a key.
|
|
57
|
+
*
|
|
58
|
+
* A good key is remembered for an hour, so a busy session does not hit the
|
|
59
|
+
* license server on every call and keeps working through a brief outage.
|
|
60
|
+
*/
|
|
61
|
+
export async function premiumRequired(tool) {
|
|
62
|
+
if (!PREMIUM.has(tool))
|
|
63
|
+
return null;
|
|
64
|
+
const key = process.env.MCP_LICENSE_KEY;
|
|
65
|
+
if (!key)
|
|
66
|
+
return blocked(tool, "missing_key");
|
|
67
|
+
const hit = seen.get(key);
|
|
68
|
+
if (hit && Date.now() - hit.at < (hit.valid ? OK_CACHE_MS : BAD_CACHE_MS)) {
|
|
69
|
+
return hit.valid ? null : blocked(tool, hit.reason ?? "invalid");
|
|
70
|
+
}
|
|
71
|
+
let result;
|
|
72
|
+
try {
|
|
73
|
+
result = await verify(key);
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
result = { valid: false, reason: "network_error" };
|
|
77
|
+
}
|
|
78
|
+
seen.set(key, { ...result, at: Date.now() });
|
|
79
|
+
return result.valid ? null : blocked(tool, result.reason ?? "invalid");
|
|
80
|
+
}
|
package/dist/server.js
CHANGED
|
@@ -2,7 +2,8 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { get } from "./api.js";
|
|
4
4
|
import { headers } from "./api.js";
|
|
5
|
-
import { ip } from "./api.js";
|
|
5
|
+
import { ip, base64Decode, echoAnything, statusCheck } from "./api.js";
|
|
6
|
+
import { premiumRequired } from "./license.js";
|
|
6
7
|
const text = (value) => ({ content: [{ type: "text", text: value }] });
|
|
7
8
|
const textError = (t) => ({ content: [{ type: "text", text: t }], isError: true });
|
|
8
9
|
const READ_ONLY = { readOnlyHint: true, openWorldHint: true };
|
|
@@ -48,5 +49,59 @@ export function createServer() {
|
|
|
48
49
|
return textError(error(e));
|
|
49
50
|
}
|
|
50
51
|
});
|
|
52
|
+
server.registerTool("base64_decode", {
|
|
53
|
+
title: "Base64 decode",
|
|
54
|
+
description: "Decode base64 through httpbin, surfacing the server's own correction hint when the input is not decodable.",
|
|
55
|
+
inputSchema: z.object({ value: z.string().describe("Base64 text to decode."), }),
|
|
56
|
+
annotations: READ_ONLY,
|
|
57
|
+
}, async (args) => {
|
|
58
|
+
// ---- paywall: base64_decode ----
|
|
59
|
+
const paywallMessage = await premiumRequired("base64_decode");
|
|
60
|
+
if (paywallMessage)
|
|
61
|
+
return { content: [{ type: "text", text: paywallMessage }], isError: true };
|
|
62
|
+
// ---- paywall: end ----
|
|
63
|
+
try {
|
|
64
|
+
return text(await base64Decode(args));
|
|
65
|
+
}
|
|
66
|
+
catch (e) {
|
|
67
|
+
return textError(error(e));
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
server.registerTool("echo_anything", {
|
|
71
|
+
title: "Echo anything",
|
|
72
|
+
description: "Send a request to httpbin's /anything and get the full request reflected back, which shows exactly what your client put on the wire.",
|
|
73
|
+
inputSchema: z.object({ path: z.string().describe("Optional extra path, e.g. /probe/check.").optional() }),
|
|
74
|
+
annotations: READ_ONLY,
|
|
75
|
+
}, async (args) => {
|
|
76
|
+
// ---- paywall: echo_anything ----
|
|
77
|
+
const paywallMessage = await premiumRequired("echo_anything");
|
|
78
|
+
if (paywallMessage)
|
|
79
|
+
return { content: [{ type: "text", text: paywallMessage }], isError: true };
|
|
80
|
+
// ---- paywall: end ----
|
|
81
|
+
try {
|
|
82
|
+
return text(await echoAnything(args));
|
|
83
|
+
}
|
|
84
|
+
catch (e) {
|
|
85
|
+
return textError(error(e));
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
server.registerTool("status_check", {
|
|
89
|
+
title: "Status check",
|
|
90
|
+
description: "Ask httpbin for a specific HTTP status code, so a client's handling of errors and redirects can be tested deliberately.",
|
|
91
|
+
inputSchema: z.object({ code: z.number().describe("HTTP status code, 100-599.").optional() }),
|
|
92
|
+
annotations: READ_ONLY,
|
|
93
|
+
}, async (args) => {
|
|
94
|
+
// ---- paywall: status_check ----
|
|
95
|
+
const paywallMessage = await premiumRequired("status_check");
|
|
96
|
+
if (paywallMessage)
|
|
97
|
+
return { content: [{ type: "text", text: paywallMessage }], isError: true };
|
|
98
|
+
// ---- paywall: end ----
|
|
99
|
+
try {
|
|
100
|
+
return text(await statusCheck(args));
|
|
101
|
+
}
|
|
102
|
+
catch (e) {
|
|
103
|
+
return textError(error(e));
|
|
104
|
+
}
|
|
105
|
+
});
|
|
51
106
|
return server;
|
|
52
107
|
}
|
package/package.json
CHANGED