lingual-mcp 0.1.1 → 0.1.2
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/index.d.ts +7 -2
- package/dist/index.js +385 -421
- package/package.json +11 -5
- package/dist/index.cjs +0 -552
- package/dist/index.d.cts +0 -27
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lingual-mcp",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "Translate and rewrite prompts via Model Context Protocol (MCP) — bilingual companion phrasing, spec/commit prompt presets, and code-safe templates for Claude Code, Cursor, Windsurf, and any MCP client.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.js",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
".": {
|
|
11
11
|
"types": "./dist/index.d.ts",
|
|
12
12
|
"import": "./dist/index.js",
|
|
13
|
-
"
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
16
|
"files": [
|
|
@@ -26,15 +26,21 @@
|
|
|
26
26
|
"node": ">=22.19.0"
|
|
27
27
|
},
|
|
28
28
|
"scripts": {
|
|
29
|
-
"build": "tsup src/index.ts --format esm
|
|
29
|
+
"build": "tsup src/index.ts --format esm --dts --clean --shims",
|
|
30
30
|
"typecheck": "tsc --noEmit",
|
|
31
31
|
"pretest": "npm run build",
|
|
32
32
|
"test": "npx tsx --test tests/**/*.test.ts",
|
|
33
|
-
"check": "npm run typecheck && npm test"
|
|
33
|
+
"check": "npm run typecheck && npm test",
|
|
34
|
+
"prepack": "npm run build"
|
|
34
35
|
},
|
|
35
36
|
"keywords": [
|
|
36
37
|
"mcp",
|
|
38
|
+
"mcp-server",
|
|
37
39
|
"model-context-protocol",
|
|
40
|
+
"translate",
|
|
41
|
+
"translation",
|
|
42
|
+
"prompt",
|
|
43
|
+
"prompt-rewriter",
|
|
38
44
|
"prompt-optimizer",
|
|
39
45
|
"bilingual",
|
|
40
46
|
"pi-lingual",
|
package/dist/index.cjs
DELETED
|
@@ -1,552 +0,0 @@
|
|
|
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
|
-
applyModeOverrides: () => applyModeOverrides,
|
|
24
|
-
createLingualMcpServer: () => createLingualMcpServer,
|
|
25
|
-
normalizeReasoningArg: () => normalizeReasoningArg,
|
|
26
|
-
resolveMcpLlmConfig: () => resolveMcpLlmConfig,
|
|
27
|
-
resolveMode: () => resolveMode,
|
|
28
|
-
runLingualMcpServer: () => runLingualMcpServer,
|
|
29
|
-
stripVocabSlots: () => stripVocabSlots
|
|
30
|
-
});
|
|
31
|
-
module.exports = __toCommonJS(index_exports);
|
|
32
|
-
var import_node_module = require("module");
|
|
33
|
-
var import_server = require("@modelcontextprotocol/sdk/server/index.js");
|
|
34
|
-
var import_stdio = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
35
|
-
var import_types = require("@modelcontextprotocol/sdk/types.js");
|
|
36
|
-
var import_core = require("pi-lingual/core");
|
|
37
|
-
var import_meta = {};
|
|
38
|
-
var require2 = (0, import_node_module.createRequire)(import_meta.url);
|
|
39
|
-
var manifest = require2("../package.json");
|
|
40
|
-
var PKG_VERSION = typeof manifest.version === "string" ? manifest.version : "0.0.0";
|
|
41
|
-
var REASONING_LEVELS = ["off", "minimal", "low", "medium", "high"];
|
|
42
|
-
var PRESET_IDS = ["spec", "commit", "oss", "yap", "direct"];
|
|
43
|
-
function isLoopbackUrl(urlStr) {
|
|
44
|
-
try {
|
|
45
|
-
const parsed = new URL(urlStr);
|
|
46
|
-
return parsed.hostname === "127.0.0.1" || parsed.hostname === "localhost" || parsed.hostname === "::1";
|
|
47
|
-
} catch {
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
function resolveMcpLlmConfig(diskConfig, env = process.env) {
|
|
52
|
-
const rawEndpoint = env.LINGUAL_ENDPOINT || env.OPENAI_BASE_URL || diskConfig.endpoint;
|
|
53
|
-
const rawApiKey = env.LINGUAL_API_KEY || env.OPENAI_API_KEY || diskConfig.apiKey;
|
|
54
|
-
const rawModel = env.LINGUAL_MODEL || env.OPENAI_MODEL || diskConfig.model;
|
|
55
|
-
if (!rawEndpoint && !rawApiKey) {
|
|
56
|
-
return { configured: false };
|
|
57
|
-
}
|
|
58
|
-
const base = (rawEndpoint || "https://api.openai.com/v1").replace(/\/+$/, "");
|
|
59
|
-
const endpoint = base.endsWith("/chat/completions") ? base : `${base}/chat/completions`;
|
|
60
|
-
const apiKey = rawApiKey || (isLoopbackUrl(endpoint) ? "local" : void 0);
|
|
61
|
-
if (!apiKey) {
|
|
62
|
-
return { configured: false };
|
|
63
|
-
}
|
|
64
|
-
return {
|
|
65
|
-
configured: true,
|
|
66
|
-
endpoint,
|
|
67
|
-
apiKey,
|
|
68
|
-
model: rawModel || "gpt-4o-mini"
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
function normalizeReasoningArg(raw) {
|
|
72
|
-
const value = typeof raw === "string" ? raw.trim().toLowerCase() : "";
|
|
73
|
-
return REASONING_LEVELS.includes(value) ? value : void 0;
|
|
74
|
-
}
|
|
75
|
-
function resolveMode(id, sourceLang, explainLang, custom) {
|
|
76
|
-
const wanted = (id || "").trim().toLowerCase();
|
|
77
|
-
if (!wanted) return null;
|
|
78
|
-
const userMode = (custom || []).find((mode) => mode.id.toLowerCase() === wanted && mode.enabled !== false);
|
|
79
|
-
if (userMode) return userMode;
|
|
80
|
-
return (0, import_core.getPresetLoadout)(wanted, sourceLang, explainLang);
|
|
81
|
-
}
|
|
82
|
-
function stripVocabSlots(slots) {
|
|
83
|
-
return slots ? slots.filter((slot) => slot.role !== "vocab") : slots;
|
|
84
|
-
}
|
|
85
|
-
function applyModeOverrides(mode, options) {
|
|
86
|
-
const next = { ...mode };
|
|
87
|
-
if (options.reasoning) next.reasoning = options.reasoning;
|
|
88
|
-
if (options.includeVocab === false) {
|
|
89
|
-
next.vocab = false;
|
|
90
|
-
next.slots = stripVocabSlots(next.slots);
|
|
91
|
-
}
|
|
92
|
-
return next;
|
|
93
|
-
}
|
|
94
|
-
function modeIds(disk, extra = []) {
|
|
95
|
-
const custom = (disk.modes || []).filter((mode) => mode.enabled !== false).map((mode) => mode.id);
|
|
96
|
-
return Array.from(/* @__PURE__ */ new Set([...extra, ...PRESET_IDS, ...custom]));
|
|
97
|
-
}
|
|
98
|
-
function createLingualMcpServer(options = {}) {
|
|
99
|
-
const readDisk = () => options.diskConfig ?? (0, import_core.loadUserLingualConfig)();
|
|
100
|
-
const server = new import_server.Server(
|
|
101
|
-
{
|
|
102
|
-
name: "lingual-mcp",
|
|
103
|
-
version: PKG_VERSION
|
|
104
|
-
},
|
|
105
|
-
{
|
|
106
|
-
capabilities: {
|
|
107
|
-
tools: {},
|
|
108
|
-
prompts: {}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
);
|
|
112
|
-
server.setRequestHandler(import_types.ListToolsRequestSchema, async () => {
|
|
113
|
-
const disk = readDisk();
|
|
114
|
-
const transformIds = modeIds(disk);
|
|
115
|
-
const templateIds = modeIds(disk, ["companion"]);
|
|
116
|
-
return {
|
|
117
|
-
tools: [
|
|
118
|
-
{
|
|
119
|
-
name: "lingual_transform_spec",
|
|
120
|
-
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. Accepts any preset id or a mode id declared in ~/.pi/agent/lingual.json.",
|
|
121
|
-
inputSchema: {
|
|
122
|
-
type: "object",
|
|
123
|
-
properties: {
|
|
124
|
-
text: {
|
|
125
|
-
type: "string",
|
|
126
|
-
description: "The raw thought, feature requirement, issue draft, or commit message in any language."
|
|
127
|
-
},
|
|
128
|
-
loadout: {
|
|
129
|
-
type: "string",
|
|
130
|
-
enum: transformIds,
|
|
131
|
-
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' (clean technical English, code blocks and stack traces intact), or any custom mode id from lingual.json. Default: 'spec'.",
|
|
132
|
-
default: "spec"
|
|
133
|
-
},
|
|
134
|
-
sourceLang: {
|
|
135
|
-
type: "string",
|
|
136
|
-
description: "Source language code (e.g. 'zh', 'ja', 'en', 'es'). Auto-detected if omitted."
|
|
137
|
-
},
|
|
138
|
-
targetLang: {
|
|
139
|
-
type: "string",
|
|
140
|
-
description: "Target language code (e.g. 'en', 'ja', 'zh'). Default: 'en'.",
|
|
141
|
-
default: "en"
|
|
142
|
-
},
|
|
143
|
-
reasoning: {
|
|
144
|
-
type: "string",
|
|
145
|
-
enum: REASONING_LEVELS,
|
|
146
|
-
description: "Thinking effort for this call. Overrides the mode's pinned level (spec pins 'low', the rest pin 'off')."
|
|
147
|
-
},
|
|
148
|
-
context: {
|
|
149
|
-
type: "string",
|
|
150
|
-
description: "Extra context for context-aware modes, such as a staged git diff for 'commit' or the previous agent turn."
|
|
151
|
-
},
|
|
152
|
-
includeVocab: {
|
|
153
|
-
type: "boolean",
|
|
154
|
-
description: "Set false to drop the vocabulary slot from the prompt and the response. Default: true.",
|
|
155
|
-
default: true
|
|
156
|
-
}
|
|
157
|
-
},
|
|
158
|
-
required: ["text"]
|
|
159
|
-
}
|
|
160
|
-
},
|
|
161
|
-
{
|
|
162
|
-
name: "lingual_bilingual_companion",
|
|
163
|
-
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.",
|
|
164
|
-
inputSchema: {
|
|
165
|
-
type: "object",
|
|
166
|
-
properties: {
|
|
167
|
-
text: {
|
|
168
|
-
type: "string",
|
|
169
|
-
description: "The natural language text or expression to unpack into technical dual-registers."
|
|
170
|
-
},
|
|
171
|
-
sourceLang: {
|
|
172
|
-
type: "string",
|
|
173
|
-
description: "Source language code (e.g. 'zh', 'ja'). Auto-detected if omitted."
|
|
174
|
-
},
|
|
175
|
-
targetLang: {
|
|
176
|
-
type: "string",
|
|
177
|
-
description: "Target language code (e.g. 'en', 'ja'). Default: 'en'.",
|
|
178
|
-
default: "en"
|
|
179
|
-
},
|
|
180
|
-
reasoning: {
|
|
181
|
-
type: "string",
|
|
182
|
-
enum: REASONING_LEVELS,
|
|
183
|
-
description: "Thinking effort for this call. Defaults to the companion mode's level ('off')."
|
|
184
|
-
},
|
|
185
|
-
includeVocab: {
|
|
186
|
-
type: "boolean",
|
|
187
|
-
description: "Set false to drop the vocabulary slot from the prompt and the response. Default: true.",
|
|
188
|
-
default: true
|
|
189
|
-
}
|
|
190
|
-
},
|
|
191
|
-
required: ["text"]
|
|
192
|
-
}
|
|
193
|
-
},
|
|
194
|
-
{
|
|
195
|
-
name: "lingual_prompt_template",
|
|
196
|
-
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. Custom modes from lingual.json are accepted.",
|
|
197
|
-
inputSchema: {
|
|
198
|
-
type: "object",
|
|
199
|
-
properties: {
|
|
200
|
-
loadout: {
|
|
201
|
-
type: "string",
|
|
202
|
-
enum: templateIds,
|
|
203
|
-
description: "Target mode or loadout id: any preset, 'companion', or a custom mode id from lingual.json.",
|
|
204
|
-
default: "spec"
|
|
205
|
-
},
|
|
206
|
-
sourceLang: {
|
|
207
|
-
type: "string",
|
|
208
|
-
description: "Source language code (e.g. 'zh', 'ja', 'en'). Default: 'zh'.",
|
|
209
|
-
default: "zh"
|
|
210
|
-
},
|
|
211
|
-
targetLang: {
|
|
212
|
-
type: "string",
|
|
213
|
-
description: "Target language code (e.g. 'en', 'ja'). Default: 'en'.",
|
|
214
|
-
default: "en"
|
|
215
|
-
},
|
|
216
|
-
includeVocab: {
|
|
217
|
-
type: "boolean",
|
|
218
|
-
description: "Set false to drop the vocabulary slot from the compiled prompt. Default: true.",
|
|
219
|
-
default: true
|
|
220
|
-
}
|
|
221
|
-
},
|
|
222
|
-
required: ["loadout"]
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
]
|
|
226
|
-
};
|
|
227
|
-
});
|
|
228
|
-
server.setRequestHandler(import_types.CallToolRequestSchema, async (request) => {
|
|
229
|
-
const { name, arguments: args } = request.params;
|
|
230
|
-
const disk = readDisk();
|
|
231
|
-
const llm = resolveMcpLlmConfig(disk);
|
|
232
|
-
if (name === "lingual_transform_spec") {
|
|
233
|
-
const text = String(args?.text || "");
|
|
234
|
-
const loadoutId = String(args?.loadout || "spec");
|
|
235
|
-
const targetLang = String(args?.targetLang || "en");
|
|
236
|
-
const sourceLang = args?.sourceLang ? String(args.sourceLang) : (0, import_core.detectScriptLanguage)(text) || disk.sourceLang || "zh";
|
|
237
|
-
const explainLang = disk.explainLang || sourceLang;
|
|
238
|
-
const reasoning = normalizeReasoningArg(args?.reasoning);
|
|
239
|
-
const includeVocab = args?.includeVocab !== false;
|
|
240
|
-
const context = typeof args?.context === "string" && args.context.trim() ? args.context.trim() : void 0;
|
|
241
|
-
const mode = resolveMode(loadoutId, sourceLang, explainLang, disk.modes);
|
|
242
|
-
if (!mode) {
|
|
243
|
-
return {
|
|
244
|
-
isError: true,
|
|
245
|
-
content: [
|
|
246
|
-
{
|
|
247
|
-
type: "text",
|
|
248
|
-
text: `Unknown loadout or mode: ${loadoutId}. Known ids: ${modeIds(disk).join(", ")}`
|
|
249
|
-
}
|
|
250
|
-
]
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
const runMode = applyModeOverrides(mode, { reasoning, includeVocab });
|
|
254
|
-
const sanitized = (0, import_core.sanitizePromptForTranslation)(text);
|
|
255
|
-
const inputToTransform = sanitized.distilledText || text;
|
|
256
|
-
if (!llm.configured) {
|
|
257
|
-
return {
|
|
258
|
-
content: [
|
|
259
|
-
{
|
|
260
|
-
type: "text",
|
|
261
|
-
text: JSON.stringify(
|
|
262
|
-
{
|
|
263
|
-
status: "unconfigured_zero_key_fallback",
|
|
264
|
-
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.",
|
|
265
|
-
mode: runMode.id,
|
|
266
|
-
reasoning: runMode.reasoning ?? "off",
|
|
267
|
-
distilledInput: inputToTransform,
|
|
268
|
-
compiledSystemPrompt: (0, import_core.compileModeSystemPrompt)(runMode, {
|
|
269
|
-
sourceLang,
|
|
270
|
-
targetLang,
|
|
271
|
-
explainLang,
|
|
272
|
-
globalKillList: disk.globalKillList,
|
|
273
|
-
extraContext: context
|
|
274
|
-
})
|
|
275
|
-
},
|
|
276
|
-
null,
|
|
277
|
-
2
|
|
278
|
-
)
|
|
279
|
-
}
|
|
280
|
-
]
|
|
281
|
-
};
|
|
282
|
-
}
|
|
283
|
-
try {
|
|
284
|
-
const candidates = await (0, import_core.executeModeRunner)(inputToTransform, runMode, {
|
|
285
|
-
endpoint: llm.endpoint,
|
|
286
|
-
apiKey: llm.apiKey,
|
|
287
|
-
model: llm.model,
|
|
288
|
-
sourceLang,
|
|
289
|
-
targetLang,
|
|
290
|
-
explainLang,
|
|
291
|
-
globalKillList: disk.globalKillList,
|
|
292
|
-
extraContext: context,
|
|
293
|
-
reasoning
|
|
294
|
-
});
|
|
295
|
-
if (!candidates || candidates.length === 0) {
|
|
296
|
-
return {
|
|
297
|
-
content: [
|
|
298
|
-
{
|
|
299
|
-
type: "text",
|
|
300
|
-
text: JSON.stringify(
|
|
301
|
-
{
|
|
302
|
-
status: "fallback",
|
|
303
|
-
message: "LLM endpoint did not return transformed candidates; returning original input.",
|
|
304
|
-
mode: runMode.id,
|
|
305
|
-
transformed: text
|
|
306
|
-
},
|
|
307
|
-
null,
|
|
308
|
-
2
|
|
309
|
-
)
|
|
310
|
-
}
|
|
311
|
-
]
|
|
312
|
-
};
|
|
313
|
-
}
|
|
314
|
-
const primary = candidates[0];
|
|
315
|
-
const finalTransformed = sanitized.rawPayload ? (0, import_core.ensureCodeTokensPreserved)(sanitized.rawPayload, primary.content) : primary.content;
|
|
316
|
-
return {
|
|
317
|
-
content: [
|
|
318
|
-
{
|
|
319
|
-
type: "text",
|
|
320
|
-
text: JSON.stringify(
|
|
321
|
-
{
|
|
322
|
-
status: "success",
|
|
323
|
-
mode: runMode.id,
|
|
324
|
-
loadout: loadoutId,
|
|
325
|
-
reasoning: runMode.reasoning ?? "off",
|
|
326
|
-
transformed: finalTransformed,
|
|
327
|
-
explanation: primary.explanation,
|
|
328
|
-
vocab: primary.vocab,
|
|
329
|
-
sourceText: text
|
|
330
|
-
},
|
|
331
|
-
null,
|
|
332
|
-
2
|
|
333
|
-
)
|
|
334
|
-
}
|
|
335
|
-
]
|
|
336
|
-
};
|
|
337
|
-
} catch (err) {
|
|
338
|
-
return {
|
|
339
|
-
isError: true,
|
|
340
|
-
content: [{ type: "text", text: `Transformation failed: ${err instanceof Error ? err.message : String(err)}` }]
|
|
341
|
-
};
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
if (name === "lingual_bilingual_companion") {
|
|
345
|
-
const text = String(args?.text || "");
|
|
346
|
-
const targetLang = String(args?.targetLang || "en");
|
|
347
|
-
const sourceLang = args?.sourceLang ? String(args.sourceLang) : (0, import_core.detectScriptLanguage)(text) || disk.sourceLang || "zh";
|
|
348
|
-
const explainLang = disk.explainLang || sourceLang;
|
|
349
|
-
const reasoning = normalizeReasoningArg(args?.reasoning);
|
|
350
|
-
const includeVocab = args?.includeVocab !== false;
|
|
351
|
-
const companion = resolveMode("companion", sourceLang, explainLang, disk.modes);
|
|
352
|
-
const runMode = companion ? applyModeOverrides(companion, { reasoning, includeVocab }) : null;
|
|
353
|
-
if (!llm.configured) {
|
|
354
|
-
return {
|
|
355
|
-
content: [
|
|
356
|
-
{
|
|
357
|
-
type: "text",
|
|
358
|
-
text: JSON.stringify(
|
|
359
|
-
{
|
|
360
|
-
status: "unconfigured_zero_key_fallback",
|
|
361
|
-
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.",
|
|
362
|
-
compiledSystemPrompt: (0, import_core.compileModeSystemPrompt)(runMode ?? {}, {
|
|
363
|
-
sourceLang,
|
|
364
|
-
targetLang,
|
|
365
|
-
explainLang,
|
|
366
|
-
globalKillList: disk.globalKillList
|
|
367
|
-
}),
|
|
368
|
-
sourceText: text
|
|
369
|
-
},
|
|
370
|
-
null,
|
|
371
|
-
2
|
|
372
|
-
)
|
|
373
|
-
}
|
|
374
|
-
]
|
|
375
|
-
};
|
|
376
|
-
}
|
|
377
|
-
try {
|
|
378
|
-
const result = await (0, import_core.translateCore)(text, {
|
|
379
|
-
endpoint: llm.endpoint,
|
|
380
|
-
apiKey: llm.apiKey,
|
|
381
|
-
model: llm.model,
|
|
382
|
-
sourceLang,
|
|
383
|
-
targetLang,
|
|
384
|
-
explainLang,
|
|
385
|
-
slots: runMode?.slots,
|
|
386
|
-
killList: runMode?.killList,
|
|
387
|
-
globalKillList: disk.globalKillList,
|
|
388
|
-
reasoning: reasoning ?? runMode?.reasoning
|
|
389
|
-
});
|
|
390
|
-
if (!result) {
|
|
391
|
-
return {
|
|
392
|
-
content: [
|
|
393
|
-
{
|
|
394
|
-
type: "text",
|
|
395
|
-
text: JSON.stringify(
|
|
396
|
-
{
|
|
397
|
-
status: "empty",
|
|
398
|
-
message: "No translation generated (input might be pure code or bypassed by shield).",
|
|
399
|
-
sourceText: text
|
|
400
|
-
},
|
|
401
|
-
null,
|
|
402
|
-
2
|
|
403
|
-
)
|
|
404
|
-
}
|
|
405
|
-
]
|
|
406
|
-
};
|
|
407
|
-
}
|
|
408
|
-
return {
|
|
409
|
-
content: [
|
|
410
|
-
{
|
|
411
|
-
type: "text",
|
|
412
|
-
text: JSON.stringify(
|
|
413
|
-
{
|
|
414
|
-
status: "success",
|
|
415
|
-
spoken: result.spoken,
|
|
416
|
-
nativeSpoken: result.nativeSpoken,
|
|
417
|
-
written: result.written,
|
|
418
|
-
nativeWritten: result.nativeWritten,
|
|
419
|
-
vocab: result.vocab,
|
|
420
|
-
sourceText: result.original
|
|
421
|
-
},
|
|
422
|
-
null,
|
|
423
|
-
2
|
|
424
|
-
)
|
|
425
|
-
}
|
|
426
|
-
]
|
|
427
|
-
};
|
|
428
|
-
} catch (err) {
|
|
429
|
-
return {
|
|
430
|
-
isError: true,
|
|
431
|
-
content: [{ type: "text", text: `Companion mapping failed: ${err instanceof Error ? err.message : String(err)}` }]
|
|
432
|
-
};
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
if (name === "lingual_prompt_template") {
|
|
436
|
-
const loadoutId = String(args?.loadout || "spec");
|
|
437
|
-
const sourceLang = String(args?.sourceLang || "zh");
|
|
438
|
-
const targetLang = String(args?.targetLang || "en");
|
|
439
|
-
const explainLang = disk.explainLang || sourceLang;
|
|
440
|
-
const includeVocab = args?.includeVocab !== false;
|
|
441
|
-
const mode = resolveMode(loadoutId, sourceLang, explainLang, disk.modes);
|
|
442
|
-
if (!mode) {
|
|
443
|
-
return {
|
|
444
|
-
isError: true,
|
|
445
|
-
content: [
|
|
446
|
-
{
|
|
447
|
-
type: "text",
|
|
448
|
-
text: `Unknown loadout or mode: ${loadoutId}. Known ids: ${modeIds(disk, ["companion"]).join(", ")}`
|
|
449
|
-
}
|
|
450
|
-
]
|
|
451
|
-
};
|
|
452
|
-
}
|
|
453
|
-
return {
|
|
454
|
-
content: [
|
|
455
|
-
{
|
|
456
|
-
type: "text",
|
|
457
|
-
text: (0, import_core.compileModeSystemPrompt)(applyModeOverrides(mode, { includeVocab }), {
|
|
458
|
-
sourceLang,
|
|
459
|
-
targetLang,
|
|
460
|
-
explainLang,
|
|
461
|
-
globalKillList: disk.globalKillList
|
|
462
|
-
})
|
|
463
|
-
}
|
|
464
|
-
]
|
|
465
|
-
};
|
|
466
|
-
}
|
|
467
|
-
return {
|
|
468
|
-
isError: true,
|
|
469
|
-
content: [{ type: "text", text: `Unknown tool name: ${name}` }]
|
|
470
|
-
};
|
|
471
|
-
});
|
|
472
|
-
server.setRequestHandler(import_types.ListPromptsRequestSchema, async () => {
|
|
473
|
-
return {
|
|
474
|
-
prompts: [
|
|
475
|
-
{
|
|
476
|
-
name: "spec_prompt",
|
|
477
|
-
description: "Structure raw developer instructions into a rigorous technical specification.",
|
|
478
|
-
arguments: [
|
|
479
|
-
{ name: "raw_idea", description: "The raw thought or instruction to structure.", required: true },
|
|
480
|
-
{ name: "source_lang", description: "Optional source language code (default: auto/zh).", required: false },
|
|
481
|
-
{ name: "target_lang", description: "Optional target language code (default: en).", required: false }
|
|
482
|
-
]
|
|
483
|
-
},
|
|
484
|
-
{
|
|
485
|
-
name: "conventional_commit",
|
|
486
|
-
description: "Dehydrate plain explanation into a Conventional Commit (first line <= 72 chars).",
|
|
487
|
-
arguments: [
|
|
488
|
-
{ name: "changes_summary", description: "Description of what was changed and why.", required: true },
|
|
489
|
-
{ name: "source_lang", description: "Optional source language code (default: auto/zh).", required: false },
|
|
490
|
-
{ name: "target_lang", description: "Optional target language code (default: en).", required: false }
|
|
491
|
-
]
|
|
492
|
-
}
|
|
493
|
-
]
|
|
494
|
-
};
|
|
495
|
-
});
|
|
496
|
-
server.setRequestHandler(import_types.GetPromptRequestSchema, async (request) => {
|
|
497
|
-
const { name, arguments: args } = request.params;
|
|
498
|
-
const disk = readDisk();
|
|
499
|
-
const sourceLang = args?.source_lang || disk.sourceLang || "zh";
|
|
500
|
-
const targetLang = args?.target_lang || "en";
|
|
501
|
-
const explainLang = disk.explainLang || sourceLang;
|
|
502
|
-
const compile = (modeId) => {
|
|
503
|
-
const mode = resolveMode(modeId, sourceLang, explainLang, disk.modes);
|
|
504
|
-
return mode ? (0, import_core.compileModeSystemPrompt)(mode, { sourceLang, targetLang, explainLang, globalKillList: disk.globalKillList }) : null;
|
|
505
|
-
};
|
|
506
|
-
if (name === "spec_prompt") {
|
|
507
|
-
const idea = args?.raw_idea || "";
|
|
508
|
-
const sys = compile("spec");
|
|
509
|
-
if (!sys) throw new Error("Spec mode is unavailable");
|
|
510
|
-
return {
|
|
511
|
-
description: "Transform idea into an engineering specification",
|
|
512
|
-
messages: [
|
|
513
|
-
{ role: "user", content: { type: "text", text: `${sys}
|
|
514
|
-
|
|
515
|
-
Task to structure:
|
|
516
|
-
${idea}` } }
|
|
517
|
-
]
|
|
518
|
-
};
|
|
519
|
-
}
|
|
520
|
-
if (name === "conventional_commit") {
|
|
521
|
-
const summary = args?.changes_summary || "";
|
|
522
|
-
const sys = compile("commit");
|
|
523
|
-
if (!sys) throw new Error("Commit mode is unavailable");
|
|
524
|
-
return {
|
|
525
|
-
description: "Transform change summary into Conventional Commit",
|
|
526
|
-
messages: [
|
|
527
|
-
{ role: "user", content: { type: "text", text: `${sys}
|
|
528
|
-
|
|
529
|
-
Changes to commit:
|
|
530
|
-
${summary}` } }
|
|
531
|
-
]
|
|
532
|
-
};
|
|
533
|
-
}
|
|
534
|
-
throw new Error(`Prompt not found: ${name}`);
|
|
535
|
-
});
|
|
536
|
-
return server;
|
|
537
|
-
}
|
|
538
|
-
async function runLingualMcpServer() {
|
|
539
|
-
const server = createLingualMcpServer();
|
|
540
|
-
const transport = new import_stdio.StdioServerTransport();
|
|
541
|
-
await server.connect(transport);
|
|
542
|
-
}
|
|
543
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
544
|
-
0 && (module.exports = {
|
|
545
|
-
applyModeOverrides,
|
|
546
|
-
createLingualMcpServer,
|
|
547
|
-
normalizeReasoningArg,
|
|
548
|
-
resolveMcpLlmConfig,
|
|
549
|
-
resolveMode,
|
|
550
|
-
runLingualMcpServer,
|
|
551
|
-
stripVocabSlots
|
|
552
|
-
});
|
package/dist/index.d.cts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
2
|
-
import { LingualConfig, CustomModeConfig, ReasoningEffort, PromptSlotConfig } from 'pi-lingual/core';
|
|
3
|
-
|
|
4
|
-
interface McpServerOptions {
|
|
5
|
-
/** Replaces the on-disk `lingual.json` snapshot; tests and embedders pin their own config. */
|
|
6
|
-
diskConfig?: Partial<LingualConfig>;
|
|
7
|
-
}
|
|
8
|
-
interface ResolvedMcpLlmConfig {
|
|
9
|
-
configured: boolean;
|
|
10
|
-
endpoint?: string;
|
|
11
|
-
apiKey?: string;
|
|
12
|
-
model?: string;
|
|
13
|
-
}
|
|
14
|
-
declare function resolveMcpLlmConfig(diskConfig: Partial<LingualConfig>, env?: NodeJS.ProcessEnv): ResolvedMcpLlmConfig;
|
|
15
|
-
declare function normalizeReasoningArg(raw: unknown): ReasoningEffort | undefined;
|
|
16
|
-
/** Resolves a preset, a factory mode, or a user mode declared in `lingual.json`. */
|
|
17
|
-
declare function resolveMode(id: string, sourceLang: string, explainLang: string, custom?: CustomModeConfig[]): CustomModeConfig | null;
|
|
18
|
-
declare function stripVocabSlots(slots?: PromptSlotConfig[]): PromptSlotConfig[] | undefined;
|
|
19
|
-
/** An explicit request-level reasoning level wins over the level a mode pins. */
|
|
20
|
-
declare function applyModeOverrides(mode: CustomModeConfig, options: {
|
|
21
|
-
reasoning?: ReasoningEffort;
|
|
22
|
-
includeVocab?: boolean;
|
|
23
|
-
}): CustomModeConfig;
|
|
24
|
-
declare function createLingualMcpServer(options?: McpServerOptions): Server;
|
|
25
|
-
declare function runLingualMcpServer(): Promise<void>;
|
|
26
|
-
|
|
27
|
-
export { type McpServerOptions, type ResolvedMcpLlmConfig, applyModeOverrides, createLingualMcpServer, normalizeReasoningArg, resolveMcpLlmConfig, resolveMode, runLingualMcpServer, stripVocabSlots };
|