@uniquedomains/mcp-server 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +248 -2
- package/dist/chunk-7RVJJYFN.js +22404 -0
- package/dist/chunk-ZBIZ6H5V.js +150 -0
- package/dist/http.js +14 -0
- package/dist/index.js +70 -0
- package/dist/stdio.js +31 -0
- package/package.json +64 -4
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ConfigError,
|
|
3
|
+
DRAIN_LIMIT_BYTES,
|
|
4
|
+
HTTP_BODY_LIMIT_BYTES,
|
|
5
|
+
SERVER_VERSION,
|
|
6
|
+
createMcpServer,
|
|
7
|
+
prepareServer,
|
|
8
|
+
readConfig
|
|
9
|
+
} from "./chunk-7RVJJYFN.js";
|
|
10
|
+
|
|
11
|
+
// src/httpApp.ts
|
|
12
|
+
import { createServer as createHttpServer } from "http";
|
|
13
|
+
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
14
|
+
var readWellKnownFiles = (env) => {
|
|
15
|
+
const raw = env.UD_WELLKNOWN_FILES?.trim();
|
|
16
|
+
const files = /* @__PURE__ */ new Map();
|
|
17
|
+
if (!raw) return files;
|
|
18
|
+
let parsed;
|
|
19
|
+
try {
|
|
20
|
+
parsed = JSON.parse(raw);
|
|
21
|
+
} catch {
|
|
22
|
+
throw new ConfigError("UD_WELLKNOWN_FILES must be a JSON object.");
|
|
23
|
+
}
|
|
24
|
+
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) throw new ConfigError("UD_WELLKNOWN_FILES must be a JSON object.");
|
|
25
|
+
for (const [key, value] of Object.entries(parsed)) {
|
|
26
|
+
const name = key.replace(/^\/?(\.well-known\/)?/u, "");
|
|
27
|
+
if (!/^[A-Za-z0-9._-]+$/u.test(name)) throw new ConfigError(`UD_WELLKNOWN_FILES: "${key}" is not a file name.`);
|
|
28
|
+
if (typeof value === "string") {
|
|
29
|
+
files.set(name, { body: value, contentType: name.endsWith(".json") ? "application/json" : "text/plain; charset=utf-8" });
|
|
30
|
+
} else if (value !== null && typeof value === "object" && typeof value.body === "string") {
|
|
31
|
+
files.set(name, { body: value.body, contentType: typeof value.contentType === "string" ? value.contentType : "text/plain; charset=utf-8" });
|
|
32
|
+
} else {
|
|
33
|
+
throw new ConfigError(`UD_WELLKNOWN_FILES: "${key}" must be a string or { "body": string, "contentType"?: string }.`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return files;
|
|
37
|
+
};
|
|
38
|
+
var CORS_HEADERS = {
|
|
39
|
+
"Access-Control-Allow-Origin": "*",
|
|
40
|
+
"Access-Control-Allow-Methods": "POST, GET, DELETE, OPTIONS",
|
|
41
|
+
"Access-Control-Allow-Headers": "Content-Type, Accept, Mcp-Protocol-Version, Mcp-Session-Id, Last-Event-ID",
|
|
42
|
+
"Access-Control-Expose-Headers": "Mcp-Session-Id, Mcp-Protocol-Version",
|
|
43
|
+
"Access-Control-Max-Age": "86400"
|
|
44
|
+
};
|
|
45
|
+
var send = (res, status, body, contentType, extra = {}) => {
|
|
46
|
+
res.writeHead(status, { "Content-Type": contentType, "Cache-Control": "no-store", "X-Content-Type-Options": "nosniff", ...extra });
|
|
47
|
+
res.end(body);
|
|
48
|
+
};
|
|
49
|
+
var sendJsonRpcError = (res, status, code, message, extra = {}) => {
|
|
50
|
+
send(res, status, JSON.stringify({ jsonrpc: "2.0", error: { code, message }, id: null }), "application/json", { ...CORS_HEADERS, ...extra });
|
|
51
|
+
};
|
|
52
|
+
var BodyTooLargeError = class extends Error {
|
|
53
|
+
};
|
|
54
|
+
var readBody = (req, limit) => new Promise((resolve, reject) => {
|
|
55
|
+
const declared = Number(req.headers["content-length"]);
|
|
56
|
+
if (Number.isFinite(declared) && declared > DRAIN_LIMIT_BYTES) {
|
|
57
|
+
req.destroy();
|
|
58
|
+
reject(new BodyTooLargeError());
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const chunks = [];
|
|
62
|
+
let size = 0;
|
|
63
|
+
req.on("data", (chunk) => {
|
|
64
|
+
size += chunk.length;
|
|
65
|
+
if (size > DRAIN_LIMIT_BYTES) {
|
|
66
|
+
req.destroy();
|
|
67
|
+
reject(new BodyTooLargeError());
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (size > limit) chunks.length = 0;
|
|
71
|
+
else chunks.push(chunk);
|
|
72
|
+
});
|
|
73
|
+
req.on("end", () => size > limit ? reject(new BodyTooLargeError()) : resolve(Buffer.concat(chunks).toString("utf8")));
|
|
74
|
+
req.on("error", reject);
|
|
75
|
+
});
|
|
76
|
+
var handleMcpPost = async (prepared, req, res) => {
|
|
77
|
+
let parsed;
|
|
78
|
+
try {
|
|
79
|
+
const body = await readBody(req, HTTP_BODY_LIMIT_BYTES);
|
|
80
|
+
parsed = JSON.parse(body);
|
|
81
|
+
} catch (error) {
|
|
82
|
+
if (error instanceof BodyTooLargeError) sendJsonRpcError(res, 413, -32600, "The request body is over 1 MB.", { Connection: "close" });
|
|
83
|
+
else sendJsonRpcError(res, 400, -32700, "The request body is not JSON.");
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const server = createMcpServer(prepared);
|
|
87
|
+
const transport = new StreamableHTTPServerTransport({ sessionIdGenerator: void 0, enableJsonResponse: true });
|
|
88
|
+
res.on("close", () => {
|
|
89
|
+
void transport.close();
|
|
90
|
+
void server.close();
|
|
91
|
+
});
|
|
92
|
+
for (const [name, value] of Object.entries(CORS_HEADERS)) res.setHeader(name, value);
|
|
93
|
+
res.setHeader("Cache-Control", "no-store");
|
|
94
|
+
await server.connect(transport);
|
|
95
|
+
await transport.handleRequest(req, res, parsed);
|
|
96
|
+
};
|
|
97
|
+
var createRequestHandler = (prepared, options) => async (req, res) => {
|
|
98
|
+
const url = new URL(req.url ?? "/", "http://localhost");
|
|
99
|
+
const path = url.pathname.replace(/\/+$/u, "") || "/";
|
|
100
|
+
try {
|
|
101
|
+
if (path === "/mcp") {
|
|
102
|
+
if (req.method === "OPTIONS") return send(res, 204, "", "text/plain", CORS_HEADERS);
|
|
103
|
+
if (req.method === "POST") return await handleMcpPost(prepared, req, res);
|
|
104
|
+
return sendJsonRpcError(res, 405, -32e3, "This server is stateless: send JSON-RPC requests with POST.", { Allow: "POST, OPTIONS" });
|
|
105
|
+
}
|
|
106
|
+
if (req.method !== "GET" && req.method !== "HEAD") return send(res, 405, "Method not allowed.\n", "text/plain; charset=utf-8", { Allow: "GET" });
|
|
107
|
+
if (path === "/healthz") {
|
|
108
|
+
return send(res, 200, JSON.stringify({ ok: true, version: SERVER_VERSION, tools: prepared.tools.length }), "application/json");
|
|
109
|
+
}
|
|
110
|
+
if (path.startsWith("/.well-known/")) {
|
|
111
|
+
const file = options.wellKnown.get(path.slice("/.well-known/".length));
|
|
112
|
+
if (file) return send(res, 200, file.body, file.contentType, { "Access-Control-Allow-Origin": "*" });
|
|
113
|
+
return send(res, 404, "Not found.\n", "text/plain; charset=utf-8");
|
|
114
|
+
}
|
|
115
|
+
if (path === "/") {
|
|
116
|
+
return send(res, 200, "Unique Domains MCP server. Connect an MCP client to /mcp. Documentation: https://github.com/UniqueDomains/mcp-server\n", "text/plain; charset=utf-8");
|
|
117
|
+
}
|
|
118
|
+
return send(res, 404, "Not found.\n", "text/plain; charset=utf-8");
|
|
119
|
+
} catch (error) {
|
|
120
|
+
process.stderr.write(`${error instanceof Error ? error.stack ?? error.message : String(error)}
|
|
121
|
+
`);
|
|
122
|
+
if (!res.headersSent) sendJsonRpcError(res, 500, -32603, "The server could not answer. Try again in a minute.");
|
|
123
|
+
else res.end();
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
var startHttpServer = async (env = process.env) => {
|
|
127
|
+
const config = readConfig(env);
|
|
128
|
+
const wellKnown = readWellKnownFiles(env);
|
|
129
|
+
const prepared = await prepareServer(config);
|
|
130
|
+
const port = Number(env.PORT ?? 8080);
|
|
131
|
+
const http = createHttpServer((req, res) => void createRequestHandler(prepared, { wellKnown })(req, res));
|
|
132
|
+
http.listen(port, () => {
|
|
133
|
+
process.stdout.write(
|
|
134
|
+
`uniquedomains-mcp-server ${SERVER_VERSION} on :${port}, ${config.profile} profile, ${prepared.tools.length} tools, connector secret ${config.connectorSecret ? "set" : "not set"}, ${wellKnown.size} well-known files.
|
|
135
|
+
`
|
|
136
|
+
);
|
|
137
|
+
});
|
|
138
|
+
const stop = () => {
|
|
139
|
+
http.close(() => process.exit(0));
|
|
140
|
+
setTimeout(() => process.exit(0), 5e3).unref();
|
|
141
|
+
};
|
|
142
|
+
process.on("SIGTERM", stop);
|
|
143
|
+
process.on("SIGINT", stop);
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
export {
|
|
147
|
+
readWellKnownFiles,
|
|
148
|
+
createRequestHandler,
|
|
149
|
+
startHttpServer
|
|
150
|
+
};
|
package/dist/http.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
startHttpServer
|
|
4
|
+
} from "./chunk-ZBIZ6H5V.js";
|
|
5
|
+
import {
|
|
6
|
+
ConfigError
|
|
7
|
+
} from "./chunk-7RVJJYFN.js";
|
|
8
|
+
|
|
9
|
+
// src/transports/http.ts
|
|
10
|
+
startHttpServer().catch((error) => {
|
|
11
|
+
process.stderr.write(`${error instanceof ConfigError ? error.message : error instanceof Error ? error.stack ?? error.message : String(error)}
|
|
12
|
+
`);
|
|
13
|
+
process.exit(1);
|
|
14
|
+
});
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createRequestHandler,
|
|
3
|
+
readWellKnownFiles,
|
|
4
|
+
startHttpServer
|
|
5
|
+
} from "./chunk-ZBIZ6H5V.js";
|
|
6
|
+
import {
|
|
7
|
+
ConfigError,
|
|
8
|
+
DETAILS_RULES,
|
|
9
|
+
DETAILS_SAMPLES,
|
|
10
|
+
INSTRUCTIONS,
|
|
11
|
+
InputError,
|
|
12
|
+
SERVER_NAME,
|
|
13
|
+
SERVER_VERSION,
|
|
14
|
+
TOOLS,
|
|
15
|
+
TOOLS_DOCUMENT_VERSION,
|
|
16
|
+
TOOLS_SDK_VERSION,
|
|
17
|
+
WEBSITE,
|
|
18
|
+
createApiClient,
|
|
19
|
+
createMcpServer,
|
|
20
|
+
detailsFor,
|
|
21
|
+
isObject,
|
|
22
|
+
outputSchemaFor,
|
|
23
|
+
prepareServer,
|
|
24
|
+
readConfig,
|
|
25
|
+
readKeyPlan,
|
|
26
|
+
readProfile,
|
|
27
|
+
refusalText,
|
|
28
|
+
registrarSlug,
|
|
29
|
+
resetPhrase,
|
|
30
|
+
runTool,
|
|
31
|
+
selectTools,
|
|
32
|
+
shapeAnswer,
|
|
33
|
+
splitInput,
|
|
34
|
+
textLine,
|
|
35
|
+
toListedTool
|
|
36
|
+
} from "./chunk-7RVJJYFN.js";
|
|
37
|
+
export {
|
|
38
|
+
ConfigError,
|
|
39
|
+
DETAILS_RULES,
|
|
40
|
+
DETAILS_SAMPLES,
|
|
41
|
+
INSTRUCTIONS,
|
|
42
|
+
InputError,
|
|
43
|
+
SERVER_NAME,
|
|
44
|
+
SERVER_VERSION,
|
|
45
|
+
TOOLS,
|
|
46
|
+
TOOLS_DOCUMENT_VERSION,
|
|
47
|
+
TOOLS_SDK_VERSION,
|
|
48
|
+
WEBSITE,
|
|
49
|
+
createApiClient,
|
|
50
|
+
createMcpServer,
|
|
51
|
+
createRequestHandler,
|
|
52
|
+
detailsFor,
|
|
53
|
+
isObject,
|
|
54
|
+
outputSchemaFor,
|
|
55
|
+
prepareServer,
|
|
56
|
+
readConfig,
|
|
57
|
+
readKeyPlan,
|
|
58
|
+
readProfile,
|
|
59
|
+
readWellKnownFiles,
|
|
60
|
+
refusalText,
|
|
61
|
+
registrarSlug,
|
|
62
|
+
resetPhrase,
|
|
63
|
+
runTool,
|
|
64
|
+
selectTools,
|
|
65
|
+
shapeAnswer,
|
|
66
|
+
splitInput,
|
|
67
|
+
startHttpServer,
|
|
68
|
+
textLine,
|
|
69
|
+
toListedTool
|
|
70
|
+
};
|
package/dist/stdio.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
ConfigError,
|
|
4
|
+
SERVER_VERSION,
|
|
5
|
+
createMcpServer,
|
|
6
|
+
prepareServer,
|
|
7
|
+
readConfig
|
|
8
|
+
} from "./chunk-7RVJJYFN.js";
|
|
9
|
+
|
|
10
|
+
// src/transports/stdio.ts
|
|
11
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
12
|
+
var log = (line) => {
|
|
13
|
+
process.stderr.write(`[uniquedomains-mcp-server] ${line}
|
|
14
|
+
`);
|
|
15
|
+
};
|
|
16
|
+
var main = async () => {
|
|
17
|
+
if (process.argv.includes("--version")) {
|
|
18
|
+
process.stdout.write(`${SERVER_VERSION}
|
|
19
|
+
`);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const config = readConfig(process.env);
|
|
23
|
+
const prepared = await prepareServer(config, { log });
|
|
24
|
+
const server = createMcpServer(prepared);
|
|
25
|
+
await server.connect(new StdioServerTransport());
|
|
26
|
+
log(`${SERVER_VERSION} ready: ${prepared.tools.length} tools, ${config.profile} profile${prepared.plan !== "none" ? `, ${prepared.plan} key` : ""}.`);
|
|
27
|
+
};
|
|
28
|
+
main().catch((error) => {
|
|
29
|
+
log(error instanceof ConfigError ? error.message : error instanceof Error ? error.stack ?? error.message : String(error));
|
|
30
|
+
process.exit(1);
|
|
31
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,66 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniquedomains/mcp-server",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "MCP server for the Unique Domains API: domain names, words, TLDs, registrar prices, the domain market, trends and the agenda.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Unique Domains (https://unique.domains)",
|
|
7
|
+
"homepage": "https://unique.domains/api",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/UniqueDomains/mcp-server.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": "https://github.com/UniqueDomains/mcp-server/issues",
|
|
13
|
+
"mcpName": "domains.unique/mcp-server",
|
|
14
|
+
"keywords": [
|
|
15
|
+
"mcp",
|
|
16
|
+
"mcp-server",
|
|
17
|
+
"model-context-protocol",
|
|
18
|
+
"domain-names",
|
|
19
|
+
"domains",
|
|
20
|
+
"whois",
|
|
21
|
+
"tld",
|
|
22
|
+
"registrar",
|
|
23
|
+
"unique-domains"
|
|
24
|
+
],
|
|
25
|
+
"type": "module",
|
|
26
|
+
"bin": {
|
|
27
|
+
"uniquedomains-mcp-server": "dist/stdio.js"
|
|
28
|
+
},
|
|
29
|
+
"exports": {
|
|
30
|
+
".": "./dist/index.js",
|
|
31
|
+
"./package.json": "./package.json"
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"dist/*.js",
|
|
35
|
+
"README.md",
|
|
36
|
+
"LICENSE"
|
|
37
|
+
],
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=20"
|
|
40
|
+
},
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"generate": "node scripts/generate.mjs",
|
|
46
|
+
"build": "tsup",
|
|
47
|
+
"typecheck": "tsc --noEmit",
|
|
48
|
+
"test": "node --test test/*.test.mjs",
|
|
49
|
+
"check:text": "node scripts/check-text.mjs",
|
|
50
|
+
"plugin": "node scripts/plugin-manifest.mjs",
|
|
51
|
+
"plugin:test": "node scripts/plugin-manifest.mjs --allow-placeholder",
|
|
52
|
+
"smoke": "node scripts/smoke.mjs",
|
|
53
|
+
"prepack": "npm run build"
|
|
54
|
+
},
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"@modelcontextprotocol/sdk": "^1.32.2",
|
|
57
|
+
"@uniquedomains/sdk": "^0.1.0"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@types/node": "22.20.5",
|
|
61
|
+
"ajv": "8.20.0",
|
|
62
|
+
"ajv-formats": "3.0.1",
|
|
63
|
+
"tsup": "8.5.1",
|
|
64
|
+
"typescript": "5.9.3"
|
|
65
|
+
}
|
|
66
|
+
}
|