@julong/mono-rele2-utils 1.9.0 → 1.10.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/dist/cli.js +144 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +3 -65
- package/dist/server.js +124 -0
- package/package.json +3 -2
package/dist/cli.js
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// ../common/kit/tool.ts
|
|
4
|
+
function toolDef(def) {
|
|
5
|
+
return def;
|
|
6
|
+
}
|
|
7
|
+
function defineTool(tool) {
|
|
8
|
+
return tool;
|
|
9
|
+
}
|
|
10
|
+
function text(content) {
|
|
11
|
+
return { content: [{ type: "text", text: content }] };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// ../common/kit/server.ts
|
|
15
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
16
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
17
|
+
|
|
18
|
+
// ../common/kit/cli.ts
|
|
19
|
+
import { z } from "zod";
|
|
20
|
+
function formatSkills(tools2) {
|
|
21
|
+
const sections = Object.entries(tools2).map(([key, tool]) => {
|
|
22
|
+
const params = Object.entries(tool.inputSchema);
|
|
23
|
+
const maxLen = Math.max(...params.map(([f]) => f.length));
|
|
24
|
+
const paramLines = params.map(([field, schema]) => {
|
|
25
|
+
const desc = schema.description ?? "";
|
|
26
|
+
return ` ${field.padEnd(maxLen + 2)}${desc}`;
|
|
27
|
+
}).join("\n");
|
|
28
|
+
return ` ${key}
|
|
29
|
+
${tool.description}
|
|
30
|
+
${paramLines}`;
|
|
31
|
+
});
|
|
32
|
+
return "Available skills:\n\n" + sections.join("\n\n");
|
|
33
|
+
}
|
|
34
|
+
async function runCli(tools2) {
|
|
35
|
+
const [, , toolName, ...rawArgs] = process.argv;
|
|
36
|
+
if (!toolName || !(toolName in tools2)) {
|
|
37
|
+
if (toolName) console.error(`Unknown skill: "${toolName}"
|
|
38
|
+
`);
|
|
39
|
+
console.log(formatSkills(tools2));
|
|
40
|
+
process.exit(toolName ? 1 : 0);
|
|
41
|
+
}
|
|
42
|
+
const tool = tools2[toolName];
|
|
43
|
+
const fieldNames = Object.keys(tool.inputSchema);
|
|
44
|
+
const rawInput = {};
|
|
45
|
+
for (let i = 0; i < fieldNames.length; i++) {
|
|
46
|
+
const raw = rawArgs[i];
|
|
47
|
+
if (raw === void 0) continue;
|
|
48
|
+
try {
|
|
49
|
+
rawInput[fieldNames[i]] = JSON.parse(raw);
|
|
50
|
+
} catch {
|
|
51
|
+
rawInput[fieldNames[i]] = raw;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const parsed = z.object(tool.inputSchema).parse(rawInput);
|
|
55
|
+
const result = await tool.handler(parsed);
|
|
56
|
+
for (const part of result.content) {
|
|
57
|
+
if (part.type === "text") console.log(part.text);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function handleCliError(err) {
|
|
61
|
+
if (err instanceof z.ZodError) {
|
|
62
|
+
console.error("Validation error:", err.issues.map((e) => `${e.path.join(".")}: ${e.message}`).join(", "));
|
|
63
|
+
} else {
|
|
64
|
+
console.error("Error:", err instanceof Error ? err.message : String(err));
|
|
65
|
+
}
|
|
66
|
+
process.exit(1);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// ../common/kit/skill.ts
|
|
70
|
+
import { z as z2 } from "zod";
|
|
71
|
+
|
|
72
|
+
// src/tools/index.ts
|
|
73
|
+
import { z as z3 } from "zod";
|
|
74
|
+
|
|
75
|
+
// src/cn.ts
|
|
76
|
+
function cn(...classes) {
|
|
77
|
+
return classes.filter(Boolean).join(" ");
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// src/tools/index.ts
|
|
81
|
+
var tools = {
|
|
82
|
+
cnTool: toolDef({
|
|
83
|
+
name: "cn",
|
|
84
|
+
description: "Merges class names, filtering out falsy values",
|
|
85
|
+
inputSchema: {
|
|
86
|
+
classes: z3.array(z3.string()).describe("List of class names to merge")
|
|
87
|
+
},
|
|
88
|
+
handler: async ({ classes }) => text(cn(...classes)),
|
|
89
|
+
examples: [{ args: [`'["btn","active","large"]'`], result: "btn active large" }]
|
|
90
|
+
}),
|
|
91
|
+
caseConvertTool: toolDef({
|
|
92
|
+
name: "case_convert",
|
|
93
|
+
description: "Converts text to the specified case format",
|
|
94
|
+
inputSchema: {
|
|
95
|
+
input: z3.string().describe("Text to convert"),
|
|
96
|
+
to: z3.enum(["upper", "lower", "capitalize", "camel", "snake", "kebab"]).describe("Target case format")
|
|
97
|
+
},
|
|
98
|
+
handler: async ({ input, to }) => text(convert(input, to)),
|
|
99
|
+
examples: [
|
|
100
|
+
{ args: [`"hello world"`, "camel"], result: "helloWorld" },
|
|
101
|
+
{ args: [`"helloWorld"`, "snake"], result: "hello_world" },
|
|
102
|
+
{ args: [`"hello world"`, "kebab"], result: "hello-world" }
|
|
103
|
+
]
|
|
104
|
+
}),
|
|
105
|
+
truncateTool: toolDef({
|
|
106
|
+
name: "truncate",
|
|
107
|
+
description: "Truncates text to a maximum length and appends a suffix",
|
|
108
|
+
inputSchema: {
|
|
109
|
+
input: z3.string().describe("Text to truncate"),
|
|
110
|
+
maxLength: z3.number().int().positive().describe("Maximum character length"),
|
|
111
|
+
suffix: z3.string().default("...").describe("Suffix to append when truncated")
|
|
112
|
+
},
|
|
113
|
+
handler: async ({ input, maxLength, suffix }) => {
|
|
114
|
+
const result = input.length <= maxLength ? input : input.slice(0, maxLength - suffix.length) + suffix;
|
|
115
|
+
return text(result);
|
|
116
|
+
},
|
|
117
|
+
examples: [
|
|
118
|
+
{ args: [`"hello world long text"`, "10"], result: "hello w..." },
|
|
119
|
+
{ args: [`"hello world"`, "8", `"\u2026"`], result: "hello w\u2026" }
|
|
120
|
+
]
|
|
121
|
+
})
|
|
122
|
+
};
|
|
123
|
+
var cnTool = defineTool(tools.cnTool);
|
|
124
|
+
var caseConvertTool = defineTool(tools.caseConvertTool);
|
|
125
|
+
var truncateTool = defineTool(tools.truncateTool);
|
|
126
|
+
function convert(input, to) {
|
|
127
|
+
switch (to) {
|
|
128
|
+
case "upper":
|
|
129
|
+
return input.toUpperCase();
|
|
130
|
+
case "lower":
|
|
131
|
+
return input.toLowerCase();
|
|
132
|
+
case "capitalize":
|
|
133
|
+
return input.charAt(0).toUpperCase() + input.slice(1).toLowerCase();
|
|
134
|
+
case "camel":
|
|
135
|
+
return input.replace(/[-_\s]+(.)/g, (_, c) => c.toUpperCase()).replace(/^(.)/, (c) => c.toLowerCase());
|
|
136
|
+
case "snake":
|
|
137
|
+
return input.replace(/([A-Z])/g, "_$1").replace(/[-\s]+/g, "_").toLowerCase().replace(/^_/, "");
|
|
138
|
+
case "kebab":
|
|
139
|
+
return input.replace(/([A-Z])/g, "-$1").replace(/[_\s]+/g, "-").toLowerCase().replace(/^-/, "");
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// src/cli.ts
|
|
144
|
+
runCli(tools).catch(handleCliError);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as _modelcontextprotocol_sdk_server_mcp_js from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
1
2
|
import { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
|
|
2
3
|
import { z } from 'zod';
|
|
3
4
|
|
|
@@ -80,4 +81,6 @@ declare const tools: {
|
|
|
80
81
|
};
|
|
81
82
|
};
|
|
82
83
|
|
|
83
|
-
|
|
84
|
+
declare function createUtilsServer(): _modelcontextprotocol_sdk_server_mcp_js.McpServer;
|
|
85
|
+
|
|
86
|
+
export { cn, createUtilsServer, generateReadmeSkills, generateSkillMarkdown, tools };
|
package/dist/index.js
CHANGED
|
@@ -24,61 +24,9 @@ function createMcpServer(config, tools2) {
|
|
|
24
24
|
}
|
|
25
25
|
return server;
|
|
26
26
|
}
|
|
27
|
-
async function startServer(server) {
|
|
28
|
-
const transport = new StdioServerTransport();
|
|
29
|
-
await server.connect(transport);
|
|
30
|
-
}
|
|
31
27
|
|
|
32
28
|
// ../common/kit/cli.ts
|
|
33
29
|
import { z } from "zod";
|
|
34
|
-
function formatSkills(tools2) {
|
|
35
|
-
const sections = Object.entries(tools2).map(([key, tool]) => {
|
|
36
|
-
const params = Object.entries(tool.inputSchema);
|
|
37
|
-
const maxLen = Math.max(...params.map(([f]) => f.length));
|
|
38
|
-
const paramLines = params.map(([field, schema]) => {
|
|
39
|
-
const desc = schema.description ?? "";
|
|
40
|
-
return ` ${field.padEnd(maxLen + 2)}${desc}`;
|
|
41
|
-
}).join("\n");
|
|
42
|
-
return ` ${key}
|
|
43
|
-
${tool.description}
|
|
44
|
-
${paramLines}`;
|
|
45
|
-
});
|
|
46
|
-
return "Available skills:\n\n" + sections.join("\n\n");
|
|
47
|
-
}
|
|
48
|
-
async function runCli(tools2) {
|
|
49
|
-
const [, , toolName, ...rawArgs] = process.argv;
|
|
50
|
-
if (!toolName || !(toolName in tools2)) {
|
|
51
|
-
if (toolName) console.error(`Unknown skill: "${toolName}"
|
|
52
|
-
`);
|
|
53
|
-
console.log(formatSkills(tools2));
|
|
54
|
-
process.exit(toolName ? 1 : 0);
|
|
55
|
-
}
|
|
56
|
-
const tool = tools2[toolName];
|
|
57
|
-
const fieldNames = Object.keys(tool.inputSchema);
|
|
58
|
-
const rawInput = {};
|
|
59
|
-
for (let i = 0; i < fieldNames.length; i++) {
|
|
60
|
-
const raw = rawArgs[i];
|
|
61
|
-
if (raw === void 0) continue;
|
|
62
|
-
try {
|
|
63
|
-
rawInput[fieldNames[i]] = JSON.parse(raw);
|
|
64
|
-
} catch {
|
|
65
|
-
rawInput[fieldNames[i]] = raw;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
const parsed = z.object(tool.inputSchema).parse(rawInput);
|
|
69
|
-
const result = await tool.handler(parsed);
|
|
70
|
-
for (const part of result.content) {
|
|
71
|
-
if (part.type === "text") console.log(part.text);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
function handleCliError(err) {
|
|
75
|
-
if (err instanceof z.ZodError) {
|
|
76
|
-
console.error("Validation error:", err.issues.map((e) => `${e.path.join(".")}: ${e.message}`).join(", "));
|
|
77
|
-
} else {
|
|
78
|
-
console.error("Error:", err instanceof Error ? err.message : String(err));
|
|
79
|
-
}
|
|
80
|
-
process.exit(1);
|
|
81
|
-
}
|
|
82
30
|
|
|
83
31
|
// ../common/kit/skill.ts
|
|
84
32
|
import { z as z2 } from "zod";
|
|
@@ -332,22 +280,12 @@ function convert(input, to) {
|
|
|
332
280
|
}
|
|
333
281
|
|
|
334
282
|
// src/index.ts
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
} else {
|
|
338
|
-
let createUtilsServer = function() {
|
|
339
|
-
return createMcpServer({ name: "mono-rele2-utils", version: "1.0.0" }, [cnTool, caseConvertTool, truncateTool]);
|
|
340
|
-
};
|
|
341
|
-
createUtilsServer2 = createUtilsServer;
|
|
342
|
-
const server = createUtilsServer();
|
|
343
|
-
startServer(server).catch((err) => {
|
|
344
|
-
console.error("[utils] server error:", err);
|
|
345
|
-
process.exit(1);
|
|
346
|
-
});
|
|
283
|
+
function createUtilsServer() {
|
|
284
|
+
return createMcpServer({ name: "mono-rele2-utils", version: "1.0.0" }, [cnTool, caseConvertTool, truncateTool]);
|
|
347
285
|
}
|
|
348
|
-
var createUtilsServer2;
|
|
349
286
|
export {
|
|
350
287
|
cn,
|
|
288
|
+
createUtilsServer,
|
|
351
289
|
generateReadmeSkills,
|
|
352
290
|
generateSkillMarkdown,
|
|
353
291
|
tools
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// ../common/kit/tool.ts
|
|
4
|
+
function toolDef(def) {
|
|
5
|
+
return def;
|
|
6
|
+
}
|
|
7
|
+
function defineTool(tool) {
|
|
8
|
+
return tool;
|
|
9
|
+
}
|
|
10
|
+
function text(content) {
|
|
11
|
+
return { content: [{ type: "text", text: content }] };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// ../common/kit/server.ts
|
|
15
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
16
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
17
|
+
function createMcpServer(config, tools2) {
|
|
18
|
+
const server2 = new McpServer(config);
|
|
19
|
+
for (const tool of tools2) {
|
|
20
|
+
server2.registerTool(
|
|
21
|
+
tool.name,
|
|
22
|
+
{ description: tool.description, inputSchema: tool.inputSchema },
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
24
|
+
tool.handler
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
return server2;
|
|
28
|
+
}
|
|
29
|
+
async function startServer(server2) {
|
|
30
|
+
const transport = new StdioServerTransport();
|
|
31
|
+
await server2.connect(transport);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// ../common/kit/cli.ts
|
|
35
|
+
import { z } from "zod";
|
|
36
|
+
|
|
37
|
+
// ../common/kit/skill.ts
|
|
38
|
+
import { z as z2 } from "zod";
|
|
39
|
+
|
|
40
|
+
// src/tools/index.ts
|
|
41
|
+
import { z as z3 } from "zod";
|
|
42
|
+
|
|
43
|
+
// src/cn.ts
|
|
44
|
+
function cn(...classes) {
|
|
45
|
+
return classes.filter(Boolean).join(" ");
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// src/tools/index.ts
|
|
49
|
+
var tools = {
|
|
50
|
+
cnTool: toolDef({
|
|
51
|
+
name: "cn",
|
|
52
|
+
description: "Merges class names, filtering out falsy values",
|
|
53
|
+
inputSchema: {
|
|
54
|
+
classes: z3.array(z3.string()).describe("List of class names to merge")
|
|
55
|
+
},
|
|
56
|
+
handler: async ({ classes }) => text(cn(...classes)),
|
|
57
|
+
examples: [{ args: [`'["btn","active","large"]'`], result: "btn active large" }]
|
|
58
|
+
}),
|
|
59
|
+
caseConvertTool: toolDef({
|
|
60
|
+
name: "case_convert",
|
|
61
|
+
description: "Converts text to the specified case format",
|
|
62
|
+
inputSchema: {
|
|
63
|
+
input: z3.string().describe("Text to convert"),
|
|
64
|
+
to: z3.enum(["upper", "lower", "capitalize", "camel", "snake", "kebab"]).describe("Target case format")
|
|
65
|
+
},
|
|
66
|
+
handler: async ({ input, to }) => text(convert(input, to)),
|
|
67
|
+
examples: [
|
|
68
|
+
{ args: [`"hello world"`, "camel"], result: "helloWorld" },
|
|
69
|
+
{ args: [`"helloWorld"`, "snake"], result: "hello_world" },
|
|
70
|
+
{ args: [`"hello world"`, "kebab"], result: "hello-world" }
|
|
71
|
+
]
|
|
72
|
+
}),
|
|
73
|
+
truncateTool: toolDef({
|
|
74
|
+
name: "truncate",
|
|
75
|
+
description: "Truncates text to a maximum length and appends a suffix",
|
|
76
|
+
inputSchema: {
|
|
77
|
+
input: z3.string().describe("Text to truncate"),
|
|
78
|
+
maxLength: z3.number().int().positive().describe("Maximum character length"),
|
|
79
|
+
suffix: z3.string().default("...").describe("Suffix to append when truncated")
|
|
80
|
+
},
|
|
81
|
+
handler: async ({ input, maxLength, suffix }) => {
|
|
82
|
+
const result = input.length <= maxLength ? input : input.slice(0, maxLength - suffix.length) + suffix;
|
|
83
|
+
return text(result);
|
|
84
|
+
},
|
|
85
|
+
examples: [
|
|
86
|
+
{ args: [`"hello world long text"`, "10"], result: "hello w..." },
|
|
87
|
+
{ args: [`"hello world"`, "8", `"\u2026"`], result: "hello w\u2026" }
|
|
88
|
+
]
|
|
89
|
+
})
|
|
90
|
+
};
|
|
91
|
+
var cnTool = defineTool(tools.cnTool);
|
|
92
|
+
var caseConvertTool = defineTool(tools.caseConvertTool);
|
|
93
|
+
var truncateTool = defineTool(tools.truncateTool);
|
|
94
|
+
function convert(input, to) {
|
|
95
|
+
switch (to) {
|
|
96
|
+
case "upper":
|
|
97
|
+
return input.toUpperCase();
|
|
98
|
+
case "lower":
|
|
99
|
+
return input.toLowerCase();
|
|
100
|
+
case "capitalize":
|
|
101
|
+
return input.charAt(0).toUpperCase() + input.slice(1).toLowerCase();
|
|
102
|
+
case "camel":
|
|
103
|
+
return input.replace(/[-_\s]+(.)/g, (_, c) => c.toUpperCase()).replace(/^(.)/, (c) => c.toLowerCase());
|
|
104
|
+
case "snake":
|
|
105
|
+
return input.replace(/([A-Z])/g, "_$1").replace(/[-\s]+/g, "_").toLowerCase().replace(/^_/, "");
|
|
106
|
+
case "kebab":
|
|
107
|
+
return input.replace(/([A-Z])/g, "-$1").replace(/[_\s]+/g, "-").toLowerCase().replace(/^-/, "");
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// src/index.ts
|
|
112
|
+
function createUtilsServer() {
|
|
113
|
+
return createMcpServer({ name: "mono-rele2-utils", version: "1.0.0" }, [cnTool, caseConvertTool, truncateTool]);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// src/server.ts
|
|
117
|
+
var server = createUtilsServer();
|
|
118
|
+
startServer(server).catch((err) => {
|
|
119
|
+
console.error("[utils] server error:", err);
|
|
120
|
+
process.exit(1);
|
|
121
|
+
});
|
|
122
|
+
export {
|
|
123
|
+
tools
|
|
124
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@julong/mono-rele2-utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.1",
|
|
4
4
|
"description": "Use this skill to invoke text utility functions via the mono-rele2-utils CLI. Handles class name merging, case conversion, and text truncation.",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"type": "module",
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
}
|
|
12
12
|
},
|
|
13
13
|
"bin": {
|
|
14
|
-
"
|
|
14
|
+
"mcp-utils": "./dist/server.js",
|
|
15
|
+
"mono-rele2-utils": "./dist/cli.js"
|
|
15
16
|
},
|
|
16
17
|
"files": [
|
|
17
18
|
"dist"
|