lingual-mcp 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 +47 -2
- package/bin/lingual-mcp.js +8 -0
- package/dist/index.cjs +419 -0
- package/dist/index.d.cts +14 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +407 -0
- package/package.json +64 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jason Song
|
|
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,48 @@
|
|
|
1
|
-
#
|
|
1
|
+
# lingual-mcp
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Universal Model Context Protocol (MCP) server powered by [`pi-lingual`](https://github.com/3ZEROS12/pi-lingual) (`pi-lingual/core`).
|
|
4
|
+
|
|
5
|
+
Works with **Claude Code**, **Claude Desktop**, **Cursor**, **Windsurf**, **Cline**, and any MCP client — with both **Zero-Key Template Mode** (no API key needed) and **Direct Endpoint Mode** (`OPENAI_BASE_URL` / `LINGUAL_ENDPOINT`).
|
|
6
|
+
|
|
7
|
+
## Quick Setup
|
|
8
|
+
|
|
9
|
+
Not published to npm yet, so point the client at this checkout (the built `dist/` is produced by `npm run build`):
|
|
10
|
+
|
|
11
|
+
```json
|
|
12
|
+
{
|
|
13
|
+
"mcpServers": {
|
|
14
|
+
"lingual": {
|
|
15
|
+
"command": "node",
|
|
16
|
+
"args": ["D:/Workspace/projects/active/lingual-mcp/bin/lingual-mcp.js"]
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Once the package is on npm, the same entry collapses to `"command": "npx", "args": ["-y", "lingual-mcp"]`.
|
|
23
|
+
|
|
24
|
+
Verify a local build before wiring it up:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm install && npm run check # typecheck + MCP protocol tests
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Tools and Prompts
|
|
31
|
+
|
|
32
|
+
| Kind | Name | Arguments | Purpose |
|
|
33
|
+
| :--- | :--- | :--- | :--- |
|
|
34
|
+
| tool | `lingual_transform_spec` | `text`, `loadout` (`spec` / `commit` / `oss` / `yap` / `direct`), `sourceLang?`, `targetLang?` | Turns messy native-language thought into a structured spec, a Conventional Commit, maintainer peer comms, a dense tech post, or a direct technical-English rewrite, leaving code blocks and stack traces untouched. |
|
|
35
|
+
| tool | `lingual_bilingual_companion` | `text`, `sourceLang?`, `targetLang?` | Dual-register phrasing (spoken vs. written), native nuance, and key vocabulary callouts. |
|
|
36
|
+
| tool | `lingual_prompt_template` | `loadout`, `sourceLang?`, `targetLang?` | Zero-key mode: returns the compiled system prompt and few-shot rules for a loadout so the host agent executes it with its own model. |
|
|
37
|
+
| prompt | `spec_prompt` | `raw_idea`, `source_lang?`, `target_lang?` | Reusable prompt that structures a raw idea into a specification. |
|
|
38
|
+
| prompt | `conventional_commit` | `changes_summary`, `source_lang?`, `target_lang?` | Reusable prompt that turns a change summary into a Conventional Commit message. |
|
|
39
|
+
|
|
40
|
+
### Optional Environment Variables (for server-side LLM execution)
|
|
41
|
+
|
|
42
|
+
| Variable | Description |
|
|
43
|
+
| :--- | :--- |
|
|
44
|
+
| `LINGUAL_ENDPOINT` / `OPENAI_BASE_URL` | OpenAI-compatible base URL (e.g. `https://api.openai.com/v1` or `http://127.0.0.1:3425/v1`) |
|
|
45
|
+
| `LINGUAL_API_KEY` / `OPENAI_API_KEY` | API key (loopback endpoints default to `"local"` if omitted) |
|
|
46
|
+
| `LINGUAL_MODEL` / `OPENAI_MODEL` | Model ID (default: `gpt-4o-mini`) |
|
|
47
|
+
|
|
48
|
+
If no external credentials are set, `lingual_prompt_template`, MCP `prompts` (`spec_prompt`, `conventional_commit`), and the `unconfigured_zero_key_fallback` mode still work out of the box using your host agent's own LLM.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
createLingualMcpServer: () => createLingualMcpServer,
|
|
24
|
+
resolveMcpLlmConfig: () => resolveMcpLlmConfig,
|
|
25
|
+
runLingualMcpServer: () => runLingualMcpServer
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(index_exports);
|
|
28
|
+
var import_server = require("@modelcontextprotocol/sdk/server/index.js");
|
|
29
|
+
var import_stdio = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
30
|
+
var import_types = require("@modelcontextprotocol/sdk/types.js");
|
|
31
|
+
var import_core = require("pi-lingual/core");
|
|
32
|
+
var PKG_VERSION = "0.1.0";
|
|
33
|
+
function isLoopbackUrl(urlStr) {
|
|
34
|
+
try {
|
|
35
|
+
const parsed = new URL(urlStr);
|
|
36
|
+
return parsed.hostname === "127.0.0.1" || parsed.hostname === "localhost" || parsed.hostname === "::1";
|
|
37
|
+
} catch {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function resolveMcpLlmConfig(diskConfig, env = process.env) {
|
|
42
|
+
const rawEndpoint = env.LINGUAL_ENDPOINT || env.OPENAI_BASE_URL || diskConfig.endpoint;
|
|
43
|
+
const rawApiKey = env.LINGUAL_API_KEY || env.OPENAI_API_KEY || diskConfig.apiKey;
|
|
44
|
+
const rawModel = env.LINGUAL_MODEL || env.OPENAI_MODEL || diskConfig.model;
|
|
45
|
+
if (!rawEndpoint && !rawApiKey) {
|
|
46
|
+
return { configured: false };
|
|
47
|
+
}
|
|
48
|
+
const base = (rawEndpoint || "https://api.openai.com/v1").replace(/\/+$/, "");
|
|
49
|
+
const endpoint = base.endsWith("/chat/completions") ? base : `${base}/chat/completions`;
|
|
50
|
+
const apiKey = rawApiKey || (isLoopbackUrl(endpoint) ? "local" : void 0);
|
|
51
|
+
if (!apiKey) {
|
|
52
|
+
return { configured: false };
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
configured: true,
|
|
56
|
+
endpoint,
|
|
57
|
+
apiKey,
|
|
58
|
+
model: rawModel || "gpt-4o-mini"
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function createLingualMcpServer() {
|
|
62
|
+
const server = new import_server.Server(
|
|
63
|
+
{
|
|
64
|
+
name: "lingual-mcp",
|
|
65
|
+
version: PKG_VERSION
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
capabilities: {
|
|
69
|
+
tools: {},
|
|
70
|
+
prompts: {}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
);
|
|
74
|
+
server.setRequestHandler(import_types.ListToolsRequestSchema, async () => {
|
|
75
|
+
return {
|
|
76
|
+
tools: [
|
|
77
|
+
{
|
|
78
|
+
name: "lingual_transform_spec",
|
|
79
|
+
description: "Transform messy native-language thoughts or instructions into crisp, structured engineering specifications, conventional commits, or OSS maintainer peer comms while keeping code blocks & stack traces 100% untouched.",
|
|
80
|
+
inputSchema: {
|
|
81
|
+
type: "object",
|
|
82
|
+
properties: {
|
|
83
|
+
text: {
|
|
84
|
+
type: "string",
|
|
85
|
+
description: "The raw thought, feature requirement, issue draft, or commit message in any language."
|
|
86
|
+
},
|
|
87
|
+
loadout: {
|
|
88
|
+
type: "string",
|
|
89
|
+
enum: ["spec", "commit", "oss", "yap", "direct"],
|
|
90
|
+
description: "Preset loadout: 'spec' (structured engineering specification), 'commit' (conventional commit <=72 chars), 'oss' (maintainer peer issue/PR feedback), 'yap' (high-density tech post for X/HN), 'direct' (rewrite into clean technical English, keeping code blocks and stack traces intact). Default: 'spec'.",
|
|
91
|
+
default: "spec"
|
|
92
|
+
},
|
|
93
|
+
sourceLang: {
|
|
94
|
+
type: "string",
|
|
95
|
+
description: "Source language code (e.g. 'zh', 'ja', 'en', 'es'). Auto-detected if omitted."
|
|
96
|
+
},
|
|
97
|
+
targetLang: {
|
|
98
|
+
type: "string",
|
|
99
|
+
description: "Target language code (e.g. 'en', 'ja', 'zh'). Default: 'en'.",
|
|
100
|
+
default: "en"
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
required: ["text"]
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
name: "lingual_bilingual_companion",
|
|
108
|
+
description: "Generate dual-register phrasing (Spoken for Slack/standups vs. Written for RFCs/PRs), native nuance meanings, and key vocabulary highlights for any technical expression or thought.",
|
|
109
|
+
inputSchema: {
|
|
110
|
+
type: "object",
|
|
111
|
+
properties: {
|
|
112
|
+
text: {
|
|
113
|
+
type: "string",
|
|
114
|
+
description: "The natural language text or expression to unpack into technical dual-registers."
|
|
115
|
+
},
|
|
116
|
+
sourceLang: {
|
|
117
|
+
type: "string",
|
|
118
|
+
description: "Source language code (e.g. 'zh', 'ja'). Auto-detected if omitted."
|
|
119
|
+
},
|
|
120
|
+
targetLang: {
|
|
121
|
+
type: "string",
|
|
122
|
+
description: "Target language code (e.g. 'en', 'ja'). Default: 'en'.",
|
|
123
|
+
default: "en"
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
required: ["text"]
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
name: "lingual_prompt_template",
|
|
131
|
+
description: "Zero-key mode: extract the exact compiled system prompt and few-shot rules for any Lingual mode so the host agent can execute it directly without external API credentials.",
|
|
132
|
+
inputSchema: {
|
|
133
|
+
type: "object",
|
|
134
|
+
properties: {
|
|
135
|
+
loadout: {
|
|
136
|
+
type: "string",
|
|
137
|
+
enum: ["spec", "commit", "oss", "yap", "direct", "companion"],
|
|
138
|
+
description: "Target mode or loadout.",
|
|
139
|
+
default: "spec"
|
|
140
|
+
},
|
|
141
|
+
sourceLang: {
|
|
142
|
+
type: "string",
|
|
143
|
+
description: "Source language code (e.g. 'zh', 'ja', 'en'). Default: 'zh'.",
|
|
144
|
+
default: "zh"
|
|
145
|
+
},
|
|
146
|
+
targetLang: {
|
|
147
|
+
type: "string",
|
|
148
|
+
description: "Target language code (e.g. 'en', 'ja'). Default: 'en'.",
|
|
149
|
+
default: "en"
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
required: ["loadout"]
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
]
|
|
156
|
+
};
|
|
157
|
+
});
|
|
158
|
+
server.setRequestHandler(import_types.CallToolRequestSchema, async (request) => {
|
|
159
|
+
const { name, arguments: args } = request.params;
|
|
160
|
+
const diskConfig = (0, import_core.loadUserLingualConfig)();
|
|
161
|
+
const llm = resolveMcpLlmConfig(diskConfig);
|
|
162
|
+
if (name === "lingual_transform_spec") {
|
|
163
|
+
const text = String(args?.text || "");
|
|
164
|
+
const loadoutId = String(args?.loadout || "spec");
|
|
165
|
+
const targetLang = String(args?.targetLang || "en");
|
|
166
|
+
const sourceLang = args?.sourceLang ? String(args.sourceLang) : (0, import_core.detectScriptLanguage)(text) || diskConfig.sourceLang || "zh";
|
|
167
|
+
const preset = (0, import_core.getPresetLoadout)(loadoutId, sourceLang);
|
|
168
|
+
if (!preset) {
|
|
169
|
+
return {
|
|
170
|
+
isError: true,
|
|
171
|
+
content: [{ type: "text", text: `Unknown loadout preset: ${loadoutId}` }]
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
const sanitized = (0, import_core.sanitizePromptForTranslation)(text);
|
|
175
|
+
const inputToTransform = sanitized.distilledText || text;
|
|
176
|
+
if (!llm.configured) {
|
|
177
|
+
return {
|
|
178
|
+
content: [
|
|
179
|
+
{
|
|
180
|
+
type: "text",
|
|
181
|
+
text: JSON.stringify(
|
|
182
|
+
{
|
|
183
|
+
status: "unconfigured_zero_key_fallback",
|
|
184
|
+
message: "No external LLM credentials configured (set LINGUAL_ENDPOINT / OPENAI_BASE_URL and LINGUAL_API_KEY / OPENAI_API_KEY, or configure ~/.pi/agent/lingual.json). Use the compiledSystemPrompt below directly in your host agent.",
|
|
185
|
+
loadout: loadoutId,
|
|
186
|
+
distilledInput: inputToTransform,
|
|
187
|
+
compiledSystemPrompt: (0, import_core.compileModeSystemPrompt)(preset, { sourceLang, targetLang })
|
|
188
|
+
},
|
|
189
|
+
null,
|
|
190
|
+
2
|
|
191
|
+
)
|
|
192
|
+
}
|
|
193
|
+
]
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
try {
|
|
197
|
+
const candidates = await (0, import_core.executeModeRunner)(inputToTransform, preset, {
|
|
198
|
+
endpoint: llm.endpoint,
|
|
199
|
+
apiKey: llm.apiKey,
|
|
200
|
+
model: llm.model,
|
|
201
|
+
sourceLang,
|
|
202
|
+
targetLang
|
|
203
|
+
});
|
|
204
|
+
if (!candidates || candidates.length === 0) {
|
|
205
|
+
return {
|
|
206
|
+
content: [
|
|
207
|
+
{
|
|
208
|
+
type: "text",
|
|
209
|
+
text: JSON.stringify(
|
|
210
|
+
{
|
|
211
|
+
status: "fallback",
|
|
212
|
+
message: "LLM endpoint did not return transformed candidates; returning original input.",
|
|
213
|
+
transformed: text
|
|
214
|
+
},
|
|
215
|
+
null,
|
|
216
|
+
2
|
|
217
|
+
)
|
|
218
|
+
}
|
|
219
|
+
]
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
const primary = candidates[0];
|
|
223
|
+
const finalTransformed = sanitized.rawPayload ? (0, import_core.ensureCodeTokensPreserved)(sanitized.rawPayload, primary.content) : primary.content;
|
|
224
|
+
return {
|
|
225
|
+
content: [
|
|
226
|
+
{
|
|
227
|
+
type: "text",
|
|
228
|
+
text: JSON.stringify(
|
|
229
|
+
{
|
|
230
|
+
status: "success",
|
|
231
|
+
loadout: loadoutId,
|
|
232
|
+
transformed: finalTransformed,
|
|
233
|
+
explanation: primary.explanation,
|
|
234
|
+
vocab: primary.vocab,
|
|
235
|
+
sourceText: text
|
|
236
|
+
},
|
|
237
|
+
null,
|
|
238
|
+
2
|
|
239
|
+
)
|
|
240
|
+
}
|
|
241
|
+
]
|
|
242
|
+
};
|
|
243
|
+
} catch (err) {
|
|
244
|
+
return {
|
|
245
|
+
isError: true,
|
|
246
|
+
content: [{ type: "text", text: `Transformation failed: ${err?.message || String(err)}` }]
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
if (name === "lingual_bilingual_companion") {
|
|
251
|
+
const text = String(args?.text || "");
|
|
252
|
+
const targetLang = String(args?.targetLang || "en");
|
|
253
|
+
const sourceLang = args?.sourceLang ? String(args.sourceLang) : (0, import_core.detectScriptLanguage)(text) || diskConfig.sourceLang || "zh";
|
|
254
|
+
if (!llm.configured) {
|
|
255
|
+
return {
|
|
256
|
+
content: [
|
|
257
|
+
{
|
|
258
|
+
type: "text",
|
|
259
|
+
text: JSON.stringify(
|
|
260
|
+
{
|
|
261
|
+
status: "unconfigured_zero_key_fallback",
|
|
262
|
+
message: "No external LLM credentials configured (set LINGUAL_ENDPOINT / OPENAI_BASE_URL and LINGUAL_API_KEY / OPENAI_API_KEY). Use compiledSystemPrompt in your host agent.",
|
|
263
|
+
compiledSystemPrompt: (0, import_core.buildSystemPrompt)(sourceLang, targetLang),
|
|
264
|
+
sourceText: text
|
|
265
|
+
},
|
|
266
|
+
null,
|
|
267
|
+
2
|
|
268
|
+
)
|
|
269
|
+
}
|
|
270
|
+
]
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
try {
|
|
274
|
+
const result = await (0, import_core.translatePrompt)(text, {
|
|
275
|
+
endpoint: llm.endpoint,
|
|
276
|
+
apiKey: llm.apiKey,
|
|
277
|
+
model: llm.model,
|
|
278
|
+
sourceLang,
|
|
279
|
+
targetLang
|
|
280
|
+
});
|
|
281
|
+
if (!result) {
|
|
282
|
+
return {
|
|
283
|
+
content: [
|
|
284
|
+
{
|
|
285
|
+
type: "text",
|
|
286
|
+
text: JSON.stringify(
|
|
287
|
+
{
|
|
288
|
+
status: "empty",
|
|
289
|
+
message: "No translation generated (input might be pure code or bypassed by shield).",
|
|
290
|
+
sourceText: text
|
|
291
|
+
},
|
|
292
|
+
null,
|
|
293
|
+
2
|
|
294
|
+
)
|
|
295
|
+
}
|
|
296
|
+
]
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
return {
|
|
300
|
+
content: [
|
|
301
|
+
{
|
|
302
|
+
type: "text",
|
|
303
|
+
text: JSON.stringify(
|
|
304
|
+
{
|
|
305
|
+
status: "success",
|
|
306
|
+
spoken: result.spoken,
|
|
307
|
+
nativeSpoken: result.nativeSpoken,
|
|
308
|
+
written: result.written,
|
|
309
|
+
nativeWritten: result.nativeWritten,
|
|
310
|
+
vocab: result.vocab,
|
|
311
|
+
sourceText: result.original
|
|
312
|
+
},
|
|
313
|
+
null,
|
|
314
|
+
2
|
|
315
|
+
)
|
|
316
|
+
}
|
|
317
|
+
]
|
|
318
|
+
};
|
|
319
|
+
} catch (err) {
|
|
320
|
+
return {
|
|
321
|
+
isError: true,
|
|
322
|
+
content: [{ type: "text", text: `Companion mapping failed: ${err?.message || String(err)}` }]
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
if (name === "lingual_prompt_template") {
|
|
327
|
+
const loadoutId = String(args?.loadout || "spec");
|
|
328
|
+
const sourceLang = String(args?.sourceLang || "zh");
|
|
329
|
+
const targetLang = String(args?.targetLang || "en");
|
|
330
|
+
if (loadoutId === "companion") {
|
|
331
|
+
return {
|
|
332
|
+
content: [{ type: "text", text: (0, import_core.buildSystemPrompt)(sourceLang, targetLang) }]
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
const preset = (0, import_core.getPresetLoadout)(loadoutId, sourceLang);
|
|
336
|
+
if (!preset) {
|
|
337
|
+
return {
|
|
338
|
+
isError: true,
|
|
339
|
+
content: [{ type: "text", text: `Unknown loadout preset: ${loadoutId}` }]
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
return {
|
|
343
|
+
content: [{ type: "text", text: (0, import_core.compileModeSystemPrompt)(preset, { sourceLang, targetLang }) }]
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
return {
|
|
347
|
+
isError: true,
|
|
348
|
+
content: [{ type: "text", text: `Unknown tool name: ${name}` }]
|
|
349
|
+
};
|
|
350
|
+
});
|
|
351
|
+
server.setRequestHandler(import_types.ListPromptsRequestSchema, async () => {
|
|
352
|
+
return {
|
|
353
|
+
prompts: [
|
|
354
|
+
{
|
|
355
|
+
name: "spec_prompt",
|
|
356
|
+
description: "Structure raw developer instructions into a rigorous technical specification.",
|
|
357
|
+
arguments: [
|
|
358
|
+
{ name: "raw_idea", description: "The raw thought or instruction to structure.", required: true },
|
|
359
|
+
{ name: "source_lang", description: "Optional source language code (default: auto/zh).", required: false },
|
|
360
|
+
{ name: "target_lang", description: "Optional target language code (default: en).", required: false }
|
|
361
|
+
]
|
|
362
|
+
},
|
|
363
|
+
{
|
|
364
|
+
name: "conventional_commit",
|
|
365
|
+
description: "Dehydrate plain explanation into a Conventional Commit (first line <= 72 chars).",
|
|
366
|
+
arguments: [
|
|
367
|
+
{ name: "changes_summary", description: "Description of what was changed and why.", required: true },
|
|
368
|
+
{ name: "source_lang", description: "Optional source language code (default: auto/zh).", required: false },
|
|
369
|
+
{ name: "target_lang", description: "Optional target language code (default: en).", required: false }
|
|
370
|
+
]
|
|
371
|
+
}
|
|
372
|
+
]
|
|
373
|
+
};
|
|
374
|
+
});
|
|
375
|
+
server.setRequestHandler(import_types.GetPromptRequestSchema, async (request) => {
|
|
376
|
+
const { name, arguments: args } = request.params;
|
|
377
|
+
const sourceLang = args?.source_lang || "zh";
|
|
378
|
+
const targetLang = args?.target_lang || "en";
|
|
379
|
+
if (name === "spec_prompt") {
|
|
380
|
+
const idea = args?.raw_idea || "";
|
|
381
|
+
const sys = (0, import_core.compileModeSystemPrompt)((0, import_core.getPresetLoadout)("spec", sourceLang), { sourceLang, targetLang });
|
|
382
|
+
return {
|
|
383
|
+
description: "Transform idea into an engineering specification",
|
|
384
|
+
messages: [
|
|
385
|
+
{ role: "user", content: { type: "text", text: `${sys}
|
|
386
|
+
|
|
387
|
+
Task to structure:
|
|
388
|
+
${idea}` } }
|
|
389
|
+
]
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
if (name === "conventional_commit") {
|
|
393
|
+
const summary = args?.changes_summary || "";
|
|
394
|
+
const sys = (0, import_core.compileModeSystemPrompt)((0, import_core.getPresetLoadout)("commit", sourceLang), { sourceLang, targetLang });
|
|
395
|
+
return {
|
|
396
|
+
description: "Transform change summary into Conventional Commit",
|
|
397
|
+
messages: [
|
|
398
|
+
{ role: "user", content: { type: "text", text: `${sys}
|
|
399
|
+
|
|
400
|
+
Changes to commit:
|
|
401
|
+
${summary}` } }
|
|
402
|
+
]
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
throw new Error(`Prompt not found: ${name}`);
|
|
406
|
+
});
|
|
407
|
+
return server;
|
|
408
|
+
}
|
|
409
|
+
async function runLingualMcpServer() {
|
|
410
|
+
const server = createLingualMcpServer();
|
|
411
|
+
const transport = new import_stdio.StdioServerTransport();
|
|
412
|
+
await server.connect(transport);
|
|
413
|
+
}
|
|
414
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
415
|
+
0 && (module.exports = {
|
|
416
|
+
createLingualMcpServer,
|
|
417
|
+
resolveMcpLlmConfig,
|
|
418
|
+
runLingualMcpServer
|
|
419
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
2
|
+
import { LingualConfig } from 'pi-lingual/core';
|
|
3
|
+
|
|
4
|
+
interface ResolvedMcpLlmConfig {
|
|
5
|
+
configured: boolean;
|
|
6
|
+
endpoint?: string;
|
|
7
|
+
apiKey?: string;
|
|
8
|
+
model?: string;
|
|
9
|
+
}
|
|
10
|
+
declare function resolveMcpLlmConfig(diskConfig: Partial<LingualConfig>, env?: NodeJS.ProcessEnv): ResolvedMcpLlmConfig;
|
|
11
|
+
declare function createLingualMcpServer(): Server;
|
|
12
|
+
declare function runLingualMcpServer(): Promise<void>;
|
|
13
|
+
|
|
14
|
+
export { type ResolvedMcpLlmConfig, createLingualMcpServer, resolveMcpLlmConfig, runLingualMcpServer };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
2
|
+
import { LingualConfig } from 'pi-lingual/core';
|
|
3
|
+
|
|
4
|
+
interface ResolvedMcpLlmConfig {
|
|
5
|
+
configured: boolean;
|
|
6
|
+
endpoint?: string;
|
|
7
|
+
apiKey?: string;
|
|
8
|
+
model?: string;
|
|
9
|
+
}
|
|
10
|
+
declare function resolveMcpLlmConfig(diskConfig: Partial<LingualConfig>, env?: NodeJS.ProcessEnv): ResolvedMcpLlmConfig;
|
|
11
|
+
declare function createLingualMcpServer(): Server;
|
|
12
|
+
declare function runLingualMcpServer(): Promise<void>;
|
|
13
|
+
|
|
14
|
+
export { type ResolvedMcpLlmConfig, createLingualMcpServer, resolveMcpLlmConfig, runLingualMcpServer };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
3
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
|
+
import {
|
|
5
|
+
CallToolRequestSchema,
|
|
6
|
+
ListToolsRequestSchema,
|
|
7
|
+
ListPromptsRequestSchema,
|
|
8
|
+
GetPromptRequestSchema
|
|
9
|
+
} from "@modelcontextprotocol/sdk/types.js";
|
|
10
|
+
import {
|
|
11
|
+
translatePrompt,
|
|
12
|
+
executeModeRunner,
|
|
13
|
+
compileModeSystemPrompt,
|
|
14
|
+
loadUserLingualConfig,
|
|
15
|
+
getPresetLoadout,
|
|
16
|
+
buildSystemPrompt,
|
|
17
|
+
sanitizePromptForTranslation,
|
|
18
|
+
ensureCodeTokensPreserved,
|
|
19
|
+
detectScriptLanguage
|
|
20
|
+
} from "pi-lingual/core";
|
|
21
|
+
var PKG_VERSION = "0.1.0";
|
|
22
|
+
function isLoopbackUrl(urlStr) {
|
|
23
|
+
try {
|
|
24
|
+
const parsed = new URL(urlStr);
|
|
25
|
+
return parsed.hostname === "127.0.0.1" || parsed.hostname === "localhost" || parsed.hostname === "::1";
|
|
26
|
+
} catch {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function resolveMcpLlmConfig(diskConfig, env = process.env) {
|
|
31
|
+
const rawEndpoint = env.LINGUAL_ENDPOINT || env.OPENAI_BASE_URL || diskConfig.endpoint;
|
|
32
|
+
const rawApiKey = env.LINGUAL_API_KEY || env.OPENAI_API_KEY || diskConfig.apiKey;
|
|
33
|
+
const rawModel = env.LINGUAL_MODEL || env.OPENAI_MODEL || diskConfig.model;
|
|
34
|
+
if (!rawEndpoint && !rawApiKey) {
|
|
35
|
+
return { configured: false };
|
|
36
|
+
}
|
|
37
|
+
const base = (rawEndpoint || "https://api.openai.com/v1").replace(/\/+$/, "");
|
|
38
|
+
const endpoint = base.endsWith("/chat/completions") ? base : `${base}/chat/completions`;
|
|
39
|
+
const apiKey = rawApiKey || (isLoopbackUrl(endpoint) ? "local" : void 0);
|
|
40
|
+
if (!apiKey) {
|
|
41
|
+
return { configured: false };
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
configured: true,
|
|
45
|
+
endpoint,
|
|
46
|
+
apiKey,
|
|
47
|
+
model: rawModel || "gpt-4o-mini"
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function createLingualMcpServer() {
|
|
51
|
+
const server = new Server(
|
|
52
|
+
{
|
|
53
|
+
name: "lingual-mcp",
|
|
54
|
+
version: PKG_VERSION
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
capabilities: {
|
|
58
|
+
tools: {},
|
|
59
|
+
prompts: {}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
);
|
|
63
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
64
|
+
return {
|
|
65
|
+
tools: [
|
|
66
|
+
{
|
|
67
|
+
name: "lingual_transform_spec",
|
|
68
|
+
description: "Transform messy native-language thoughts or instructions into crisp, structured engineering specifications, conventional commits, or OSS maintainer peer comms while keeping code blocks & stack traces 100% untouched.",
|
|
69
|
+
inputSchema: {
|
|
70
|
+
type: "object",
|
|
71
|
+
properties: {
|
|
72
|
+
text: {
|
|
73
|
+
type: "string",
|
|
74
|
+
description: "The raw thought, feature requirement, issue draft, or commit message in any language."
|
|
75
|
+
},
|
|
76
|
+
loadout: {
|
|
77
|
+
type: "string",
|
|
78
|
+
enum: ["spec", "commit", "oss", "yap", "direct"],
|
|
79
|
+
description: "Preset loadout: 'spec' (structured engineering specification), 'commit' (conventional commit <=72 chars), 'oss' (maintainer peer issue/PR feedback), 'yap' (high-density tech post for X/HN), 'direct' (rewrite into clean technical English, keeping code blocks and stack traces intact). Default: 'spec'.",
|
|
80
|
+
default: "spec"
|
|
81
|
+
},
|
|
82
|
+
sourceLang: {
|
|
83
|
+
type: "string",
|
|
84
|
+
description: "Source language code (e.g. 'zh', 'ja', 'en', 'es'). Auto-detected if omitted."
|
|
85
|
+
},
|
|
86
|
+
targetLang: {
|
|
87
|
+
type: "string",
|
|
88
|
+
description: "Target language code (e.g. 'en', 'ja', 'zh'). Default: 'en'.",
|
|
89
|
+
default: "en"
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
required: ["text"]
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
name: "lingual_bilingual_companion",
|
|
97
|
+
description: "Generate dual-register phrasing (Spoken for Slack/standups vs. Written for RFCs/PRs), native nuance meanings, and key vocabulary highlights for any technical expression or thought.",
|
|
98
|
+
inputSchema: {
|
|
99
|
+
type: "object",
|
|
100
|
+
properties: {
|
|
101
|
+
text: {
|
|
102
|
+
type: "string",
|
|
103
|
+
description: "The natural language text or expression to unpack into technical dual-registers."
|
|
104
|
+
},
|
|
105
|
+
sourceLang: {
|
|
106
|
+
type: "string",
|
|
107
|
+
description: "Source language code (e.g. 'zh', 'ja'). Auto-detected if omitted."
|
|
108
|
+
},
|
|
109
|
+
targetLang: {
|
|
110
|
+
type: "string",
|
|
111
|
+
description: "Target language code (e.g. 'en', 'ja'). Default: 'en'.",
|
|
112
|
+
default: "en"
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
required: ["text"]
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
name: "lingual_prompt_template",
|
|
120
|
+
description: "Zero-key mode: extract the exact compiled system prompt and few-shot rules for any Lingual mode so the host agent can execute it directly without external API credentials.",
|
|
121
|
+
inputSchema: {
|
|
122
|
+
type: "object",
|
|
123
|
+
properties: {
|
|
124
|
+
loadout: {
|
|
125
|
+
type: "string",
|
|
126
|
+
enum: ["spec", "commit", "oss", "yap", "direct", "companion"],
|
|
127
|
+
description: "Target mode or loadout.",
|
|
128
|
+
default: "spec"
|
|
129
|
+
},
|
|
130
|
+
sourceLang: {
|
|
131
|
+
type: "string",
|
|
132
|
+
description: "Source language code (e.g. 'zh', 'ja', 'en'). Default: 'zh'.",
|
|
133
|
+
default: "zh"
|
|
134
|
+
},
|
|
135
|
+
targetLang: {
|
|
136
|
+
type: "string",
|
|
137
|
+
description: "Target language code (e.g. 'en', 'ja'). Default: 'en'.",
|
|
138
|
+
default: "en"
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
required: ["loadout"]
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
]
|
|
145
|
+
};
|
|
146
|
+
});
|
|
147
|
+
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
148
|
+
const { name, arguments: args } = request.params;
|
|
149
|
+
const diskConfig = loadUserLingualConfig();
|
|
150
|
+
const llm = resolveMcpLlmConfig(diskConfig);
|
|
151
|
+
if (name === "lingual_transform_spec") {
|
|
152
|
+
const text = String(args?.text || "");
|
|
153
|
+
const loadoutId = String(args?.loadout || "spec");
|
|
154
|
+
const targetLang = String(args?.targetLang || "en");
|
|
155
|
+
const sourceLang = args?.sourceLang ? String(args.sourceLang) : detectScriptLanguage(text) || diskConfig.sourceLang || "zh";
|
|
156
|
+
const preset = getPresetLoadout(loadoutId, sourceLang);
|
|
157
|
+
if (!preset) {
|
|
158
|
+
return {
|
|
159
|
+
isError: true,
|
|
160
|
+
content: [{ type: "text", text: `Unknown loadout preset: ${loadoutId}` }]
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
const sanitized = sanitizePromptForTranslation(text);
|
|
164
|
+
const inputToTransform = sanitized.distilledText || text;
|
|
165
|
+
if (!llm.configured) {
|
|
166
|
+
return {
|
|
167
|
+
content: [
|
|
168
|
+
{
|
|
169
|
+
type: "text",
|
|
170
|
+
text: JSON.stringify(
|
|
171
|
+
{
|
|
172
|
+
status: "unconfigured_zero_key_fallback",
|
|
173
|
+
message: "No external LLM credentials configured (set LINGUAL_ENDPOINT / OPENAI_BASE_URL and LINGUAL_API_KEY / OPENAI_API_KEY, or configure ~/.pi/agent/lingual.json). Use the compiledSystemPrompt below directly in your host agent.",
|
|
174
|
+
loadout: loadoutId,
|
|
175
|
+
distilledInput: inputToTransform,
|
|
176
|
+
compiledSystemPrompt: compileModeSystemPrompt(preset, { sourceLang, targetLang })
|
|
177
|
+
},
|
|
178
|
+
null,
|
|
179
|
+
2
|
|
180
|
+
)
|
|
181
|
+
}
|
|
182
|
+
]
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
try {
|
|
186
|
+
const candidates = await executeModeRunner(inputToTransform, preset, {
|
|
187
|
+
endpoint: llm.endpoint,
|
|
188
|
+
apiKey: llm.apiKey,
|
|
189
|
+
model: llm.model,
|
|
190
|
+
sourceLang,
|
|
191
|
+
targetLang
|
|
192
|
+
});
|
|
193
|
+
if (!candidates || candidates.length === 0) {
|
|
194
|
+
return {
|
|
195
|
+
content: [
|
|
196
|
+
{
|
|
197
|
+
type: "text",
|
|
198
|
+
text: JSON.stringify(
|
|
199
|
+
{
|
|
200
|
+
status: "fallback",
|
|
201
|
+
message: "LLM endpoint did not return transformed candidates; returning original input.",
|
|
202
|
+
transformed: text
|
|
203
|
+
},
|
|
204
|
+
null,
|
|
205
|
+
2
|
|
206
|
+
)
|
|
207
|
+
}
|
|
208
|
+
]
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
const primary = candidates[0];
|
|
212
|
+
const finalTransformed = sanitized.rawPayload ? ensureCodeTokensPreserved(sanitized.rawPayload, primary.content) : primary.content;
|
|
213
|
+
return {
|
|
214
|
+
content: [
|
|
215
|
+
{
|
|
216
|
+
type: "text",
|
|
217
|
+
text: JSON.stringify(
|
|
218
|
+
{
|
|
219
|
+
status: "success",
|
|
220
|
+
loadout: loadoutId,
|
|
221
|
+
transformed: finalTransformed,
|
|
222
|
+
explanation: primary.explanation,
|
|
223
|
+
vocab: primary.vocab,
|
|
224
|
+
sourceText: text
|
|
225
|
+
},
|
|
226
|
+
null,
|
|
227
|
+
2
|
|
228
|
+
)
|
|
229
|
+
}
|
|
230
|
+
]
|
|
231
|
+
};
|
|
232
|
+
} catch (err) {
|
|
233
|
+
return {
|
|
234
|
+
isError: true,
|
|
235
|
+
content: [{ type: "text", text: `Transformation failed: ${err?.message || String(err)}` }]
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
if (name === "lingual_bilingual_companion") {
|
|
240
|
+
const text = String(args?.text || "");
|
|
241
|
+
const targetLang = String(args?.targetLang || "en");
|
|
242
|
+
const sourceLang = args?.sourceLang ? String(args.sourceLang) : detectScriptLanguage(text) || diskConfig.sourceLang || "zh";
|
|
243
|
+
if (!llm.configured) {
|
|
244
|
+
return {
|
|
245
|
+
content: [
|
|
246
|
+
{
|
|
247
|
+
type: "text",
|
|
248
|
+
text: JSON.stringify(
|
|
249
|
+
{
|
|
250
|
+
status: "unconfigured_zero_key_fallback",
|
|
251
|
+
message: "No external LLM credentials configured (set LINGUAL_ENDPOINT / OPENAI_BASE_URL and LINGUAL_API_KEY / OPENAI_API_KEY). Use compiledSystemPrompt in your host agent.",
|
|
252
|
+
compiledSystemPrompt: buildSystemPrompt(sourceLang, targetLang),
|
|
253
|
+
sourceText: text
|
|
254
|
+
},
|
|
255
|
+
null,
|
|
256
|
+
2
|
|
257
|
+
)
|
|
258
|
+
}
|
|
259
|
+
]
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
try {
|
|
263
|
+
const result = await translatePrompt(text, {
|
|
264
|
+
endpoint: llm.endpoint,
|
|
265
|
+
apiKey: llm.apiKey,
|
|
266
|
+
model: llm.model,
|
|
267
|
+
sourceLang,
|
|
268
|
+
targetLang
|
|
269
|
+
});
|
|
270
|
+
if (!result) {
|
|
271
|
+
return {
|
|
272
|
+
content: [
|
|
273
|
+
{
|
|
274
|
+
type: "text",
|
|
275
|
+
text: JSON.stringify(
|
|
276
|
+
{
|
|
277
|
+
status: "empty",
|
|
278
|
+
message: "No translation generated (input might be pure code or bypassed by shield).",
|
|
279
|
+
sourceText: text
|
|
280
|
+
},
|
|
281
|
+
null,
|
|
282
|
+
2
|
|
283
|
+
)
|
|
284
|
+
}
|
|
285
|
+
]
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
return {
|
|
289
|
+
content: [
|
|
290
|
+
{
|
|
291
|
+
type: "text",
|
|
292
|
+
text: JSON.stringify(
|
|
293
|
+
{
|
|
294
|
+
status: "success",
|
|
295
|
+
spoken: result.spoken,
|
|
296
|
+
nativeSpoken: result.nativeSpoken,
|
|
297
|
+
written: result.written,
|
|
298
|
+
nativeWritten: result.nativeWritten,
|
|
299
|
+
vocab: result.vocab,
|
|
300
|
+
sourceText: result.original
|
|
301
|
+
},
|
|
302
|
+
null,
|
|
303
|
+
2
|
|
304
|
+
)
|
|
305
|
+
}
|
|
306
|
+
]
|
|
307
|
+
};
|
|
308
|
+
} catch (err) {
|
|
309
|
+
return {
|
|
310
|
+
isError: true,
|
|
311
|
+
content: [{ type: "text", text: `Companion mapping failed: ${err?.message || String(err)}` }]
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
if (name === "lingual_prompt_template") {
|
|
316
|
+
const loadoutId = String(args?.loadout || "spec");
|
|
317
|
+
const sourceLang = String(args?.sourceLang || "zh");
|
|
318
|
+
const targetLang = String(args?.targetLang || "en");
|
|
319
|
+
if (loadoutId === "companion") {
|
|
320
|
+
return {
|
|
321
|
+
content: [{ type: "text", text: buildSystemPrompt(sourceLang, targetLang) }]
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
const preset = getPresetLoadout(loadoutId, sourceLang);
|
|
325
|
+
if (!preset) {
|
|
326
|
+
return {
|
|
327
|
+
isError: true,
|
|
328
|
+
content: [{ type: "text", text: `Unknown loadout preset: ${loadoutId}` }]
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
return {
|
|
332
|
+
content: [{ type: "text", text: compileModeSystemPrompt(preset, { sourceLang, targetLang }) }]
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
return {
|
|
336
|
+
isError: true,
|
|
337
|
+
content: [{ type: "text", text: `Unknown tool name: ${name}` }]
|
|
338
|
+
};
|
|
339
|
+
});
|
|
340
|
+
server.setRequestHandler(ListPromptsRequestSchema, async () => {
|
|
341
|
+
return {
|
|
342
|
+
prompts: [
|
|
343
|
+
{
|
|
344
|
+
name: "spec_prompt",
|
|
345
|
+
description: "Structure raw developer instructions into a rigorous technical specification.",
|
|
346
|
+
arguments: [
|
|
347
|
+
{ name: "raw_idea", description: "The raw thought or instruction to structure.", required: true },
|
|
348
|
+
{ name: "source_lang", description: "Optional source language code (default: auto/zh).", required: false },
|
|
349
|
+
{ name: "target_lang", description: "Optional target language code (default: en).", required: false }
|
|
350
|
+
]
|
|
351
|
+
},
|
|
352
|
+
{
|
|
353
|
+
name: "conventional_commit",
|
|
354
|
+
description: "Dehydrate plain explanation into a Conventional Commit (first line <= 72 chars).",
|
|
355
|
+
arguments: [
|
|
356
|
+
{ name: "changes_summary", description: "Description of what was changed and why.", required: true },
|
|
357
|
+
{ name: "source_lang", description: "Optional source language code (default: auto/zh).", required: false },
|
|
358
|
+
{ name: "target_lang", description: "Optional target language code (default: en).", required: false }
|
|
359
|
+
]
|
|
360
|
+
}
|
|
361
|
+
]
|
|
362
|
+
};
|
|
363
|
+
});
|
|
364
|
+
server.setRequestHandler(GetPromptRequestSchema, async (request) => {
|
|
365
|
+
const { name, arguments: args } = request.params;
|
|
366
|
+
const sourceLang = args?.source_lang || "zh";
|
|
367
|
+
const targetLang = args?.target_lang || "en";
|
|
368
|
+
if (name === "spec_prompt") {
|
|
369
|
+
const idea = args?.raw_idea || "";
|
|
370
|
+
const sys = compileModeSystemPrompt(getPresetLoadout("spec", sourceLang), { sourceLang, targetLang });
|
|
371
|
+
return {
|
|
372
|
+
description: "Transform idea into an engineering specification",
|
|
373
|
+
messages: [
|
|
374
|
+
{ role: "user", content: { type: "text", text: `${sys}
|
|
375
|
+
|
|
376
|
+
Task to structure:
|
|
377
|
+
${idea}` } }
|
|
378
|
+
]
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
if (name === "conventional_commit") {
|
|
382
|
+
const summary = args?.changes_summary || "";
|
|
383
|
+
const sys = compileModeSystemPrompt(getPresetLoadout("commit", sourceLang), { sourceLang, targetLang });
|
|
384
|
+
return {
|
|
385
|
+
description: "Transform change summary into Conventional Commit",
|
|
386
|
+
messages: [
|
|
387
|
+
{ role: "user", content: { type: "text", text: `${sys}
|
|
388
|
+
|
|
389
|
+
Changes to commit:
|
|
390
|
+
${summary}` } }
|
|
391
|
+
]
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
throw new Error(`Prompt not found: ${name}`);
|
|
395
|
+
});
|
|
396
|
+
return server;
|
|
397
|
+
}
|
|
398
|
+
async function runLingualMcpServer() {
|
|
399
|
+
const server = createLingualMcpServer();
|
|
400
|
+
const transport = new StdioServerTransport();
|
|
401
|
+
await server.connect(transport);
|
|
402
|
+
}
|
|
403
|
+
export {
|
|
404
|
+
createLingualMcpServer,
|
|
405
|
+
resolveMcpLlmConfig,
|
|
406
|
+
runLingualMcpServer
|
|
407
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,66 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lingual-mcp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Universal Model Context Protocol (MCP) server for pi-lingual — bring 0ms dual-register phrasing, intent compilation, and code-token-safe prompt templates to Claude Code, Cursor, Windsurf, Cline, and any MCP client.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"module": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"bin",
|
|
19
|
+
"README.md",
|
|
20
|
+
"LICENSE"
|
|
21
|
+
],
|
|
22
|
+
"bin": {
|
|
23
|
+
"lingual-mcp": "bin/lingual-mcp.js"
|
|
24
|
+
},
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=22.19.0"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "tsup src/index.ts --format esm,cjs --dts --clean --no-splitting",
|
|
30
|
+
"typecheck": "tsc --noEmit",
|
|
31
|
+
"pretest": "npm run build",
|
|
32
|
+
"test": "npx tsx --test tests/**/*.test.ts",
|
|
33
|
+
"check": "npm run typecheck && npm test"
|
|
34
|
+
},
|
|
35
|
+
"keywords": [
|
|
36
|
+
"mcp",
|
|
37
|
+
"model-context-protocol",
|
|
38
|
+
"prompt-optimizer",
|
|
39
|
+
"bilingual",
|
|
40
|
+
"pi-lingual",
|
|
41
|
+
"claude-code",
|
|
42
|
+
"cursor",
|
|
43
|
+
"windsurf",
|
|
44
|
+
"developer-tools"
|
|
45
|
+
],
|
|
46
|
+
"author": "Jason Song",
|
|
47
|
+
"license": "MIT",
|
|
48
|
+
"repository": {
|
|
49
|
+
"type": "git",
|
|
50
|
+
"url": "git+https://github.com/3ZEROS12/lingual-mcp.git"
|
|
51
|
+
},
|
|
52
|
+
"homepage": "https://github.com/3ZEROS12/lingual-mcp#readme",
|
|
53
|
+
"bugs": {
|
|
54
|
+
"url": "https://github.com/3ZEROS12/lingual-mcp/issues"
|
|
55
|
+
},
|
|
56
|
+
"dependencies": {
|
|
57
|
+
"@modelcontextprotocol/sdk": "^1.32.2",
|
|
58
|
+
"pi-lingual": "^0.9.0"
|
|
59
|
+
},
|
|
60
|
+
"devDependencies": {
|
|
61
|
+
"@types/node": "^26.6.2",
|
|
62
|
+
"tsup": "^8.5.1",
|
|
63
|
+
"tsx": "^4.23.15",
|
|
64
|
+
"typescript": "^5.8.2"
|
|
65
|
+
}
|
|
66
|
+
}
|