@open-mena-mcp/cli 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 +48 -2
- package/dist/args.d.ts +14 -0
- package/dist/args.js +66 -0
- package/dist/args.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +71 -0
- package/dist/index.js.map +1 -0
- package/dist/prompts.d.ts +10 -0
- package/dist/prompts.js +56 -0
- package/dist/prompts.js.map +1 -0
- package/dist/scaffold.d.ts +8 -0
- package/dist/scaffold.js +33 -0
- package/dist/scaffold.js.map +1 -0
- package/dist/templates.d.ts +20 -0
- package/dist/templates.js +323 -0
- package/dist/templates.js.map +1 -0
- package/dist/validate.d.ts +10 -0
- package/dist/validate.js +25 -0
- package/dist/validate.js.map +1 -0
- package/package.json +40 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Dinaelsayed99
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,49 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @open-mena-mcp/cli
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Interactive scaffolder for the open-mena-mcp monorepo. Generates a runnable TypeScript MCP server package (official `@modelcontextprotocol/sdk` over stdio, Zod input schema, vitest suite with mocked HTTP, README) under `packages/<name>`.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
From the repo root:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm install
|
|
11
|
+
pnpm build
|
|
12
|
+
pnpm new-server my-server
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
`pnpm new-server` walks you through the name, description, example tool name and author. Non-interactive use (CI, scripts):
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pnpm new-server my-server --description "My server" --tool my_server_lookup --author "you" --yes
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Flags: `--name/-n`, `--description/-d`, `--tool/-t`, `--author/-a`, `--dir`, `--yes/-y`, `--help/-h`.
|
|
22
|
+
|
|
23
|
+
## What it generates
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
packages/<name>/
|
|
27
|
+
├── package.json # @open-mena-mcp/<name>, deps: @modelcontextprotocol/sdk + zod
|
|
28
|
+
├── tsconfig.json # extends ../../tsconfig.base.json (strict)
|
|
29
|
+
├── tsconfig.build.json
|
|
30
|
+
├── vitest.config.ts
|
|
31
|
+
├── README.md
|
|
32
|
+
└── src/
|
|
33
|
+
├── index.ts # stdio entrypoint
|
|
34
|
+
├── server.ts # McpServer + Zod schema + example tool
|
|
35
|
+
├── client.ts # HTTP client (mockable fetch)
|
|
36
|
+
└── server.test.ts # vitest, mocked HTTP, no API keys needed
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Develop
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pnpm --filter @open-mena-mcp/cli build
|
|
43
|
+
pnpm --filter @open-mena-mcp/cli test
|
|
44
|
+
pnpm --filter @open-mena-mcp/cli lint
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## License
|
|
48
|
+
|
|
49
|
+
MIT
|
package/dist/args.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface CliArgs {
|
|
2
|
+
name?: string;
|
|
3
|
+
description?: string;
|
|
4
|
+
tool?: string;
|
|
5
|
+
author?: string;
|
|
6
|
+
dir?: string;
|
|
7
|
+
yes: boolean;
|
|
8
|
+
help: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare class ArgError extends Error {
|
|
11
|
+
}
|
|
12
|
+
/** Parses argv (already sliced past node + script). The first bare token is the server name. */
|
|
13
|
+
export declare function parseArgs(argv: string[]): CliArgs;
|
|
14
|
+
export declare function usage(): string;
|
package/dist/args.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
const VALUE_FLAGS = {
|
|
2
|
+
"--name": "name",
|
|
3
|
+
"-n": "name",
|
|
4
|
+
"--description": "description",
|
|
5
|
+
"-d": "description",
|
|
6
|
+
"--tool": "tool",
|
|
7
|
+
"-t": "tool",
|
|
8
|
+
"--author": "author",
|
|
9
|
+
"-a": "author",
|
|
10
|
+
"--dir": "dir",
|
|
11
|
+
};
|
|
12
|
+
export class ArgError extends Error {
|
|
13
|
+
}
|
|
14
|
+
/** Parses argv (already sliced past node + script). The first bare token is the server name. */
|
|
15
|
+
export function parseArgs(argv) {
|
|
16
|
+
const result = { yes: false, help: false };
|
|
17
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
18
|
+
const token = argv[i];
|
|
19
|
+
if (token === undefined)
|
|
20
|
+
break;
|
|
21
|
+
if (token === "--yes" || token === "-y") {
|
|
22
|
+
result.yes = true;
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
if (token === "--help" || token === "-h") {
|
|
26
|
+
result.help = true;
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
const key = VALUE_FLAGS[token];
|
|
30
|
+
if (key !== undefined) {
|
|
31
|
+
const value = argv[i + 1];
|
|
32
|
+
if (value === undefined || value.startsWith("-")) {
|
|
33
|
+
throw new ArgError("flag " + token + " expects a value");
|
|
34
|
+
}
|
|
35
|
+
result[key] = value;
|
|
36
|
+
i += 1;
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
if (token.startsWith("-")) {
|
|
40
|
+
throw new ArgError("unknown flag: " + token);
|
|
41
|
+
}
|
|
42
|
+
if (result.name !== undefined) {
|
|
43
|
+
throw new ArgError("unexpected extra argument: " + token);
|
|
44
|
+
}
|
|
45
|
+
result.name = token;
|
|
46
|
+
}
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
49
|
+
export function usage() {
|
|
50
|
+
return [
|
|
51
|
+
"Usage: pnpm new-server <name> [options]",
|
|
52
|
+
"",
|
|
53
|
+
"Creates a runnable TypeScript MCP server package under packages/<name>.",
|
|
54
|
+
"",
|
|
55
|
+
"Options:",
|
|
56
|
+
" -n, --name <slug> Server name (kebab-case), e.g. arabic-tools",
|
|
57
|
+
" -d, --description <text> One-line description of the server",
|
|
58
|
+
" -t, --tool <name> Example tool name (snake_case)",
|
|
59
|
+
" -a, --author <name> Author recorded in package.json",
|
|
60
|
+
" --dir <path> Target directory (default: packages/<name>)",
|
|
61
|
+
" -y, --yes Accept defaults for anything not provided (no prompts)",
|
|
62
|
+
" -h, --help Show this help",
|
|
63
|
+
"",
|
|
64
|
+
].join("\n");
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=args.js.map
|
package/dist/args.js.map
ADDED
|
@@ -0,0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gBACjD,MAAM,IAAI,QAAQ,CAAC,OAAO,GAAG,KAAK,GAAG,kBAAkB,CAAC,CAAC;YAC3D,CAAC;YACD,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;YACpB,CAAC,IAAI,CAAC,CAAC;YACP,SAAS;QACX,CAAC;QACD,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YAC1B,MAAM,IAAI,QAAQ,CAAC,gBAAgB,GAAG,KAAK,CAAC,CAAC;QAC/C,CAAC;QACD,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;YAC9B,MAAM,IAAI,QAAQ,CAAC,6BAA6B,GAAG,KAAK,CAAC,CAAC;QAC5D,CAAC;QACD,MAAM,CAAC,IAAI,GAAG,KAAK,CAAC;IACtB,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,KAAK;IACnB,OAAO;QACL,yCAAyC;QACzC,EAAE;QACF,yEAAyE;QACzE,EAAE;QACF,UAAU;QACV,yEAAyE;QACzE,gEAAgE;QAChE,4DAA4D;QAC5D,6DAA6D;QAC7D,yEAAyE;QACzE,oFAAoF;QACpF,4CAA4C;QAC5C,EAAE;KACH,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { ArgError, parseArgs, usage } from "./args.js";
|
|
5
|
+
import { CancelledError, resolveOptions } from "./prompts.js";
|
|
6
|
+
import { scaffoldServer } from "./scaffold.js";
|
|
7
|
+
import { validateName } from "./validate.js";
|
|
8
|
+
import { scopedName } from "./templates.js";
|
|
9
|
+
function findWorkspaceRoot(startDir) {
|
|
10
|
+
let dir = path.resolve(startDir);
|
|
11
|
+
for (;;) {
|
|
12
|
+
if (existsSync(path.join(dir, "pnpm-workspace.yaml"))) {
|
|
13
|
+
return dir;
|
|
14
|
+
}
|
|
15
|
+
const parent = path.dirname(dir);
|
|
16
|
+
if (parent === dir) {
|
|
17
|
+
return path.resolve(startDir);
|
|
18
|
+
}
|
|
19
|
+
dir = parent;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
async function main() {
|
|
23
|
+
const args = parseArgs(process.argv.slice(2));
|
|
24
|
+
if (args.help) {
|
|
25
|
+
console.log(usage());
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (args.name !== undefined) {
|
|
29
|
+
const validation = validateName(args.name);
|
|
30
|
+
if (!validation.ok) {
|
|
31
|
+
console.error("Invalid server name: " + validation.reason);
|
|
32
|
+
process.exitCode = 1;
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const interactive = process.stdin.isTTY;
|
|
37
|
+
const options = await resolveOptions(args, interactive);
|
|
38
|
+
// pnpm runs package scripts with cwd inside the package, so anchor the
|
|
39
|
+
// default target at the workspace root (pnpm-workspace.yaml), falling back
|
|
40
|
+
// to the directory the command was invoked from.
|
|
41
|
+
const invokedFrom = process.env.INIT_CWD ?? process.cwd();
|
|
42
|
+
const workspaceRoot = findWorkspaceRoot(invokedFrom);
|
|
43
|
+
const targetDir = args.dir !== undefined
|
|
44
|
+
? path.resolve(invokedFrom, args.dir)
|
|
45
|
+
: path.join(workspaceRoot, "packages", options.name);
|
|
46
|
+
const result = await scaffoldServer(options, targetDir);
|
|
47
|
+
console.log("");
|
|
48
|
+
console.log("Created " + scopedName(options.name) + " in " + result.targetDir);
|
|
49
|
+
for (const file of result.files) {
|
|
50
|
+
console.log(" " + file);
|
|
51
|
+
}
|
|
52
|
+
console.log("");
|
|
53
|
+
console.log("Next steps:");
|
|
54
|
+
console.log(" pnpm install");
|
|
55
|
+
console.log(" pnpm --filter " + scopedName(options.name) + " test");
|
|
56
|
+
console.log(" pnpm --filter " + scopedName(options.name) + " build");
|
|
57
|
+
console.log("");
|
|
58
|
+
console.log("Then replace the example tool in src/server.ts with your real API calls.");
|
|
59
|
+
}
|
|
60
|
+
main().catch((error) => {
|
|
61
|
+
if (error instanceof ArgError || error instanceof CancelledError) {
|
|
62
|
+
console.error(error.message);
|
|
63
|
+
console.error("");
|
|
64
|
+
console.error(usage());
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
68
|
+
}
|
|
69
|
+
process.exitCode = 1;
|
|
70
|
+
});
|
|
71
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,SAAS,iBAAiB,CAAC,QAAgB;IACzC,IAAI,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACjC,SAAS,CAAC;QACR,IAAI,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,qBAAqB,CAAC,CAAC,EAAE,CAAC;YACtD,OAAO,GAAG,CAAC;QACb,CAAC;QACD,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACjC,IAAI,MAAM,KAAK,GAAG,EAAE,CAAC;YACnB,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,C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AC,KAAK,CAAC,CAAC,CAAC;IACxE,CAAC;IACD,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;AACvB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { CliArgs } from "./args.js";
|
|
2
|
+
import type { ServerTemplateOptions } from "./templates.js";
|
|
3
|
+
export declare class CancelledError extends Error {
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Resolves the final template options, prompting interactively for anything
|
|
7
|
+
* still missing. When --yes is passed or stdin is not a TTY, defaults are used
|
|
8
|
+
* and a missing name is an error.
|
|
9
|
+
*/
|
|
10
|
+
export declare function resolveOptions(args: CliArgs, interactive: boolean): Promise<ServerTemplateOptions>;
|
package/dist/prompts.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { createInterface } from "node:readline/promises";
|
|
2
|
+
import { defaultToolName, validateName } from "./validate.js";
|
|
3
|
+
export class CancelledError extends Error {
|
|
4
|
+
}
|
|
5
|
+
async function ask(rl, label, fallback) {
|
|
6
|
+
const suffix = fallback !== undefined && fallback.length > 0 ? " [" + fallback + "]" : "";
|
|
7
|
+
const answer = (await rl.question(label + suffix + ": ")).trim();
|
|
8
|
+
if (answer.length > 0)
|
|
9
|
+
return answer;
|
|
10
|
+
if (fallback !== undefined)
|
|
11
|
+
return fallback;
|
|
12
|
+
return "";
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Resolves the final template options, prompting interactively for anything
|
|
16
|
+
* still missing. When --yes is passed or stdin is not a TTY, defaults are used
|
|
17
|
+
* and a missing name is an error.
|
|
18
|
+
*/
|
|
19
|
+
export async function resolveOptions(args, interactive) {
|
|
20
|
+
if (!interactive || args.yes) {
|
|
21
|
+
if (args.name === undefined || args.name.length === 0) {
|
|
22
|
+
throw new CancelledError("a server name is required in non-interactive mode: pnpm new-server <name>");
|
|
23
|
+
}
|
|
24
|
+
return buildOptions(args, args.name);
|
|
25
|
+
}
|
|
26
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
27
|
+
try {
|
|
28
|
+
let name = args.name ?? "";
|
|
29
|
+
for (;;) {
|
|
30
|
+
if (name.length === 0) {
|
|
31
|
+
name = await ask(rl, "Server name (kebab-case, e.g. arabic-tools)");
|
|
32
|
+
}
|
|
33
|
+
const validation = validateName(name);
|
|
34
|
+
if (validation.ok)
|
|
35
|
+
break;
|
|
36
|
+
console.log("Invalid name: " + validation.reason);
|
|
37
|
+
name = "";
|
|
38
|
+
}
|
|
39
|
+
const description = await ask(rl, "Description", args.description ?? "MCP server for " + name + ".");
|
|
40
|
+
const toolName = await ask(rl, "Example tool name (snake_case)", args.tool ?? defaultToolName(name));
|
|
41
|
+
const author = await ask(rl, "Author", args.author ?? "open-mena-mcp contributors");
|
|
42
|
+
return { name, description, toolName, author };
|
|
43
|
+
}
|
|
44
|
+
finally {
|
|
45
|
+
rl.close();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function buildOptions(args, name) {
|
|
49
|
+
return {
|
|
50
|
+
name,
|
|
51
|
+
description: args.description ?? "MCP server for " + name + ".",
|
|
52
|
+
toolName: args.tool ?? defaultToolName(name),
|
|
53
|
+
author: args.author ?? "open-mena-mcp contributors",
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=prompts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompts.js","sourceRoot":"","sources":["../src/prompts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAkB,MAAM,wBAAwB,CAAC;AAGzE,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAG9D,MAAM,OAAO,cAAe,SAAQ,KAAK;CAAG;AAE5C,KAAK,UAAU,GAAG,CAAC,EAAa,EAAE,KAAa,EAAE,QAAiB;IAChE,MAAM,MAAM,GAAG,QAAQ,KAAK,SAAS,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,C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AAgB,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC;YAClD,IAAI,GAAG,EAAE,CAAC;QACZ,CAAC;QACD,MAAM,WAAW,GAAG,MAAM,GAAG,CAC3B,EAAE,EACF,aAAa,EACb,IAAI,CAAC,WAAW,IAAI,iBAAiB,GAAG,IAAI,GAAG,GAAG,CACnD,CAAC;QACF,MAAM,QAAQ,GAAG,MAAM,GAAG,CACxB,EAAE,EACF,gCAAgC,EAChC,IAAI,CAAC,IAAI,IAAI,eAAe,CAAC,IAAI,CAAC,CACnC,CAAC;QACF,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,EAAE,EAAE,QAAQ,EAAE,IAAI,CAAC,MAAM,IAAI,4BAA4B,CAAC,CAAC;QACpF,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;IACjD,CAAC;YAAS,CAAC;QACT,EAAE,CAAC,KAAK,EAAE,CAAC;IACb,CAAC;AACH,CAAC;AAED,SAAS,YAAY,CAAC,IAAa,EAAE,IAAY;IAC/C,OAAO;QACL,IAAI;QACJ,WAAW,EAAE,IAAI,CAAC,WAAW,IAAI,iBAAiB,GAAG,IAAI,GAAG,GAAG;QAC/D,QAAQ,EAAE,IAAI,CAAC,IAAI,IAAI,eAAe,CAAC,IAAI,CAAC;QAC5C,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,4BAA4B;KACpD,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type ServerTemplateOptions } from "./templates.js";
|
|
2
|
+
export interface ScaffoldResult {
|
|
3
|
+
targetDir: string;
|
|
4
|
+
files: string[];
|
|
5
|
+
}
|
|
6
|
+
export declare function templateFiles(o: ServerTemplateOptions): Record<string, string>;
|
|
7
|
+
/** Writes the generated server package to disk. Refuses to overwrite an existing directory. */
|
|
8
|
+
export declare function scaffoldServer(o: ServerTemplateOptions, targetDir: string): Promise<ScaffoldResult>;
|
package/dist/scaffold.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { existsSync } from "node:fs";
|
|
4
|
+
import { clientSource, indexSource, packageJson, readme, serverSource, testSource, tsconfigBuildJson, tsconfigJson, vitestConfig, } from "./templates.js";
|
|
5
|
+
export function templateFiles(o) {
|
|
6
|
+
return {
|
|
7
|
+
"package.json": packageJson(o),
|
|
8
|
+
"tsconfig.json": tsconfigJson(),
|
|
9
|
+
"tsconfig.build.json": tsconfigBuildJson(),
|
|
10
|
+
"vitest.config.ts": vitestConfig(),
|
|
11
|
+
"README.md": readme(o),
|
|
12
|
+
"src/index.ts": indexSource(),
|
|
13
|
+
"src/server.ts": serverSource(o),
|
|
14
|
+
"src/client.ts": clientSource(),
|
|
15
|
+
"src/server.test.ts": testSource(o),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/** Writes the generated server package to disk. Refuses to overwrite an existing directory. */
|
|
19
|
+
export async function scaffoldServer(o, targetDir) {
|
|
20
|
+
if (existsSync(targetDir)) {
|
|
21
|
+
throw new Error("target directory already exists: " + targetDir);
|
|
22
|
+
}
|
|
23
|
+
const files = templateFiles(o);
|
|
24
|
+
const written = [];
|
|
25
|
+
for (const [relativePath, content] of Object.entries(files)) {
|
|
26
|
+
const absolutePath = path.join(targetDir, relativePath);
|
|
27
|
+
await mkdir(path.dirname(absolutePath), { recursive: true });
|
|
28
|
+
await writeFile(absolutePath, content, "utf8");
|
|
29
|
+
written.push(relativePath);
|
|
30
|
+
}
|
|
31
|
+
return { targetDir, files: written };
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=scaffold.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scaffold.js","sourceRoot":"","sources":["../src/scaffold.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,IA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AAY,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;QAC/C,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAC7B,CAAC;IACD,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;AACvC,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface ServerTemplateOptions {
|
|
2
|
+
/** Kebab-case slug, e.g. "arabic-tools". */
|
|
3
|
+
name: string;
|
|
4
|
+
description: string;
|
|
5
|
+
author: string;
|
|
6
|
+
/** snake_case MCP tool name, e.g. "arabic_tools_lookup". */
|
|
7
|
+
toolName: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function scopedName(name: string): string;
|
|
10
|
+
export declare function packageJson(o: ServerTemplateOptions): string;
|
|
11
|
+
export declare function tsconfigJson(): string;
|
|
12
|
+
export declare function tsconfigBuildJson(): string;
|
|
13
|
+
export declare function vitestConfig(): string;
|
|
14
|
+
/** Example HTTP client. The test mocks global fetch, so CI needs no live API keys. */
|
|
15
|
+
export declare function clientSource(): string;
|
|
16
|
+
export declare function serverSource(o: ServerTemplateOptions): string;
|
|
17
|
+
export declare function indexSource(): string;
|
|
18
|
+
/** Vitest suite with mocked HTTP (vi.stubGlobal on fetch). No network, no API keys. */
|
|
19
|
+
export declare function testSource(o: ServerTemplateOptions): string;
|
|
20
|
+
export declare function readme(o: ServerTemplateOptions): string;
|
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
const SCOPE = "@open-mena-mcp";
|
|
2
|
+
export function scopedName(name) {
|
|
3
|
+
return SCOPE + "/" + name;
|
|
4
|
+
}
|
|
5
|
+
export function packageJson(o) {
|
|
6
|
+
const manifest = {
|
|
7
|
+
name: scopedName(o.name),
|
|
8
|
+
version: "0.1.0",
|
|
9
|
+
description: o.description,
|
|
10
|
+
license: "MIT",
|
|
11
|
+
author: o.author,
|
|
12
|
+
type: "module",
|
|
13
|
+
main: "./dist/index.js",
|
|
14
|
+
types: "./dist/index.d.ts",
|
|
15
|
+
files: ["dist"],
|
|
16
|
+
engines: { node: ">=20" },
|
|
17
|
+
scripts: {
|
|
18
|
+
build: "tsc -p tsconfig.build.json",
|
|
19
|
+
typecheck: "tsc --noEmit -p tsconfig.json",
|
|
20
|
+
lint: "eslint src",
|
|
21
|
+
test: "vitest run",
|
|
22
|
+
start: "node dist/index.js",
|
|
23
|
+
},
|
|
24
|
+
dependencies: {
|
|
25
|
+
"@modelcontextprotocol/sdk": "^1.12.0",
|
|
26
|
+
zod: "^3.24.1",
|
|
27
|
+
},
|
|
28
|
+
devDependencies: {
|
|
29
|
+
"@types/node": "^22.7.4",
|
|
30
|
+
typescript: "^5.6.3",
|
|
31
|
+
vitest: "^4.1.12",
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
return JSON.stringify(manifest, null, 2) + "\n";
|
|
35
|
+
}
|
|
36
|
+
export function tsconfigJson() {
|
|
37
|
+
return [
|
|
38
|
+
"{",
|
|
39
|
+
' "extends": "../../tsconfig.base.json",',
|
|
40
|
+
' "compilerOptions": {',
|
|
41
|
+
' "outDir": "dist",',
|
|
42
|
+
' "rootDir": "src",',
|
|
43
|
+
' "noEmit": true',
|
|
44
|
+
" },",
|
|
45
|
+
' "include": ["src"]',
|
|
46
|
+
"}",
|
|
47
|
+
"",
|
|
48
|
+
].join("\n");
|
|
49
|
+
}
|
|
50
|
+
export function tsconfigBuildJson() {
|
|
51
|
+
return [
|
|
52
|
+
"{",
|
|
53
|
+
' "extends": "../../tsconfig.base.json",',
|
|
54
|
+
' "compilerOptions": {',
|
|
55
|
+
' "outDir": "dist",',
|
|
56
|
+
' "rootDir": "src",',
|
|
57
|
+
' "noEmit": false',
|
|
58
|
+
" },",
|
|
59
|
+
' "include": ["src"],',
|
|
60
|
+
' "exclude": ["src/**/*.test.ts"]',
|
|
61
|
+
"}",
|
|
62
|
+
"",
|
|
63
|
+
].join("\n");
|
|
64
|
+
}
|
|
65
|
+
export function vitestConfig() {
|
|
66
|
+
return [
|
|
67
|
+
'import { defineConfig } from "vitest/config";',
|
|
68
|
+
"",
|
|
69
|
+
"export default defineConfig({",
|
|
70
|
+
" test: {",
|
|
71
|
+
' environment: "node",',
|
|
72
|
+
' include: ["src/**/*.test.ts"],',
|
|
73
|
+
" },",
|
|
74
|
+
"});",
|
|
75
|
+
"",
|
|
76
|
+
].join("\n");
|
|
77
|
+
}
|
|
78
|
+
/** Example HTTP client. The test mocks global fetch, so CI needs no live API keys. */
|
|
79
|
+
export function clientSource() {
|
|
80
|
+
return [
|
|
81
|
+
"/**",
|
|
82
|
+
" * Replace this example client with calls to your real API.",
|
|
83
|
+
" * Keep every call behind this module so tests can mock global fetch.",
|
|
84
|
+
" */",
|
|
85
|
+
"export async function fetchJson(url: string, params: Record<string, string>): Promise<unknown> {",
|
|
86
|
+
" const query = new URLSearchParams(params).toString();",
|
|
87
|
+
' const response = await fetch(url + "?" + query, {',
|
|
88
|
+
' headers: { accept: "application/json" },',
|
|
89
|
+
" });",
|
|
90
|
+
" if (!response.ok) {",
|
|
91
|
+
' throw new Error("Request failed with HTTP status " + String(response.status));',
|
|
92
|
+
" }",
|
|
93
|
+
" return await response.json();",
|
|
94
|
+
"}",
|
|
95
|
+
"",
|
|
96
|
+
].join("\n");
|
|
97
|
+
}
|
|
98
|
+
export function serverSource(o) {
|
|
99
|
+
return [
|
|
100
|
+
'import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";',
|
|
101
|
+
'import { z } from "zod";',
|
|
102
|
+
"",
|
|
103
|
+
'import { fetchJson } from "./client.js";',
|
|
104
|
+
"",
|
|
105
|
+
"/**",
|
|
106
|
+
" * Zod schema for the example tool input.",
|
|
107
|
+
" * Every field needs a .describe() so MCP clients can show humans what it means.",
|
|
108
|
+
" */",
|
|
109
|
+
"export const " + toolSchemaConst(o) + " = z.object({",
|
|
110
|
+
' query: z.string().min(1).describe("Search query to send to the example API."),',
|
|
111
|
+
" limit: z",
|
|
112
|
+
" .number()",
|
|
113
|
+
" .int()",
|
|
114
|
+
" .min(1)",
|
|
115
|
+
" .max(50)",
|
|
116
|
+
" .optional()",
|
|
117
|
+
' .describe("Maximum number of results to return (1-50, default 10)."),',
|
|
118
|
+
"});",
|
|
119
|
+
"",
|
|
120
|
+
"export type " + toolInputType(o) + " = z.infer<typeof " + toolSchemaConst(o) + ">;",
|
|
121
|
+
"",
|
|
122
|
+
"export function createServer(): McpServer {",
|
|
123
|
+
" const server = new McpServer({",
|
|
124
|
+
' name: "' + scopedName(o.name) + '",',
|
|
125
|
+
' version: "0.1.0",',
|
|
126
|
+
" });",
|
|
127
|
+
"",
|
|
128
|
+
" server.registerTool(",
|
|
129
|
+
' "' + o.toolName + '",',
|
|
130
|
+
" {",
|
|
131
|
+
' title: "' + toTitleCase(o.name) + '",',
|
|
132
|
+
' description: "' + o.description.replace(/"/g, "'") + '",',
|
|
133
|
+
" inputSchema: " + toolSchemaConst(o) + ".shape,",
|
|
134
|
+
" },",
|
|
135
|
+
" async (input) => {",
|
|
136
|
+
" const data = await fetchJson(" + '"https://api.example.com/search"' + ", {",
|
|
137
|
+
" q: input.query,",
|
|
138
|
+
" limit: String(input.limit ?? 10),",
|
|
139
|
+
" });",
|
|
140
|
+
" return {",
|
|
141
|
+
" content: [",
|
|
142
|
+
" {",
|
|
143
|
+
' type: "text" as const,',
|
|
144
|
+
" text: JSON.stringify(data, null, 2),",
|
|
145
|
+
" },",
|
|
146
|
+
" ],",
|
|
147
|
+
" };",
|
|
148
|
+
" },",
|
|
149
|
+
" );",
|
|
150
|
+
"",
|
|
151
|
+
" return server;",
|
|
152
|
+
"}",
|
|
153
|
+
"",
|
|
154
|
+
].join("\n");
|
|
155
|
+
}
|
|
156
|
+
function toPascalCase(name) {
|
|
157
|
+
return name
|
|
158
|
+
.split("-")
|
|
159
|
+
.filter((part) => part.length > 0)
|
|
160
|
+
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
|
|
161
|
+
.join("");
|
|
162
|
+
}
|
|
163
|
+
function padCell(text, width) {
|
|
164
|
+
return text + " ".repeat(Math.max(0, width - text.length));
|
|
165
|
+
}
|
|
166
|
+
/** Emits a two-column markdown table already aligned the way Prettier formats it. */
|
|
167
|
+
function prettierTable(o) {
|
|
168
|
+
const toolCell = "\u0060" + o.toolName + "\u0060";
|
|
169
|
+
const toolWidth = Math.max("Tool".length, toolCell.length);
|
|
170
|
+
const descWidth = Math.max("Description".length, o.description.length);
|
|
171
|
+
return [
|
|
172
|
+
"| " + padCell("Tool", toolWidth) + " | " + padCell("Description", descWidth) + " |",
|
|
173
|
+
"| " + "-".repeat(toolWidth) + " | " + "-".repeat(descWidth) + " |",
|
|
174
|
+
"| " + padCell(toolCell, toolWidth) + " | " + padCell(o.description, descWidth) + " |",
|
|
175
|
+
];
|
|
176
|
+
}
|
|
177
|
+
function toTitleCase(name) {
|
|
178
|
+
return name
|
|
179
|
+
.split("-")
|
|
180
|
+
.filter((part) => part.length > 0)
|
|
181
|
+
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
|
|
182
|
+
.join(" ");
|
|
183
|
+
}
|
|
184
|
+
function toolSchemaConst(o) {
|
|
185
|
+
return toPascalCase(o.name) + "InputSchema";
|
|
186
|
+
}
|
|
187
|
+
function toolInputType(o) {
|
|
188
|
+
return toPascalCase(o.name) + "Input";
|
|
189
|
+
}
|
|
190
|
+
export function indexSource() {
|
|
191
|
+
return [
|
|
192
|
+
"#!/usr/bin/env node",
|
|
193
|
+
'import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";',
|
|
194
|
+
"",
|
|
195
|
+
'import { createServer } from "./server.js";',
|
|
196
|
+
"",
|
|
197
|
+
"async function main(): Promise<void> {",
|
|
198
|
+
" const server = createServer();",
|
|
199
|
+
" const transport = new StdioServerTransport();",
|
|
200
|
+
" await server.connect(transport);",
|
|
201
|
+
' console.error("' + 'MCP server running on stdio");',
|
|
202
|
+
"}",
|
|
203
|
+
"",
|
|
204
|
+
"main().catch((error: unknown) => {",
|
|
205
|
+
" console.error(error);",
|
|
206
|
+
" process.exit(1);",
|
|
207
|
+
"});",
|
|
208
|
+
"",
|
|
209
|
+
].join("\n");
|
|
210
|
+
}
|
|
211
|
+
/** Vitest suite with mocked HTTP (vi.stubGlobal on fetch). No network, no API keys. */
|
|
212
|
+
export function testSource(o) {
|
|
213
|
+
return [
|
|
214
|
+
'import { afterEach, describe, expect, it, vi } from "vitest";',
|
|
215
|
+
"",
|
|
216
|
+
'import { fetchJson } from "./client.js";',
|
|
217
|
+
"import { " + toolSchemaConst(o) + ", createServer } from " + '"./server.js";',
|
|
218
|
+
"",
|
|
219
|
+
"const okResponse = (body: unknown): Response =>",
|
|
220
|
+
" new Response(JSON.stringify(body), {",
|
|
221
|
+
" status: 200,",
|
|
222
|
+
' headers: { "content-type": "application/json" },',
|
|
223
|
+
" });",
|
|
224
|
+
"",
|
|
225
|
+
'describe("' + scopedName(o.name) + '", () => {',
|
|
226
|
+
" afterEach(() => {",
|
|
227
|
+
" vi.unstubAllGlobals();",
|
|
228
|
+
" });",
|
|
229
|
+
"",
|
|
230
|
+
' it("validates tool input with the Zod schema", () => {',
|
|
231
|
+
" expect(" + toolSchemaConst(o) + '.parse({ query: "riyadh" })).toEqual({',
|
|
232
|
+
' query: "riyadh",',
|
|
233
|
+
" });",
|
|
234
|
+
" expect(() => " + toolSchemaConst(o) + '.parse({ query: "" })).toThrow();',
|
|
235
|
+
" });",
|
|
236
|
+
"",
|
|
237
|
+
' it("fetchJson builds the query string and parses JSON", async () => {',
|
|
238
|
+
" const fetchMock = vi.fn((_input: unknown): Promise<Response> =>",
|
|
239
|
+
' Promise.resolve(okResponse({ results: ["a", "b"] })),',
|
|
240
|
+
" );",
|
|
241
|
+
' vi.stubGlobal("fetch", fetchMock);',
|
|
242
|
+
"",
|
|
243
|
+
' const data = await fetchJson("https://api.example.com/search", {',
|
|
244
|
+
' q: "riyadh",',
|
|
245
|
+
' limit: "5",',
|
|
246
|
+
" });",
|
|
247
|
+
"",
|
|
248
|
+
" expect(fetchMock).toHaveBeenCalledTimes(1);",
|
|
249
|
+
" const firstCall = fetchMock.mock.calls[0];",
|
|
250
|
+
" if (firstCall === undefined) {",
|
|
251
|
+
' throw new Error("expected fetch to have been called");',
|
|
252
|
+
" }",
|
|
253
|
+
" expect(String(firstCall[0])).toContain(" + '"q=riyadh");',
|
|
254
|
+
" expect(data).toEqual({ results: [" + '"a", "b"] });',
|
|
255
|
+
" });",
|
|
256
|
+
"",
|
|
257
|
+
' it("fetchJson throws on a non-2xx response", async () => {',
|
|
258
|
+
" vi.stubGlobal(",
|
|
259
|
+
' "fetch",',
|
|
260
|
+
' vi.fn((): Promise<Response> => Promise.resolve(new Response("nope", { status: 500 }))),',
|
|
261
|
+
" );",
|
|
262
|
+
' await expect(fetchJson("https://api.example.com/x", {})).rejects.toThrow("500");',
|
|
263
|
+
" });",
|
|
264
|
+
"",
|
|
265
|
+
' it("createServer returns a configured MCP server", () => {',
|
|
266
|
+
" const server = createServer();",
|
|
267
|
+
" expect(server).toBeDefined();",
|
|
268
|
+
" });",
|
|
269
|
+
"});",
|
|
270
|
+
"",
|
|
271
|
+
].join("\n");
|
|
272
|
+
}
|
|
273
|
+
export function readme(o) {
|
|
274
|
+
const fence = "```";
|
|
275
|
+
return [
|
|
276
|
+
"# " + scopedName(o.name),
|
|
277
|
+
"",
|
|
278
|
+
o.description,
|
|
279
|
+
"",
|
|
280
|
+
"Part of the [open-mena-mcp](https://github.com/Dinaelsayed99/open-mena-mcp) monorepo: MCP servers for Arabic language utilities and MENA ecosystem services.",
|
|
281
|
+
"",
|
|
282
|
+
"## Tools",
|
|
283
|
+
"",
|
|
284
|
+
...prettierTable(o),
|
|
285
|
+
"",
|
|
286
|
+
"## Develop",
|
|
287
|
+
"",
|
|
288
|
+
fence + "bash",
|
|
289
|
+
"pnpm install",
|
|
290
|
+
"pnpm --filter " + scopedName(o.name) + " build",
|
|
291
|
+
"pnpm --filter " + scopedName(o.name) + " test",
|
|
292
|
+
fence,
|
|
293
|
+
"",
|
|
294
|
+
'Tests mock HTTP with vitest (\u0060vi.stubGlobal("fetch", ...)\u0060), so they run without live API keys.',
|
|
295
|
+
"",
|
|
296
|
+
"## Run with an MCP client",
|
|
297
|
+
"",
|
|
298
|
+
"Point your client at the built entrypoint over stdio, for example in Claude Desktop config:",
|
|
299
|
+
"",
|
|
300
|
+
fence + "json",
|
|
301
|
+
"{",
|
|
302
|
+
' "mcpServers": {',
|
|
303
|
+
' "' + o.name + '": {',
|
|
304
|
+
' "command": "node",',
|
|
305
|
+
' "args": ["/absolute/path/to/open-mena-mcp/packages/' + o.name + '/dist/index.js"]',
|
|
306
|
+
" }",
|
|
307
|
+
" }",
|
|
308
|
+
"}",
|
|
309
|
+
fence,
|
|
310
|
+
"",
|
|
311
|
+
"## Where to put your code",
|
|
312
|
+
"",
|
|
313
|
+
"- \u0060src/server.ts\u0060 registers tools. Keep the Zod schema descriptions accurate.",
|
|
314
|
+
"- \u0060src/client.ts\u0060 owns every outbound HTTP call so tests can mock \u0060fetch\u0060.",
|
|
315
|
+
"- Never commit API keys or \u0060.env\u0060 files. Read secrets from environment variables at runtime.",
|
|
316
|
+
"",
|
|
317
|
+
"## License",
|
|
318
|
+
"",
|
|
319
|
+
"MIT",
|
|
320
|
+
"",
|
|
321
|
+
].join("\n");
|
|
322
|
+
}
|
|
323
|
+
//# sourceMappingURL=templates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"templates.js","sourceRoot":"","sources":["../src/templates.ts"],"names":[],"mappings":"AASA,MAAM,KAAK,GAAG,gBAAgB,CAAC;AAE/B,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,OAAO,KAAK,GAAG,GAAG,GAAG,IAAI,CAAC;AAC5B,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,CAAwB;IAClD,MAAM,QAAQ,GAAG;QACf,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC;QACxB,OAAO,EAAE,OAAO;QAChB,WAAW,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,MAAM,CAAC,CAAwB;IAC7C,MAAM,KAAK,GAAG,KAAK,CAAC;IACpB,OAAO;QACL,IAAI,GAAG,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC;QACzB,EAAE;QACF,CAAC,CAAC,WAAW;QACb,EAAE;QACF,8JAA8J;QAC9J,EAAE;QACF,UAAU;QACV,EAAE;QACF,GAAG,aAAa,CAAC,CAAC,CAAC;QACnB,EAAE;QACF,YAAY;QACZ,EAAE;QACF,KAAK,GAAG,MAAM;QACd,cAAc;QACd,gBAAgB,GAAG,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,QAAQ;QAChD,gBAAgB,GAAG,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO;QAC/C,KAAK;QACL,EAAE;QACF,2GAA2G;QAC3G,EAAE;QACF,2BAA2B;QAC3B,EAAE;QACF,6FAA6F;QAC7F,EAAE;QACF,KAAK,GAAG,MAAM;QACd,GAAG;QACH,mBAAmB;QACnB,OAAO,GAAG,CAAC,CAAC,IAAI,GAAG,MAAM;QACzB,0BAA0B;QAC1B,2DAA2D,GAAG,CAAC,CAAC,IAAI,GAAG,kBAAkB;QACzF,OAAO;QACP,KAAK;QACL,GAAG;QACH,KAAK;QACL,EAAE;QACF,2BAA2B;QAC3B,EAAE;QACF,yFAAyF;QACzF,gGAAgG;QAChG,wGAAwG;QACxG,EAAE;QACF,YAAY;QACZ,EAAE;QACF,KAAK;QACL,EAAE;KACH,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type NameValidation = {
|
|
2
|
+
ok: true;
|
|
3
|
+
} | {
|
|
4
|
+
ok: false;
|
|
5
|
+
reason: string;
|
|
6
|
+
};
|
|
7
|
+
/** A server name must be a kebab-case slug safe for an npm package name and a directory. */
|
|
8
|
+
export declare function validateName(name: string): NameValidation;
|
|
9
|
+
/** Turns a kebab-case server name into a default snake_case tool name. */
|
|
10
|
+
export declare function defaultToolName(name: string): string;
|
package/dist/validate.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const NAME_PATTERN = /^[a-z0-9][a-z0-9-]*$/;
|
|
2
|
+
/** A server name must be a kebab-case slug safe for an npm package name and a directory. */
|
|
3
|
+
export function validateName(name) {
|
|
4
|
+
if (name.length === 0) {
|
|
5
|
+
return { ok: false, reason: "name must not be empty" };
|
|
6
|
+
}
|
|
7
|
+
if (name.length > 64) {
|
|
8
|
+
return { ok: false, reason: "name must be at most 64 characters" };
|
|
9
|
+
}
|
|
10
|
+
if (!NAME_PATTERN.test(name)) {
|
|
11
|
+
return {
|
|
12
|
+
ok: false,
|
|
13
|
+
reason: "name must be lowercase kebab-case (letters, digits, dashes; no leading dash)",
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
if (name.endsWith("-")) {
|
|
17
|
+
return { ok: false, reason: "name must not end with a dash" };
|
|
18
|
+
}
|
|
19
|
+
return { ok: true };
|
|
20
|
+
}
|
|
21
|
+
/** Turns a kebab-case server name into a default snake_case tool name. */
|
|
22
|
+
export function defaultToolName(name) {
|
|
23
|
+
return name.replace(/-/g, "_") + "_lookup";
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=validate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AAAA,MAAM,YAAY,GAAG,sBAAsB,CAAC;AAI5C,4FAA4F;AAC5F,MAAM,UAAU,YAAY,CAAC,IAAY;IACvC,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtB,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,wBAAwB,EAAE,CAAC;IACzD,CAAC;IACD,IAAI,IAAI,CAAC,MAAM,GAAG,EAAE,EAAE,CAAC;QACrB,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,oCAAoC,EAAE,CAAC;IACrE,CAAC;IACD,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QAC7B,OAAO;YACL,EAAE,EAAE,KAAK;YACT,MAAM,EAAE,8EAA8E;SACvF,CAAC;IACJ,CAAC;IACD,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACvB,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,+BAA+B,EAAE,CAAC;IAChE,CAAC;IACD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC;AACtB,CAAC;AAED,0EAA0E;AAC1E,MAAM,UAAU,eAAe,CAAC,IAAY;IAC1C,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,GAAG,SAAS,CAAC;AAC7C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-mena-mcp/cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Interactive scaffolder that generates runnable TypeScript MCP server boilerplate for the open-mena-mcp monorepo.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"new-server": "./dist/index.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"LICENSE",
|
|
13
|
+
"README.md"
|
|
14
|
+
],
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">=20"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@types/node": "^22.7.4",
|
|
20
|
+
"tsx": "^4.19.1",
|
|
21
|
+
"typescript": "^5.6.3",
|
|
22
|
+
"vitest": "^4.1.12"
|
|
23
|
+
},
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://github.com/Dinaelsayed99/open-mena-mcp.git",
|
|
27
|
+
"directory": "packages/cli"
|
|
28
|
+
},
|
|
29
|
+
"homepage": "https://github.com/Dinaelsayed99/open-mena-mcp/tree/main/packages/cli#readme",
|
|
30
|
+
"bugs": {
|
|
31
|
+
"url": "https://github.com/Dinaelsayed99/open-mena-mcp/issues"
|
|
32
|
+
},
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsc -p tsconfig.build.json",
|
|
38
|
+
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
39
|
+
"lint": "eslint src",
|
|
40
|
+
"test": "vitest run",
|
|
41
|
+
"new-server": "tsx src/index.ts"
|
|
42
|
+
}
|
|
6
43
|
}
|