mcp-texttools 1.0.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 +80 -0
- package/index.js +462 -0
- package/package.json +38 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Hong Teoh
|
|
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
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# mcp-texttools
|
|
2
|
+
|
|
3
|
+
MCP server with 10 text transformation tools for AI assistants (Claude, Cursor, etc).
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npx mcp-texttools
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
### Claude Desktop
|
|
12
|
+
|
|
13
|
+
Add to `claude_desktop_config.json`:
|
|
14
|
+
|
|
15
|
+
```json
|
|
16
|
+
{
|
|
17
|
+
"mcpServers": {
|
|
18
|
+
"texttools": {
|
|
19
|
+
"command": "npx",
|
|
20
|
+
"args": ["-y", "mcp-texttools"]
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### Cursor
|
|
27
|
+
|
|
28
|
+
Add to `.cursor/mcp.json`:
|
|
29
|
+
|
|
30
|
+
```json
|
|
31
|
+
{
|
|
32
|
+
"mcpServers": {
|
|
33
|
+
"texttools": {
|
|
34
|
+
"command": "npx",
|
|
35
|
+
"args": ["-y", "mcp-texttools"]
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Tools
|
|
42
|
+
|
|
43
|
+
| Tool | Description |
|
|
44
|
+
|------|-------------|
|
|
45
|
+
| `case_convert` | Convert between camelCase, snake_case, kebab-case, PascalCase, CONSTANT_CASE, Title Case, dot.case |
|
|
46
|
+
| `slugify` | Convert text to URL-friendly slug |
|
|
47
|
+
| `word_count` | Count words, characters, sentences, paragraphs + reading time |
|
|
48
|
+
| `lorem_ipsum` | Generate placeholder text (words, sentences, or paragraphs) |
|
|
49
|
+
| `truncate` | Smart truncation at word/sentence/character boundaries |
|
|
50
|
+
| `regex_replace` | Find & replace with regex (supports capture groups) |
|
|
51
|
+
| `markdown_strip` | Strip markdown formatting to plain text |
|
|
52
|
+
| `text_reverse` | Reverse by characters, words, or lines |
|
|
53
|
+
| `line_sort` | Sort lines (alpha, numeric, length, random) + dedup |
|
|
54
|
+
| `text_diff` | Compare two texts line by line |
|
|
55
|
+
|
|
56
|
+
## Examples
|
|
57
|
+
|
|
58
|
+
**Convert case:**
|
|
59
|
+
- Input: `"myVariableName"` → snake → `my_variable_name`
|
|
60
|
+
- Input: `"my-api-endpoint"` → pascal → `MyApiEndpoint`
|
|
61
|
+
|
|
62
|
+
**Slugify:**
|
|
63
|
+
- Input: `"Hello World! This is a Test"` → `hello-world-this-is-a-test`
|
|
64
|
+
|
|
65
|
+
**Word count:**
|
|
66
|
+
- Returns words, characters, sentences, paragraphs, reading time
|
|
67
|
+
|
|
68
|
+
## Part of the MCP Dev Tools Suite
|
|
69
|
+
|
|
70
|
+
- [mcp-devutils](https://www.npmjs.com/package/mcp-devutils) — UUID, hash, base64, timestamps, JWT decode, and more
|
|
71
|
+
- [mcp-apitools](https://www.npmjs.com/package/mcp-apitools) — HTTP status, MIME types, JWT create, mock data, CORS headers
|
|
72
|
+
- **mcp-texttools** — Text transformation and analysis (this package)
|
|
73
|
+
|
|
74
|
+
## Support
|
|
75
|
+
|
|
76
|
+
If you find this useful, consider [buying me a coffee](https://buymeacoffee.com/gl89tu25lp)!
|
|
77
|
+
|
|
78
|
+
## License
|
|
79
|
+
|
|
80
|
+
MIT
|
package/index.js
ADDED
|
@@ -0,0 +1,462 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
3
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
|
+
import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
5
|
+
|
|
6
|
+
const server = new Server(
|
|
7
|
+
{ name: "mcp-texttools", version: "1.0.0" },
|
|
8
|
+
{ capabilities: { tools: {} } }
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
12
|
+
return {
|
|
13
|
+
tools: [
|
|
14
|
+
{
|
|
15
|
+
name: "case_convert",
|
|
16
|
+
description: "Convert text between camelCase, snake_case, kebab-case, PascalCase, CONSTANT_CASE, Title Case, and dot.case",
|
|
17
|
+
inputSchema: {
|
|
18
|
+
type: "object",
|
|
19
|
+
properties: {
|
|
20
|
+
text: { type: "string", description: "Text to convert" },
|
|
21
|
+
to: {
|
|
22
|
+
type: "string",
|
|
23
|
+
enum: ["camel", "snake", "kebab", "pascal", "constant", "title", "dot"],
|
|
24
|
+
description: "Target case format"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
required: ["text", "to"]
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: "slugify",
|
|
32
|
+
description: "Convert text to a URL-friendly slug",
|
|
33
|
+
inputSchema: {
|
|
34
|
+
type: "object",
|
|
35
|
+
properties: {
|
|
36
|
+
text: { type: "string", description: "Text to slugify" },
|
|
37
|
+
separator: { type: "string", description: "Separator character (default: -)" }
|
|
38
|
+
},
|
|
39
|
+
required: ["text"]
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: "word_count",
|
|
44
|
+
description: "Count words, characters, sentences, paragraphs, and estimate reading time",
|
|
45
|
+
inputSchema: {
|
|
46
|
+
type: "object",
|
|
47
|
+
properties: {
|
|
48
|
+
text: { type: "string", description: "Text to analyze" }
|
|
49
|
+
},
|
|
50
|
+
required: ["text"]
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
name: "lorem_ipsum",
|
|
55
|
+
description: "Generate lorem ipsum placeholder text",
|
|
56
|
+
inputSchema: {
|
|
57
|
+
type: "object",
|
|
58
|
+
properties: {
|
|
59
|
+
count: { type: "number", description: "Number of units to generate (default: 3)" },
|
|
60
|
+
unit: {
|
|
61
|
+
type: "string",
|
|
62
|
+
enum: ["words", "sentences", "paragraphs"],
|
|
63
|
+
description: "Unit type (default: paragraphs)"
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
name: "truncate",
|
|
70
|
+
description: "Truncate text to a specified length with customizable suffix",
|
|
71
|
+
inputSchema: {
|
|
72
|
+
type: "object",
|
|
73
|
+
properties: {
|
|
74
|
+
text: { type: "string", description: "Text to truncate" },
|
|
75
|
+
length: { type: "number", description: "Maximum length (default: 100)" },
|
|
76
|
+
suffix: { type: "string", description: "Suffix to append (default: ...)" },
|
|
77
|
+
boundary: {
|
|
78
|
+
type: "string",
|
|
79
|
+
enum: ["char", "word", "sentence"],
|
|
80
|
+
description: "Break at character, word, or sentence boundary (default: word)"
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
required: ["text"]
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
name: "regex_replace",
|
|
88
|
+
description: "Find and replace text using regular expressions",
|
|
89
|
+
inputSchema: {
|
|
90
|
+
type: "object",
|
|
91
|
+
properties: {
|
|
92
|
+
text: { type: "string", description: "Input text" },
|
|
93
|
+
pattern: { type: "string", description: "Regex pattern to find" },
|
|
94
|
+
replacement: { type: "string", description: "Replacement string (supports $1, $2 capture groups)" },
|
|
95
|
+
flags: { type: "string", description: "Regex flags (default: g)" }
|
|
96
|
+
},
|
|
97
|
+
required: ["text", "pattern", "replacement"]
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
name: "markdown_strip",
|
|
102
|
+
description: "Strip markdown formatting to get plain text",
|
|
103
|
+
inputSchema: {
|
|
104
|
+
type: "object",
|
|
105
|
+
properties: {
|
|
106
|
+
text: { type: "string", description: "Markdown text to strip" }
|
|
107
|
+
},
|
|
108
|
+
required: ["text"]
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
name: "text_reverse",
|
|
113
|
+
description: "Reverse text — by characters, words, or lines",
|
|
114
|
+
inputSchema: {
|
|
115
|
+
type: "object",
|
|
116
|
+
properties: {
|
|
117
|
+
text: { type: "string", description: "Text to reverse" },
|
|
118
|
+
mode: {
|
|
119
|
+
type: "string",
|
|
120
|
+
enum: ["chars", "words", "lines"],
|
|
121
|
+
description: "Reverse by characters, words, or lines (default: chars)"
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
required: ["text"]
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
name: "line_sort",
|
|
129
|
+
description: "Sort lines of text alphabetically, numerically, by length, or randomly; remove duplicates",
|
|
130
|
+
inputSchema: {
|
|
131
|
+
type: "object",
|
|
132
|
+
properties: {
|
|
133
|
+
text: { type: "string", description: "Multi-line text to sort" },
|
|
134
|
+
order: {
|
|
135
|
+
type: "string",
|
|
136
|
+
enum: ["asc", "desc", "numeric", "length", "random"],
|
|
137
|
+
description: "Sort order (default: asc)"
|
|
138
|
+
},
|
|
139
|
+
unique: { type: "boolean", description: "Remove duplicate lines (default: false)" }
|
|
140
|
+
},
|
|
141
|
+
required: ["text"]
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
name: "text_diff",
|
|
146
|
+
description: "Compare two texts and show the differences line by line",
|
|
147
|
+
inputSchema: {
|
|
148
|
+
type: "object",
|
|
149
|
+
properties: {
|
|
150
|
+
text1: { type: "string", description: "First text" },
|
|
151
|
+
text2: { type: "string", description: "Second text" }
|
|
152
|
+
},
|
|
153
|
+
required: ["text1", "text2"]
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
]
|
|
157
|
+
};
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
// Helper: split text into words for case conversion
|
|
161
|
+
function splitWords(text) {
|
|
162
|
+
return text
|
|
163
|
+
.replace(/([a-z])([A-Z])/g, "$1 $2")
|
|
164
|
+
.replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2")
|
|
165
|
+
.replace(/[_\-\.]+/g, " ")
|
|
166
|
+
.trim()
|
|
167
|
+
.split(/\s+/)
|
|
168
|
+
.filter(w => w.length > 0);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// Lorem ipsum corpus
|
|
172
|
+
const LOREM_WORDS = "lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua ut enim ad minim veniam quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur excepteur sint occaecat cupidatat non proident sunt in culpa qui officia deserunt mollit anim id est laborum".split(" ");
|
|
173
|
+
|
|
174
|
+
function generateLoremWords(count) {
|
|
175
|
+
const words = [];
|
|
176
|
+
for (let i = 0; i < count; i++) {
|
|
177
|
+
words.push(LOREM_WORDS[i % LOREM_WORDS.length]);
|
|
178
|
+
}
|
|
179
|
+
words[0] = words[0].charAt(0).toUpperCase() + words[0].slice(1);
|
|
180
|
+
return words.join(" ");
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function generateLoremSentence() {
|
|
184
|
+
const len = 8 + Math.floor(Math.random() * 12);
|
|
185
|
+
const start = Math.floor(Math.random() * LOREM_WORDS.length);
|
|
186
|
+
const words = [];
|
|
187
|
+
for (let i = 0; i < len; i++) {
|
|
188
|
+
words.push(LOREM_WORDS[(start + i) % LOREM_WORDS.length]);
|
|
189
|
+
}
|
|
190
|
+
words[0] = words[0].charAt(0).toUpperCase() + words[0].slice(1);
|
|
191
|
+
return words.join(" ") + ".";
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function generateLoremParagraph() {
|
|
195
|
+
const sentenceCount = 3 + Math.floor(Math.random() * 4);
|
|
196
|
+
const sentences = [];
|
|
197
|
+
for (let i = 0; i < sentenceCount; i++) {
|
|
198
|
+
sentences.push(generateLoremSentence());
|
|
199
|
+
}
|
|
200
|
+
return sentences.join(" ");
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
204
|
+
const { name, arguments: args } = request.params;
|
|
205
|
+
|
|
206
|
+
try {
|
|
207
|
+
switch (name) {
|
|
208
|
+
case "case_convert": {
|
|
209
|
+
const { text, to } = args;
|
|
210
|
+
const words = splitWords(text);
|
|
211
|
+
let result;
|
|
212
|
+
switch (to) {
|
|
213
|
+
case "camel":
|
|
214
|
+
result = words.map((w, i) => i === 0 ? w.toLowerCase() : w.charAt(0).toUpperCase() + w.slice(1).toLowerCase()).join("");
|
|
215
|
+
break;
|
|
216
|
+
case "snake":
|
|
217
|
+
result = words.map(w => w.toLowerCase()).join("_");
|
|
218
|
+
break;
|
|
219
|
+
case "kebab":
|
|
220
|
+
result = words.map(w => w.toLowerCase()).join("-");
|
|
221
|
+
break;
|
|
222
|
+
case "pascal":
|
|
223
|
+
result = words.map(w => w.charAt(0).toUpperCase() + w.slice(1).toLowerCase()).join("");
|
|
224
|
+
break;
|
|
225
|
+
case "constant":
|
|
226
|
+
result = words.map(w => w.toUpperCase()).join("_");
|
|
227
|
+
break;
|
|
228
|
+
case "title":
|
|
229
|
+
result = words.map(w => w.charAt(0).toUpperCase() + w.slice(1).toLowerCase()).join(" ");
|
|
230
|
+
break;
|
|
231
|
+
case "dot":
|
|
232
|
+
result = words.map(w => w.toLowerCase()).join(".");
|
|
233
|
+
break;
|
|
234
|
+
default:
|
|
235
|
+
throw new Error(`Unknown case: ${to}`);
|
|
236
|
+
}
|
|
237
|
+
return { content: [{ type: "text", text: result }] };
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
case "slugify": {
|
|
241
|
+
const { text, separator = "-" } = args;
|
|
242
|
+
const slug = text
|
|
243
|
+
.toLowerCase()
|
|
244
|
+
.normalize("NFD")
|
|
245
|
+
.replace(/[\u0300-\u036f]/g, "")
|
|
246
|
+
.replace(/[^a-z0-9\s-]/g, "")
|
|
247
|
+
.trim()
|
|
248
|
+
.replace(/[\s-]+/g, separator);
|
|
249
|
+
return { content: [{ type: "text", text: slug }] };
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
case "word_count": {
|
|
253
|
+
const { text } = args;
|
|
254
|
+
const words = text.trim().split(/\s+/).filter(w => w.length > 0);
|
|
255
|
+
const chars = text.length;
|
|
256
|
+
const charsNoSpaces = text.replace(/\s/g, "").length;
|
|
257
|
+
const sentences = text.split(/[.!?]+/).filter(s => s.trim().length > 0).length;
|
|
258
|
+
const paragraphs = text.split(/\n\s*\n/).filter(p => p.trim().length > 0).length || 1;
|
|
259
|
+
const readingTimeMin = Math.ceil(words.length / 200);
|
|
260
|
+
const output = [
|
|
261
|
+
`Words: ${words.length}`,
|
|
262
|
+
`Characters: ${chars}`,
|
|
263
|
+
`Characters (no spaces): ${charsNoSpaces}`,
|
|
264
|
+
`Sentences: ${sentences}`,
|
|
265
|
+
`Paragraphs: ${paragraphs}`,
|
|
266
|
+
`Reading time: ~${readingTimeMin} min (at 200 wpm)`
|
|
267
|
+
];
|
|
268
|
+
return { content: [{ type: "text", text: output.join("\n") }] };
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
case "lorem_ipsum": {
|
|
272
|
+
const { count = 3, unit = "paragraphs" } = args || {};
|
|
273
|
+
const n = Math.min(Math.max(1, count), 50);
|
|
274
|
+
let result;
|
|
275
|
+
switch (unit) {
|
|
276
|
+
case "words":
|
|
277
|
+
result = generateLoremWords(n);
|
|
278
|
+
break;
|
|
279
|
+
case "sentences": {
|
|
280
|
+
const sentences = [];
|
|
281
|
+
for (let i = 0; i < n; i++) sentences.push(generateLoremSentence());
|
|
282
|
+
result = sentences.join(" ");
|
|
283
|
+
break;
|
|
284
|
+
}
|
|
285
|
+
case "paragraphs":
|
|
286
|
+
default: {
|
|
287
|
+
const paragraphs = [];
|
|
288
|
+
for (let i = 0; i < n; i++) paragraphs.push(generateLoremParagraph());
|
|
289
|
+
result = paragraphs.join("\n\n");
|
|
290
|
+
break;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
return { content: [{ type: "text", text: result }] };
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
case "truncate": {
|
|
297
|
+
const { text, length = 100, suffix = "...", boundary = "word" } = args;
|
|
298
|
+
if (text.length <= length) {
|
|
299
|
+
return { content: [{ type: "text", text }] };
|
|
300
|
+
}
|
|
301
|
+
const maxLen = length - suffix.length;
|
|
302
|
+
let result;
|
|
303
|
+
switch (boundary) {
|
|
304
|
+
case "char":
|
|
305
|
+
result = text.slice(0, maxLen) + suffix;
|
|
306
|
+
break;
|
|
307
|
+
case "sentence": {
|
|
308
|
+
const sentenceEnd = text.slice(0, maxLen).lastIndexOf(".");
|
|
309
|
+
result = sentenceEnd > 0 ? text.slice(0, sentenceEnd + 1) : text.slice(0, maxLen) + suffix;
|
|
310
|
+
break;
|
|
311
|
+
}
|
|
312
|
+
case "word":
|
|
313
|
+
default: {
|
|
314
|
+
const lastSpace = text.slice(0, maxLen).lastIndexOf(" ");
|
|
315
|
+
result = (lastSpace > 0 ? text.slice(0, lastSpace) : text.slice(0, maxLen)) + suffix;
|
|
316
|
+
break;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
return { content: [{ type: "text", text: `${result}\n\n(${text.length} → ${result.length} characters)` }] };
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
case "regex_replace": {
|
|
323
|
+
const { text, pattern, replacement, flags = "g" } = args;
|
|
324
|
+
const regex = new RegExp(pattern, flags);
|
|
325
|
+
const result = text.replace(regex, replacement);
|
|
326
|
+
const matchCount = (text.match(new RegExp(pattern, flags.includes("g") ? flags : flags + "g")) || []).length;
|
|
327
|
+
return {
|
|
328
|
+
content: [{ type: "text", text: `Replacements: ${matchCount}\n\n${result}` }]
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
case "markdown_strip": {
|
|
333
|
+
const { text } = args;
|
|
334
|
+
let result = text;
|
|
335
|
+
// Remove code blocks
|
|
336
|
+
result = result.replace(/```[\s\S]*?```/g, "");
|
|
337
|
+
result = result.replace(/`([^`]+)`/g, "$1");
|
|
338
|
+
// Remove images
|
|
339
|
+
result = result.replace(/!\[([^\]]*)\]\([^)]+\)/g, "$1");
|
|
340
|
+
// Remove links, keep text
|
|
341
|
+
result = result.replace(/\[([^\]]+)\]\([^)]+\)/g, "$1");
|
|
342
|
+
// Remove headings markers
|
|
343
|
+
result = result.replace(/^#{1,6}\s+/gm, "");
|
|
344
|
+
// Remove bold/italic
|
|
345
|
+
result = result.replace(/\*\*\*(.+?)\*\*\*/g, "$1");
|
|
346
|
+
result = result.replace(/\*\*(.+?)\*\*/g, "$1");
|
|
347
|
+
result = result.replace(/\*(.+?)\*/g, "$1");
|
|
348
|
+
result = result.replace(/___(.+?)___/g, "$1");
|
|
349
|
+
result = result.replace(/__(.+?)__/g, "$1");
|
|
350
|
+
result = result.replace(/_(.+?)_/g, "$1");
|
|
351
|
+
// Remove strikethrough
|
|
352
|
+
result = result.replace(/~~(.+?)~~/g, "$1");
|
|
353
|
+
// Remove blockquotes
|
|
354
|
+
result = result.replace(/^>\s?/gm, "");
|
|
355
|
+
// Remove horizontal rules
|
|
356
|
+
result = result.replace(/^[-*_]{3,}\s*$/gm, "");
|
|
357
|
+
// Remove list markers
|
|
358
|
+
result = result.replace(/^[\s]*[-*+]\s+/gm, "");
|
|
359
|
+
result = result.replace(/^[\s]*\d+\.\s+/gm, "");
|
|
360
|
+
// Remove HTML tags
|
|
361
|
+
result = result.replace(/<[^>]+>/g, "");
|
|
362
|
+
// Collapse multiple blank lines
|
|
363
|
+
result = result.replace(/\n{3,}/g, "\n\n");
|
|
364
|
+
return { content: [{ type: "text", text: result.trim() }] };
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
case "text_reverse": {
|
|
368
|
+
const { text, mode = "chars" } = args;
|
|
369
|
+
let result;
|
|
370
|
+
switch (mode) {
|
|
371
|
+
case "words":
|
|
372
|
+
result = text.split(/\s+/).reverse().join(" ");
|
|
373
|
+
break;
|
|
374
|
+
case "lines":
|
|
375
|
+
result = text.split("\n").reverse().join("\n");
|
|
376
|
+
break;
|
|
377
|
+
case "chars":
|
|
378
|
+
default:
|
|
379
|
+
result = [...text].reverse().join("");
|
|
380
|
+
break;
|
|
381
|
+
}
|
|
382
|
+
return { content: [{ type: "text", text: result }] };
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
case "line_sort": {
|
|
386
|
+
const { text, order = "asc", unique = false } = args;
|
|
387
|
+
let lines = text.split("\n");
|
|
388
|
+
if (unique) {
|
|
389
|
+
lines = [...new Set(lines)];
|
|
390
|
+
}
|
|
391
|
+
switch (order) {
|
|
392
|
+
case "desc":
|
|
393
|
+
lines.sort((a, b) => b.localeCompare(a));
|
|
394
|
+
break;
|
|
395
|
+
case "numeric":
|
|
396
|
+
lines.sort((a, b) => {
|
|
397
|
+
const na = parseFloat(a) || 0;
|
|
398
|
+
const nb = parseFloat(b) || 0;
|
|
399
|
+
return na - nb;
|
|
400
|
+
});
|
|
401
|
+
break;
|
|
402
|
+
case "length":
|
|
403
|
+
lines.sort((a, b) => a.length - b.length);
|
|
404
|
+
break;
|
|
405
|
+
case "random":
|
|
406
|
+
for (let i = lines.length - 1; i > 0; i--) {
|
|
407
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
408
|
+
[lines[i], lines[j]] = [lines[j], lines[i]];
|
|
409
|
+
}
|
|
410
|
+
break;
|
|
411
|
+
case "asc":
|
|
412
|
+
default:
|
|
413
|
+
lines.sort((a, b) => a.localeCompare(b));
|
|
414
|
+
break;
|
|
415
|
+
}
|
|
416
|
+
return { content: [{ type: "text", text: lines.join("\n") }] };
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
case "text_diff": {
|
|
420
|
+
const { text1, text2 } = args;
|
|
421
|
+
const lines1 = text1.split("\n");
|
|
422
|
+
const lines2 = text2.split("\n");
|
|
423
|
+
const maxLen = Math.max(lines1.length, lines2.length);
|
|
424
|
+
const output = [];
|
|
425
|
+
let added = 0, removed = 0, unchanged = 0;
|
|
426
|
+
|
|
427
|
+
for (let i = 0; i < maxLen; i++) {
|
|
428
|
+
const l1 = i < lines1.length ? lines1[i] : undefined;
|
|
429
|
+
const l2 = i < lines2.length ? lines2[i] : undefined;
|
|
430
|
+
|
|
431
|
+
if (l1 === l2) {
|
|
432
|
+
output.push(` ${l1}`);
|
|
433
|
+
unchanged++;
|
|
434
|
+
} else {
|
|
435
|
+
if (l1 !== undefined) {
|
|
436
|
+
output.push(`- ${l1}`);
|
|
437
|
+
removed++;
|
|
438
|
+
}
|
|
439
|
+
if (l2 !== undefined) {
|
|
440
|
+
output.push(`+ ${l2}`);
|
|
441
|
+
added++;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
const summary = `\n---\nLines: ${added} added, ${removed} removed, ${unchanged} unchanged`;
|
|
447
|
+
return { content: [{ type: "text", text: output.join("\n") + summary }] };
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
default:
|
|
451
|
+
throw new Error(`Unknown tool: ${name}`);
|
|
452
|
+
}
|
|
453
|
+
} catch (error) {
|
|
454
|
+
return {
|
|
455
|
+
content: [{ type: "text", text: `Error: ${error.message}` }],
|
|
456
|
+
isError: true
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
const transport = new StdioServerTransport();
|
|
462
|
+
await server.connect(transport);
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mcp-texttools",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "MCP server with 10 text transformation tools — case conversion, slug, word count, lorem ipsum, truncate, regex replace, markdown strip, character count, reverse, line sort",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"bin": {
|
|
8
|
+
"mcp-texttools": "index.js"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"start": "node index.js"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"mcp",
|
|
15
|
+
"model-context-protocol",
|
|
16
|
+
"text-tools",
|
|
17
|
+
"text-transform",
|
|
18
|
+
"case-convert",
|
|
19
|
+
"slugify",
|
|
20
|
+
"word-count",
|
|
21
|
+
"lorem-ipsum",
|
|
22
|
+
"markdown",
|
|
23
|
+
"developer-tools",
|
|
24
|
+
"claude",
|
|
25
|
+
"cursor",
|
|
26
|
+
"ai-tools",
|
|
27
|
+
"string-utils"
|
|
28
|
+
],
|
|
29
|
+
"author": "Hong Teoh",
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"funding": {
|
|
32
|
+
"type": "buymeacoffee",
|
|
33
|
+
"url": "https://buymeacoffee.com/gl89tu25lp"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@modelcontextprotocol/sdk": "^1.0.0"
|
|
37
|
+
}
|
|
38
|
+
}
|