lingual-mcp 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +57 -21
- package/dist/index.cjs +171 -38
- package/dist/index.d.cts +16 -3
- package/dist/index.d.ts +16 -3
- package/dist/index.js +166 -39
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,12 +1,29 @@
|
|
|
1
1
|
# lingual-mcp
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Model Context Protocol server for [`pi-lingual`](https://github.com/3ZEROS12/pi-lingual): the same mode engine, reachable from any MCP client.
|
|
4
4
|
|
|
5
|
-
Works with **Claude Code**, **Claude Desktop**, **Cursor**, **Windsurf**, **Cline**, and
|
|
5
|
+
Works with **Claude Code**, **Claude Desktop**, **Cursor**, **Windsurf**, **Cline**, and anything else that speaks MCP. Two run modes: **template mode** (no API key — the client's own model executes the compiled prompt) and **endpoint mode** (the server calls an OpenAI-compatible endpoint).
|
|
6
6
|
|
|
7
|
-
##
|
|
7
|
+
## Install
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
```bash
|
|
10
|
+
npm install -g lingual-mcp # or: npx -y lingual-mcp
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Point the client at it:
|
|
14
|
+
|
|
15
|
+
```json
|
|
16
|
+
{
|
|
17
|
+
"mcpServers": {
|
|
18
|
+
"lingual": {
|
|
19
|
+
"command": "npx",
|
|
20
|
+
"args": ["-y", "lingual-mcp"]
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
From a checkout instead:
|
|
10
27
|
|
|
11
28
|
```json
|
|
12
29
|
{
|
|
@@ -19,30 +36,49 @@ Not published to npm yet, so point the client at this checkout (the built `dist/
|
|
|
19
36
|
}
|
|
20
37
|
```
|
|
21
38
|
|
|
22
|
-
|
|
39
|
+
## Tools
|
|
23
40
|
|
|
24
|
-
|
|
41
|
+
| Tool | Arguments | Purpose |
|
|
42
|
+
| :--- | :--- | :--- |
|
|
43
|
+
| `lingual_transform_spec` | `text`, `loadout`, `sourceLang?`, `targetLang?`, `reasoning?`, `context?`, `includeVocab?` | Compiles a draft into a preset's product: `spec`, `commit`, `oss`, `yap`, `direct`, or any custom mode id. Code fences and stack traces stay untouched. |
|
|
44
|
+
| `lingual_bilingual_companion` | `text`, `sourceLang?`, `targetLang?`, `reasoning?`, `includeVocab?` | Dual-register phrasing (spoken vs. written), native nuance, and vocabulary callouts, using the companion slots from your `lingual.json`. |
|
|
45
|
+
| `lingual_prompt_template` | `loadout`, `sourceLang?`, `targetLang?`, `includeVocab?` | Returns the compiled system prompt and slot schema so the host agent can run it with its own model. |
|
|
25
46
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
47
|
+
Shared argument semantics:
|
|
48
|
+
|
|
49
|
+
- `loadout` accepts the five presets (`spec`, `commit`, `oss`, `yap`, `direct`), `companion` where it applies, and **any mode id declared in `~/.pi/agent/lingual.json`**. Custom ids are resolved at request time and offered in the tool schema.
|
|
50
|
+
- `reasoning` is one of `off`, `minimal`, `low`, `medium`, `high`. An explicit value overrides the level the mode pins (`spec` pins `low`, the rest pin `off`).
|
|
51
|
+
- `context` injects extra material for context-aware modes: a staged diff for `commit`, the previous turn for a review mode.
|
|
52
|
+
- `includeVocab: false` drops the vocabulary slot from both the prompt and the response.
|
|
53
|
+
- `sourceLang` is auto-detected from the script when omitted; `targetLang` defaults to `en`.
|
|
54
|
+
|
|
55
|
+
## Prompts
|
|
29
56
|
|
|
30
|
-
|
|
57
|
+
| Prompt | Arguments | Purpose |
|
|
58
|
+
| :--- | :--- | :--- |
|
|
59
|
+
| `spec_prompt` | `raw_idea`, `source_lang?`, `target_lang?` | Reusable prompt that structures a raw idea into a specification. |
|
|
60
|
+
| `conventional_commit` | `changes_summary`, `source_lang?`, `target_lang?` | Reusable prompt that turns a change summary into a Conventional Commit. |
|
|
31
61
|
|
|
32
|
-
|
|
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. |
|
|
62
|
+
Both are compiled through the same mode resolution, so a custom `spec` or `commit` mode in `lingual.json` changes what the prompts emit.
|
|
39
63
|
|
|
40
|
-
|
|
64
|
+
## Endpoint mode
|
|
65
|
+
|
|
66
|
+
Set any of these to let the server call a model itself:
|
|
41
67
|
|
|
42
68
|
| Variable | Description |
|
|
43
69
|
| :--- | :--- |
|
|
44
70
|
| `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
|
|
46
|
-
| `LINGUAL_MODEL` / `OPENAI_MODEL` | Model
|
|
71
|
+
| `LINGUAL_API_KEY` / `OPENAI_API_KEY` | API key; loopback endpoints default to `"local"` when omitted |
|
|
72
|
+
| `LINGUAL_MODEL` / `OPENAI_MODEL` | Model id (default: `gpt-4o-mini`) |
|
|
73
|
+
|
|
74
|
+
`~/.pi/agent/lingual.json` is also read, so `endpoint`, `apiKey`, `model`, `explainLang`, `globalKillList`, and `modes` carry over from your Pi setup.
|
|
75
|
+
|
|
76
|
+
Without credentials, the transform and companion tools return `unconfigured_zero_key_fallback` with a `compiledSystemPrompt` field; `lingual_prompt_template` and the MCP prompts work with no key at all.
|
|
77
|
+
|
|
78
|
+
## Notes
|
|
79
|
+
|
|
80
|
+
- The server reports its `package.json` version in the MCP handshake.
|
|
81
|
+
- Requires `pi-lingual` `^0.9.0` for the core engine.
|
|
82
|
+
- `lingual-mcp` is not a Pi extension: it runs beside your editor's agent, not inside Pi.
|
|
47
83
|
|
|
48
|
-
|
|
84
|
+
MIT © [Jason Song](https://github.com/3ZEROS12)
|
package/dist/index.cjs
CHANGED
|
@@ -20,16 +20,26 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
+
applyModeOverrides: () => applyModeOverrides,
|
|
23
24
|
createLingualMcpServer: () => createLingualMcpServer,
|
|
25
|
+
normalizeReasoningArg: () => normalizeReasoningArg,
|
|
24
26
|
resolveMcpLlmConfig: () => resolveMcpLlmConfig,
|
|
25
|
-
|
|
27
|
+
resolveMode: () => resolveMode,
|
|
28
|
+
runLingualMcpServer: () => runLingualMcpServer,
|
|
29
|
+
stripVocabSlots: () => stripVocabSlots
|
|
26
30
|
});
|
|
27
31
|
module.exports = __toCommonJS(index_exports);
|
|
32
|
+
var import_node_module = require("module");
|
|
28
33
|
var import_server = require("@modelcontextprotocol/sdk/server/index.js");
|
|
29
34
|
var import_stdio = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
30
35
|
var import_types = require("@modelcontextprotocol/sdk/types.js");
|
|
31
36
|
var import_core = require("pi-lingual/core");
|
|
32
|
-
var
|
|
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"];
|
|
33
43
|
function isLoopbackUrl(urlStr) {
|
|
34
44
|
try {
|
|
35
45
|
const parsed = new URL(urlStr);
|
|
@@ -58,7 +68,35 @@ function resolveMcpLlmConfig(diskConfig, env = process.env) {
|
|
|
58
68
|
model: rawModel || "gpt-4o-mini"
|
|
59
69
|
};
|
|
60
70
|
}
|
|
61
|
-
function
|
|
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)();
|
|
62
100
|
const server = new import_server.Server(
|
|
63
101
|
{
|
|
64
102
|
name: "lingual-mcp",
|
|
@@ -72,11 +110,14 @@ function createLingualMcpServer() {
|
|
|
72
110
|
}
|
|
73
111
|
);
|
|
74
112
|
server.setRequestHandler(import_types.ListToolsRequestSchema, async () => {
|
|
113
|
+
const disk = readDisk();
|
|
114
|
+
const transformIds = modeIds(disk);
|
|
115
|
+
const templateIds = modeIds(disk, ["companion"]);
|
|
75
116
|
return {
|
|
76
117
|
tools: [
|
|
77
118
|
{
|
|
78
119
|
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.",
|
|
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.",
|
|
80
121
|
inputSchema: {
|
|
81
122
|
type: "object",
|
|
82
123
|
properties: {
|
|
@@ -86,8 +127,8 @@ function createLingualMcpServer() {
|
|
|
86
127
|
},
|
|
87
128
|
loadout: {
|
|
88
129
|
type: "string",
|
|
89
|
-
enum:
|
|
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' (
|
|
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'.",
|
|
91
132
|
default: "spec"
|
|
92
133
|
},
|
|
93
134
|
sourceLang: {
|
|
@@ -98,6 +139,20 @@ function createLingualMcpServer() {
|
|
|
98
139
|
type: "string",
|
|
99
140
|
description: "Target language code (e.g. 'en', 'ja', 'zh'). Default: 'en'.",
|
|
100
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
|
|
101
156
|
}
|
|
102
157
|
},
|
|
103
158
|
required: ["text"]
|
|
@@ -121,6 +176,16 @@ function createLingualMcpServer() {
|
|
|
121
176
|
type: "string",
|
|
122
177
|
description: "Target language code (e.g. 'en', 'ja'). Default: 'en'.",
|
|
123
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
|
|
124
189
|
}
|
|
125
190
|
},
|
|
126
191
|
required: ["text"]
|
|
@@ -128,14 +193,14 @@ function createLingualMcpServer() {
|
|
|
128
193
|
},
|
|
129
194
|
{
|
|
130
195
|
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.",
|
|
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.",
|
|
132
197
|
inputSchema: {
|
|
133
198
|
type: "object",
|
|
134
199
|
properties: {
|
|
135
200
|
loadout: {
|
|
136
201
|
type: "string",
|
|
137
|
-
enum:
|
|
138
|
-
description: "Target mode or loadout.",
|
|
202
|
+
enum: templateIds,
|
|
203
|
+
description: "Target mode or loadout id: any preset, 'companion', or a custom mode id from lingual.json.",
|
|
139
204
|
default: "spec"
|
|
140
205
|
},
|
|
141
206
|
sourceLang: {
|
|
@@ -147,6 +212,11 @@ function createLingualMcpServer() {
|
|
|
147
212
|
type: "string",
|
|
148
213
|
description: "Target language code (e.g. 'en', 'ja'). Default: 'en'.",
|
|
149
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
|
|
150
220
|
}
|
|
151
221
|
},
|
|
152
222
|
required: ["loadout"]
|
|
@@ -157,20 +227,30 @@ function createLingualMcpServer() {
|
|
|
157
227
|
});
|
|
158
228
|
server.setRequestHandler(import_types.CallToolRequestSchema, async (request) => {
|
|
159
229
|
const { name, arguments: args } = request.params;
|
|
160
|
-
const
|
|
161
|
-
const llm = resolveMcpLlmConfig(
|
|
230
|
+
const disk = readDisk();
|
|
231
|
+
const llm = resolveMcpLlmConfig(disk);
|
|
162
232
|
if (name === "lingual_transform_spec") {
|
|
163
233
|
const text = String(args?.text || "");
|
|
164
234
|
const loadoutId = String(args?.loadout || "spec");
|
|
165
235
|
const targetLang = String(args?.targetLang || "en");
|
|
166
|
-
const sourceLang = args?.sourceLang ? String(args.sourceLang) : (0, import_core.detectScriptLanguage)(text) ||
|
|
167
|
-
const
|
|
168
|
-
|
|
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) {
|
|
169
243
|
return {
|
|
170
244
|
isError: true,
|
|
171
|
-
content: [
|
|
245
|
+
content: [
|
|
246
|
+
{
|
|
247
|
+
type: "text",
|
|
248
|
+
text: `Unknown loadout or mode: ${loadoutId}. Known ids: ${modeIds(disk).join(", ")}`
|
|
249
|
+
}
|
|
250
|
+
]
|
|
172
251
|
};
|
|
173
252
|
}
|
|
253
|
+
const runMode = applyModeOverrides(mode, { reasoning, includeVocab });
|
|
174
254
|
const sanitized = (0, import_core.sanitizePromptForTranslation)(text);
|
|
175
255
|
const inputToTransform = sanitized.distilledText || text;
|
|
176
256
|
if (!llm.configured) {
|
|
@@ -182,9 +262,16 @@ function createLingualMcpServer() {
|
|
|
182
262
|
{
|
|
183
263
|
status: "unconfigured_zero_key_fallback",
|
|
184
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.",
|
|
185
|
-
|
|
265
|
+
mode: runMode.id,
|
|
266
|
+
reasoning: runMode.reasoning ?? "off",
|
|
186
267
|
distilledInput: inputToTransform,
|
|
187
|
-
compiledSystemPrompt: (0, import_core.compileModeSystemPrompt)(
|
|
268
|
+
compiledSystemPrompt: (0, import_core.compileModeSystemPrompt)(runMode, {
|
|
269
|
+
sourceLang,
|
|
270
|
+
targetLang,
|
|
271
|
+
explainLang,
|
|
272
|
+
globalKillList: disk.globalKillList,
|
|
273
|
+
extraContext: context
|
|
274
|
+
})
|
|
188
275
|
},
|
|
189
276
|
null,
|
|
190
277
|
2
|
|
@@ -194,12 +281,16 @@ function createLingualMcpServer() {
|
|
|
194
281
|
};
|
|
195
282
|
}
|
|
196
283
|
try {
|
|
197
|
-
const candidates = await (0, import_core.executeModeRunner)(inputToTransform,
|
|
284
|
+
const candidates = await (0, import_core.executeModeRunner)(inputToTransform, runMode, {
|
|
198
285
|
endpoint: llm.endpoint,
|
|
199
286
|
apiKey: llm.apiKey,
|
|
200
287
|
model: llm.model,
|
|
201
288
|
sourceLang,
|
|
202
|
-
targetLang
|
|
289
|
+
targetLang,
|
|
290
|
+
explainLang,
|
|
291
|
+
globalKillList: disk.globalKillList,
|
|
292
|
+
extraContext: context,
|
|
293
|
+
reasoning
|
|
203
294
|
});
|
|
204
295
|
if (!candidates || candidates.length === 0) {
|
|
205
296
|
return {
|
|
@@ -210,6 +301,7 @@ function createLingualMcpServer() {
|
|
|
210
301
|
{
|
|
211
302
|
status: "fallback",
|
|
212
303
|
message: "LLM endpoint did not return transformed candidates; returning original input.",
|
|
304
|
+
mode: runMode.id,
|
|
213
305
|
transformed: text
|
|
214
306
|
},
|
|
215
307
|
null,
|
|
@@ -228,7 +320,9 @@ function createLingualMcpServer() {
|
|
|
228
320
|
text: JSON.stringify(
|
|
229
321
|
{
|
|
230
322
|
status: "success",
|
|
323
|
+
mode: runMode.id,
|
|
231
324
|
loadout: loadoutId,
|
|
325
|
+
reasoning: runMode.reasoning ?? "off",
|
|
232
326
|
transformed: finalTransformed,
|
|
233
327
|
explanation: primary.explanation,
|
|
234
328
|
vocab: primary.vocab,
|
|
@@ -243,14 +337,19 @@ function createLingualMcpServer() {
|
|
|
243
337
|
} catch (err) {
|
|
244
338
|
return {
|
|
245
339
|
isError: true,
|
|
246
|
-
content: [{ type: "text", text: `Transformation failed: ${err
|
|
340
|
+
content: [{ type: "text", text: `Transformation failed: ${err instanceof Error ? err.message : String(err)}` }]
|
|
247
341
|
};
|
|
248
342
|
}
|
|
249
343
|
}
|
|
250
344
|
if (name === "lingual_bilingual_companion") {
|
|
251
345
|
const text = String(args?.text || "");
|
|
252
346
|
const targetLang = String(args?.targetLang || "en");
|
|
253
|
-
const sourceLang = args?.sourceLang ? String(args.sourceLang) : (0, import_core.detectScriptLanguage)(text) ||
|
|
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;
|
|
254
353
|
if (!llm.configured) {
|
|
255
354
|
return {
|
|
256
355
|
content: [
|
|
@@ -260,7 +359,12 @@ function createLingualMcpServer() {
|
|
|
260
359
|
{
|
|
261
360
|
status: "unconfigured_zero_key_fallback",
|
|
262
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.",
|
|
263
|
-
compiledSystemPrompt: (0, import_core.
|
|
362
|
+
compiledSystemPrompt: (0, import_core.compileModeSystemPrompt)(runMode ?? {}, {
|
|
363
|
+
sourceLang,
|
|
364
|
+
targetLang,
|
|
365
|
+
explainLang,
|
|
366
|
+
globalKillList: disk.globalKillList
|
|
367
|
+
}),
|
|
264
368
|
sourceText: text
|
|
265
369
|
},
|
|
266
370
|
null,
|
|
@@ -271,12 +375,17 @@ function createLingualMcpServer() {
|
|
|
271
375
|
};
|
|
272
376
|
}
|
|
273
377
|
try {
|
|
274
|
-
const result = await (0, import_core.
|
|
378
|
+
const result = await (0, import_core.translateCore)(text, {
|
|
275
379
|
endpoint: llm.endpoint,
|
|
276
380
|
apiKey: llm.apiKey,
|
|
277
381
|
model: llm.model,
|
|
278
382
|
sourceLang,
|
|
279
|
-
targetLang
|
|
383
|
+
targetLang,
|
|
384
|
+
explainLang,
|
|
385
|
+
slots: runMode?.slots,
|
|
386
|
+
killList: runMode?.killList,
|
|
387
|
+
globalKillList: disk.globalKillList,
|
|
388
|
+
reasoning: reasoning ?? runMode?.reasoning
|
|
280
389
|
});
|
|
281
390
|
if (!result) {
|
|
282
391
|
return {
|
|
@@ -319,7 +428,7 @@ function createLingualMcpServer() {
|
|
|
319
428
|
} catch (err) {
|
|
320
429
|
return {
|
|
321
430
|
isError: true,
|
|
322
|
-
content: [{ type: "text", text: `Companion mapping failed: ${err
|
|
431
|
+
content: [{ type: "text", text: `Companion mapping failed: ${err instanceof Error ? err.message : String(err)}` }]
|
|
323
432
|
};
|
|
324
433
|
}
|
|
325
434
|
}
|
|
@@ -327,20 +436,32 @@ function createLingualMcpServer() {
|
|
|
327
436
|
const loadoutId = String(args?.loadout || "spec");
|
|
328
437
|
const sourceLang = String(args?.sourceLang || "zh");
|
|
329
438
|
const targetLang = String(args?.targetLang || "en");
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
}
|
|
335
|
-
const preset = (0, import_core.getPresetLoadout)(loadoutId, sourceLang);
|
|
336
|
-
if (!preset) {
|
|
439
|
+
const explainLang = disk.explainLang || sourceLang;
|
|
440
|
+
const includeVocab = args?.includeVocab !== false;
|
|
441
|
+
const mode = resolveMode(loadoutId, sourceLang, explainLang, disk.modes);
|
|
442
|
+
if (!mode) {
|
|
337
443
|
return {
|
|
338
444
|
isError: true,
|
|
339
|
-
content: [
|
|
445
|
+
content: [
|
|
446
|
+
{
|
|
447
|
+
type: "text",
|
|
448
|
+
text: `Unknown loadout or mode: ${loadoutId}. Known ids: ${modeIds(disk, ["companion"]).join(", ")}`
|
|
449
|
+
}
|
|
450
|
+
]
|
|
340
451
|
};
|
|
341
452
|
}
|
|
342
453
|
return {
|
|
343
|
-
content: [
|
|
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
|
+
]
|
|
344
465
|
};
|
|
345
466
|
}
|
|
346
467
|
return {
|
|
@@ -374,11 +495,18 @@ function createLingualMcpServer() {
|
|
|
374
495
|
});
|
|
375
496
|
server.setRequestHandler(import_types.GetPromptRequestSchema, async (request) => {
|
|
376
497
|
const { name, arguments: args } = request.params;
|
|
377
|
-
const
|
|
498
|
+
const disk = readDisk();
|
|
499
|
+
const sourceLang = args?.source_lang || disk.sourceLang || "zh";
|
|
378
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
|
+
};
|
|
379
506
|
if (name === "spec_prompt") {
|
|
380
507
|
const idea = args?.raw_idea || "";
|
|
381
|
-
const sys = (
|
|
508
|
+
const sys = compile("spec");
|
|
509
|
+
if (!sys) throw new Error("Spec mode is unavailable");
|
|
382
510
|
return {
|
|
383
511
|
description: "Transform idea into an engineering specification",
|
|
384
512
|
messages: [
|
|
@@ -391,7 +519,8 @@ ${idea}` } }
|
|
|
391
519
|
}
|
|
392
520
|
if (name === "conventional_commit") {
|
|
393
521
|
const summary = args?.changes_summary || "";
|
|
394
|
-
const sys = (
|
|
522
|
+
const sys = compile("commit");
|
|
523
|
+
if (!sys) throw new Error("Commit mode is unavailable");
|
|
395
524
|
return {
|
|
396
525
|
description: "Transform change summary into Conventional Commit",
|
|
397
526
|
messages: [
|
|
@@ -413,7 +542,11 @@ async function runLingualMcpServer() {
|
|
|
413
542
|
}
|
|
414
543
|
// Annotate the CommonJS export names for ESM import in node:
|
|
415
544
|
0 && (module.exports = {
|
|
545
|
+
applyModeOverrides,
|
|
416
546
|
createLingualMcpServer,
|
|
547
|
+
normalizeReasoningArg,
|
|
417
548
|
resolveMcpLlmConfig,
|
|
418
|
-
|
|
549
|
+
resolveMode,
|
|
550
|
+
runLingualMcpServer,
|
|
551
|
+
stripVocabSlots
|
|
419
552
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
2
|
-
import { LingualConfig } from 'pi-lingual/core';
|
|
2
|
+
import { LingualConfig, CustomModeConfig, ReasoningEffort, PromptSlotConfig } from 'pi-lingual/core';
|
|
3
3
|
|
|
4
|
+
interface McpServerOptions {
|
|
5
|
+
/** Replaces the on-disk `lingual.json` snapshot; tests and embedders pin their own config. */
|
|
6
|
+
diskConfig?: Partial<LingualConfig>;
|
|
7
|
+
}
|
|
4
8
|
interface ResolvedMcpLlmConfig {
|
|
5
9
|
configured: boolean;
|
|
6
10
|
endpoint?: string;
|
|
@@ -8,7 +12,16 @@ interface ResolvedMcpLlmConfig {
|
|
|
8
12
|
model?: string;
|
|
9
13
|
}
|
|
10
14
|
declare function resolveMcpLlmConfig(diskConfig: Partial<LingualConfig>, env?: NodeJS.ProcessEnv): ResolvedMcpLlmConfig;
|
|
11
|
-
declare function
|
|
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;
|
|
12
25
|
declare function runLingualMcpServer(): Promise<void>;
|
|
13
26
|
|
|
14
|
-
export { type ResolvedMcpLlmConfig, createLingualMcpServer, resolveMcpLlmConfig, runLingualMcpServer };
|
|
27
|
+
export { type McpServerOptions, type ResolvedMcpLlmConfig, applyModeOverrides, createLingualMcpServer, normalizeReasoningArg, resolveMcpLlmConfig, resolveMode, runLingualMcpServer, stripVocabSlots };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
2
|
-
import { LingualConfig } from 'pi-lingual/core';
|
|
2
|
+
import { LingualConfig, CustomModeConfig, ReasoningEffort, PromptSlotConfig } from 'pi-lingual/core';
|
|
3
3
|
|
|
4
|
+
interface McpServerOptions {
|
|
5
|
+
/** Replaces the on-disk `lingual.json` snapshot; tests and embedders pin their own config. */
|
|
6
|
+
diskConfig?: Partial<LingualConfig>;
|
|
7
|
+
}
|
|
4
8
|
interface ResolvedMcpLlmConfig {
|
|
5
9
|
configured: boolean;
|
|
6
10
|
endpoint?: string;
|
|
@@ -8,7 +12,16 @@ interface ResolvedMcpLlmConfig {
|
|
|
8
12
|
model?: string;
|
|
9
13
|
}
|
|
10
14
|
declare function resolveMcpLlmConfig(diskConfig: Partial<LingualConfig>, env?: NodeJS.ProcessEnv): ResolvedMcpLlmConfig;
|
|
11
|
-
declare function
|
|
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;
|
|
12
25
|
declare function runLingualMcpServer(): Promise<void>;
|
|
13
26
|
|
|
14
|
-
export { type ResolvedMcpLlmConfig, createLingualMcpServer, resolveMcpLlmConfig, runLingualMcpServer };
|
|
27
|
+
export { type McpServerOptions, type ResolvedMcpLlmConfig, applyModeOverrides, createLingualMcpServer, normalizeReasoningArg, resolveMcpLlmConfig, resolveMode, runLingualMcpServer, stripVocabSlots };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
+
import { createRequire } from "module";
|
|
2
3
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
3
4
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
5
|
import {
|
|
@@ -8,17 +9,20 @@ import {
|
|
|
8
9
|
GetPromptRequestSchema
|
|
9
10
|
} from "@modelcontextprotocol/sdk/types.js";
|
|
10
11
|
import {
|
|
11
|
-
|
|
12
|
+
translateCore,
|
|
12
13
|
executeModeRunner,
|
|
13
14
|
compileModeSystemPrompt,
|
|
14
15
|
loadUserLingualConfig,
|
|
15
16
|
getPresetLoadout,
|
|
16
|
-
buildSystemPrompt,
|
|
17
17
|
sanitizePromptForTranslation,
|
|
18
18
|
ensureCodeTokensPreserved,
|
|
19
19
|
detectScriptLanguage
|
|
20
20
|
} from "pi-lingual/core";
|
|
21
|
-
var
|
|
21
|
+
var require2 = createRequire(import.meta.url);
|
|
22
|
+
var manifest = require2("../package.json");
|
|
23
|
+
var PKG_VERSION = typeof manifest.version === "string" ? manifest.version : "0.0.0";
|
|
24
|
+
var REASONING_LEVELS = ["off", "minimal", "low", "medium", "high"];
|
|
25
|
+
var PRESET_IDS = ["spec", "commit", "oss", "yap", "direct"];
|
|
22
26
|
function isLoopbackUrl(urlStr) {
|
|
23
27
|
try {
|
|
24
28
|
const parsed = new URL(urlStr);
|
|
@@ -47,7 +51,35 @@ function resolveMcpLlmConfig(diskConfig, env = process.env) {
|
|
|
47
51
|
model: rawModel || "gpt-4o-mini"
|
|
48
52
|
};
|
|
49
53
|
}
|
|
50
|
-
function
|
|
54
|
+
function normalizeReasoningArg(raw) {
|
|
55
|
+
const value = typeof raw === "string" ? raw.trim().toLowerCase() : "";
|
|
56
|
+
return REASONING_LEVELS.includes(value) ? value : void 0;
|
|
57
|
+
}
|
|
58
|
+
function resolveMode(id, sourceLang, explainLang, custom) {
|
|
59
|
+
const wanted = (id || "").trim().toLowerCase();
|
|
60
|
+
if (!wanted) return null;
|
|
61
|
+
const userMode = (custom || []).find((mode) => mode.id.toLowerCase() === wanted && mode.enabled !== false);
|
|
62
|
+
if (userMode) return userMode;
|
|
63
|
+
return getPresetLoadout(wanted, sourceLang, explainLang);
|
|
64
|
+
}
|
|
65
|
+
function stripVocabSlots(slots) {
|
|
66
|
+
return slots ? slots.filter((slot) => slot.role !== "vocab") : slots;
|
|
67
|
+
}
|
|
68
|
+
function applyModeOverrides(mode, options) {
|
|
69
|
+
const next = { ...mode };
|
|
70
|
+
if (options.reasoning) next.reasoning = options.reasoning;
|
|
71
|
+
if (options.includeVocab === false) {
|
|
72
|
+
next.vocab = false;
|
|
73
|
+
next.slots = stripVocabSlots(next.slots);
|
|
74
|
+
}
|
|
75
|
+
return next;
|
|
76
|
+
}
|
|
77
|
+
function modeIds(disk, extra = []) {
|
|
78
|
+
const custom = (disk.modes || []).filter((mode) => mode.enabled !== false).map((mode) => mode.id);
|
|
79
|
+
return Array.from(/* @__PURE__ */ new Set([...extra, ...PRESET_IDS, ...custom]));
|
|
80
|
+
}
|
|
81
|
+
function createLingualMcpServer(options = {}) {
|
|
82
|
+
const readDisk = () => options.diskConfig ?? loadUserLingualConfig();
|
|
51
83
|
const server = new Server(
|
|
52
84
|
{
|
|
53
85
|
name: "lingual-mcp",
|
|
@@ -61,11 +93,14 @@ function createLingualMcpServer() {
|
|
|
61
93
|
}
|
|
62
94
|
);
|
|
63
95
|
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
96
|
+
const disk = readDisk();
|
|
97
|
+
const transformIds = modeIds(disk);
|
|
98
|
+
const templateIds = modeIds(disk, ["companion"]);
|
|
64
99
|
return {
|
|
65
100
|
tools: [
|
|
66
101
|
{
|
|
67
102
|
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.",
|
|
103
|
+
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.",
|
|
69
104
|
inputSchema: {
|
|
70
105
|
type: "object",
|
|
71
106
|
properties: {
|
|
@@ -75,8 +110,8 @@ function createLingualMcpServer() {
|
|
|
75
110
|
},
|
|
76
111
|
loadout: {
|
|
77
112
|
type: "string",
|
|
78
|
-
enum:
|
|
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' (
|
|
113
|
+
enum: transformIds,
|
|
114
|
+
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'.",
|
|
80
115
|
default: "spec"
|
|
81
116
|
},
|
|
82
117
|
sourceLang: {
|
|
@@ -87,6 +122,20 @@ function createLingualMcpServer() {
|
|
|
87
122
|
type: "string",
|
|
88
123
|
description: "Target language code (e.g. 'en', 'ja', 'zh'). Default: 'en'.",
|
|
89
124
|
default: "en"
|
|
125
|
+
},
|
|
126
|
+
reasoning: {
|
|
127
|
+
type: "string",
|
|
128
|
+
enum: REASONING_LEVELS,
|
|
129
|
+
description: "Thinking effort for this call. Overrides the mode's pinned level (spec pins 'low', the rest pin 'off')."
|
|
130
|
+
},
|
|
131
|
+
context: {
|
|
132
|
+
type: "string",
|
|
133
|
+
description: "Extra context for context-aware modes, such as a staged git diff for 'commit' or the previous agent turn."
|
|
134
|
+
},
|
|
135
|
+
includeVocab: {
|
|
136
|
+
type: "boolean",
|
|
137
|
+
description: "Set false to drop the vocabulary slot from the prompt and the response. Default: true.",
|
|
138
|
+
default: true
|
|
90
139
|
}
|
|
91
140
|
},
|
|
92
141
|
required: ["text"]
|
|
@@ -110,6 +159,16 @@ function createLingualMcpServer() {
|
|
|
110
159
|
type: "string",
|
|
111
160
|
description: "Target language code (e.g. 'en', 'ja'). Default: 'en'.",
|
|
112
161
|
default: "en"
|
|
162
|
+
},
|
|
163
|
+
reasoning: {
|
|
164
|
+
type: "string",
|
|
165
|
+
enum: REASONING_LEVELS,
|
|
166
|
+
description: "Thinking effort for this call. Defaults to the companion mode's level ('off')."
|
|
167
|
+
},
|
|
168
|
+
includeVocab: {
|
|
169
|
+
type: "boolean",
|
|
170
|
+
description: "Set false to drop the vocabulary slot from the prompt and the response. Default: true.",
|
|
171
|
+
default: true
|
|
113
172
|
}
|
|
114
173
|
},
|
|
115
174
|
required: ["text"]
|
|
@@ -117,14 +176,14 @@ function createLingualMcpServer() {
|
|
|
117
176
|
},
|
|
118
177
|
{
|
|
119
178
|
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.",
|
|
179
|
+
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.",
|
|
121
180
|
inputSchema: {
|
|
122
181
|
type: "object",
|
|
123
182
|
properties: {
|
|
124
183
|
loadout: {
|
|
125
184
|
type: "string",
|
|
126
|
-
enum:
|
|
127
|
-
description: "Target mode or loadout.",
|
|
185
|
+
enum: templateIds,
|
|
186
|
+
description: "Target mode or loadout id: any preset, 'companion', or a custom mode id from lingual.json.",
|
|
128
187
|
default: "spec"
|
|
129
188
|
},
|
|
130
189
|
sourceLang: {
|
|
@@ -136,6 +195,11 @@ function createLingualMcpServer() {
|
|
|
136
195
|
type: "string",
|
|
137
196
|
description: "Target language code (e.g. 'en', 'ja'). Default: 'en'.",
|
|
138
197
|
default: "en"
|
|
198
|
+
},
|
|
199
|
+
includeVocab: {
|
|
200
|
+
type: "boolean",
|
|
201
|
+
description: "Set false to drop the vocabulary slot from the compiled prompt. Default: true.",
|
|
202
|
+
default: true
|
|
139
203
|
}
|
|
140
204
|
},
|
|
141
205
|
required: ["loadout"]
|
|
@@ -146,20 +210,30 @@ function createLingualMcpServer() {
|
|
|
146
210
|
});
|
|
147
211
|
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
148
212
|
const { name, arguments: args } = request.params;
|
|
149
|
-
const
|
|
150
|
-
const llm = resolveMcpLlmConfig(
|
|
213
|
+
const disk = readDisk();
|
|
214
|
+
const llm = resolveMcpLlmConfig(disk);
|
|
151
215
|
if (name === "lingual_transform_spec") {
|
|
152
216
|
const text = String(args?.text || "");
|
|
153
217
|
const loadoutId = String(args?.loadout || "spec");
|
|
154
218
|
const targetLang = String(args?.targetLang || "en");
|
|
155
|
-
const sourceLang = args?.sourceLang ? String(args.sourceLang) : detectScriptLanguage(text) ||
|
|
156
|
-
const
|
|
157
|
-
|
|
219
|
+
const sourceLang = args?.sourceLang ? String(args.sourceLang) : detectScriptLanguage(text) || disk.sourceLang || "zh";
|
|
220
|
+
const explainLang = disk.explainLang || sourceLang;
|
|
221
|
+
const reasoning = normalizeReasoningArg(args?.reasoning);
|
|
222
|
+
const includeVocab = args?.includeVocab !== false;
|
|
223
|
+
const context = typeof args?.context === "string" && args.context.trim() ? args.context.trim() : void 0;
|
|
224
|
+
const mode = resolveMode(loadoutId, sourceLang, explainLang, disk.modes);
|
|
225
|
+
if (!mode) {
|
|
158
226
|
return {
|
|
159
227
|
isError: true,
|
|
160
|
-
content: [
|
|
228
|
+
content: [
|
|
229
|
+
{
|
|
230
|
+
type: "text",
|
|
231
|
+
text: `Unknown loadout or mode: ${loadoutId}. Known ids: ${modeIds(disk).join(", ")}`
|
|
232
|
+
}
|
|
233
|
+
]
|
|
161
234
|
};
|
|
162
235
|
}
|
|
236
|
+
const runMode = applyModeOverrides(mode, { reasoning, includeVocab });
|
|
163
237
|
const sanitized = sanitizePromptForTranslation(text);
|
|
164
238
|
const inputToTransform = sanitized.distilledText || text;
|
|
165
239
|
if (!llm.configured) {
|
|
@@ -171,9 +245,16 @@ function createLingualMcpServer() {
|
|
|
171
245
|
{
|
|
172
246
|
status: "unconfigured_zero_key_fallback",
|
|
173
247
|
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
|
-
|
|
248
|
+
mode: runMode.id,
|
|
249
|
+
reasoning: runMode.reasoning ?? "off",
|
|
175
250
|
distilledInput: inputToTransform,
|
|
176
|
-
compiledSystemPrompt: compileModeSystemPrompt(
|
|
251
|
+
compiledSystemPrompt: compileModeSystemPrompt(runMode, {
|
|
252
|
+
sourceLang,
|
|
253
|
+
targetLang,
|
|
254
|
+
explainLang,
|
|
255
|
+
globalKillList: disk.globalKillList,
|
|
256
|
+
extraContext: context
|
|
257
|
+
})
|
|
177
258
|
},
|
|
178
259
|
null,
|
|
179
260
|
2
|
|
@@ -183,12 +264,16 @@ function createLingualMcpServer() {
|
|
|
183
264
|
};
|
|
184
265
|
}
|
|
185
266
|
try {
|
|
186
|
-
const candidates = await executeModeRunner(inputToTransform,
|
|
267
|
+
const candidates = await executeModeRunner(inputToTransform, runMode, {
|
|
187
268
|
endpoint: llm.endpoint,
|
|
188
269
|
apiKey: llm.apiKey,
|
|
189
270
|
model: llm.model,
|
|
190
271
|
sourceLang,
|
|
191
|
-
targetLang
|
|
272
|
+
targetLang,
|
|
273
|
+
explainLang,
|
|
274
|
+
globalKillList: disk.globalKillList,
|
|
275
|
+
extraContext: context,
|
|
276
|
+
reasoning
|
|
192
277
|
});
|
|
193
278
|
if (!candidates || candidates.length === 0) {
|
|
194
279
|
return {
|
|
@@ -199,6 +284,7 @@ function createLingualMcpServer() {
|
|
|
199
284
|
{
|
|
200
285
|
status: "fallback",
|
|
201
286
|
message: "LLM endpoint did not return transformed candidates; returning original input.",
|
|
287
|
+
mode: runMode.id,
|
|
202
288
|
transformed: text
|
|
203
289
|
},
|
|
204
290
|
null,
|
|
@@ -217,7 +303,9 @@ function createLingualMcpServer() {
|
|
|
217
303
|
text: JSON.stringify(
|
|
218
304
|
{
|
|
219
305
|
status: "success",
|
|
306
|
+
mode: runMode.id,
|
|
220
307
|
loadout: loadoutId,
|
|
308
|
+
reasoning: runMode.reasoning ?? "off",
|
|
221
309
|
transformed: finalTransformed,
|
|
222
310
|
explanation: primary.explanation,
|
|
223
311
|
vocab: primary.vocab,
|
|
@@ -232,14 +320,19 @@ function createLingualMcpServer() {
|
|
|
232
320
|
} catch (err) {
|
|
233
321
|
return {
|
|
234
322
|
isError: true,
|
|
235
|
-
content: [{ type: "text", text: `Transformation failed: ${err
|
|
323
|
+
content: [{ type: "text", text: `Transformation failed: ${err instanceof Error ? err.message : String(err)}` }]
|
|
236
324
|
};
|
|
237
325
|
}
|
|
238
326
|
}
|
|
239
327
|
if (name === "lingual_bilingual_companion") {
|
|
240
328
|
const text = String(args?.text || "");
|
|
241
329
|
const targetLang = String(args?.targetLang || "en");
|
|
242
|
-
const sourceLang = args?.sourceLang ? String(args.sourceLang) : detectScriptLanguage(text) ||
|
|
330
|
+
const sourceLang = args?.sourceLang ? String(args.sourceLang) : detectScriptLanguage(text) || disk.sourceLang || "zh";
|
|
331
|
+
const explainLang = disk.explainLang || sourceLang;
|
|
332
|
+
const reasoning = normalizeReasoningArg(args?.reasoning);
|
|
333
|
+
const includeVocab = args?.includeVocab !== false;
|
|
334
|
+
const companion = resolveMode("companion", sourceLang, explainLang, disk.modes);
|
|
335
|
+
const runMode = companion ? applyModeOverrides(companion, { reasoning, includeVocab }) : null;
|
|
243
336
|
if (!llm.configured) {
|
|
244
337
|
return {
|
|
245
338
|
content: [
|
|
@@ -249,7 +342,12 @@ function createLingualMcpServer() {
|
|
|
249
342
|
{
|
|
250
343
|
status: "unconfigured_zero_key_fallback",
|
|
251
344
|
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:
|
|
345
|
+
compiledSystemPrompt: compileModeSystemPrompt(runMode ?? {}, {
|
|
346
|
+
sourceLang,
|
|
347
|
+
targetLang,
|
|
348
|
+
explainLang,
|
|
349
|
+
globalKillList: disk.globalKillList
|
|
350
|
+
}),
|
|
253
351
|
sourceText: text
|
|
254
352
|
},
|
|
255
353
|
null,
|
|
@@ -260,12 +358,17 @@ function createLingualMcpServer() {
|
|
|
260
358
|
};
|
|
261
359
|
}
|
|
262
360
|
try {
|
|
263
|
-
const result = await
|
|
361
|
+
const result = await translateCore(text, {
|
|
264
362
|
endpoint: llm.endpoint,
|
|
265
363
|
apiKey: llm.apiKey,
|
|
266
364
|
model: llm.model,
|
|
267
365
|
sourceLang,
|
|
268
|
-
targetLang
|
|
366
|
+
targetLang,
|
|
367
|
+
explainLang,
|
|
368
|
+
slots: runMode?.slots,
|
|
369
|
+
killList: runMode?.killList,
|
|
370
|
+
globalKillList: disk.globalKillList,
|
|
371
|
+
reasoning: reasoning ?? runMode?.reasoning
|
|
269
372
|
});
|
|
270
373
|
if (!result) {
|
|
271
374
|
return {
|
|
@@ -308,7 +411,7 @@ function createLingualMcpServer() {
|
|
|
308
411
|
} catch (err) {
|
|
309
412
|
return {
|
|
310
413
|
isError: true,
|
|
311
|
-
content: [{ type: "text", text: `Companion mapping failed: ${err
|
|
414
|
+
content: [{ type: "text", text: `Companion mapping failed: ${err instanceof Error ? err.message : String(err)}` }]
|
|
312
415
|
};
|
|
313
416
|
}
|
|
314
417
|
}
|
|
@@ -316,20 +419,32 @@ function createLingualMcpServer() {
|
|
|
316
419
|
const loadoutId = String(args?.loadout || "spec");
|
|
317
420
|
const sourceLang = String(args?.sourceLang || "zh");
|
|
318
421
|
const targetLang = String(args?.targetLang || "en");
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
}
|
|
324
|
-
const preset = getPresetLoadout(loadoutId, sourceLang);
|
|
325
|
-
if (!preset) {
|
|
422
|
+
const explainLang = disk.explainLang || sourceLang;
|
|
423
|
+
const includeVocab = args?.includeVocab !== false;
|
|
424
|
+
const mode = resolveMode(loadoutId, sourceLang, explainLang, disk.modes);
|
|
425
|
+
if (!mode) {
|
|
326
426
|
return {
|
|
327
427
|
isError: true,
|
|
328
|
-
content: [
|
|
428
|
+
content: [
|
|
429
|
+
{
|
|
430
|
+
type: "text",
|
|
431
|
+
text: `Unknown loadout or mode: ${loadoutId}. Known ids: ${modeIds(disk, ["companion"]).join(", ")}`
|
|
432
|
+
}
|
|
433
|
+
]
|
|
329
434
|
};
|
|
330
435
|
}
|
|
331
436
|
return {
|
|
332
|
-
content: [
|
|
437
|
+
content: [
|
|
438
|
+
{
|
|
439
|
+
type: "text",
|
|
440
|
+
text: compileModeSystemPrompt(applyModeOverrides(mode, { includeVocab }), {
|
|
441
|
+
sourceLang,
|
|
442
|
+
targetLang,
|
|
443
|
+
explainLang,
|
|
444
|
+
globalKillList: disk.globalKillList
|
|
445
|
+
})
|
|
446
|
+
}
|
|
447
|
+
]
|
|
333
448
|
};
|
|
334
449
|
}
|
|
335
450
|
return {
|
|
@@ -363,11 +478,18 @@ function createLingualMcpServer() {
|
|
|
363
478
|
});
|
|
364
479
|
server.setRequestHandler(GetPromptRequestSchema, async (request) => {
|
|
365
480
|
const { name, arguments: args } = request.params;
|
|
366
|
-
const
|
|
481
|
+
const disk = readDisk();
|
|
482
|
+
const sourceLang = args?.source_lang || disk.sourceLang || "zh";
|
|
367
483
|
const targetLang = args?.target_lang || "en";
|
|
484
|
+
const explainLang = disk.explainLang || sourceLang;
|
|
485
|
+
const compile = (modeId) => {
|
|
486
|
+
const mode = resolveMode(modeId, sourceLang, explainLang, disk.modes);
|
|
487
|
+
return mode ? compileModeSystemPrompt(mode, { sourceLang, targetLang, explainLang, globalKillList: disk.globalKillList }) : null;
|
|
488
|
+
};
|
|
368
489
|
if (name === "spec_prompt") {
|
|
369
490
|
const idea = args?.raw_idea || "";
|
|
370
|
-
const sys =
|
|
491
|
+
const sys = compile("spec");
|
|
492
|
+
if (!sys) throw new Error("Spec mode is unavailable");
|
|
371
493
|
return {
|
|
372
494
|
description: "Transform idea into an engineering specification",
|
|
373
495
|
messages: [
|
|
@@ -380,7 +502,8 @@ ${idea}` } }
|
|
|
380
502
|
}
|
|
381
503
|
if (name === "conventional_commit") {
|
|
382
504
|
const summary = args?.changes_summary || "";
|
|
383
|
-
const sys =
|
|
505
|
+
const sys = compile("commit");
|
|
506
|
+
if (!sys) throw new Error("Commit mode is unavailable");
|
|
384
507
|
return {
|
|
385
508
|
description: "Transform change summary into Conventional Commit",
|
|
386
509
|
messages: [
|
|
@@ -401,7 +524,11 @@ async function runLingualMcpServer() {
|
|
|
401
524
|
await server.connect(transport);
|
|
402
525
|
}
|
|
403
526
|
export {
|
|
527
|
+
applyModeOverrides,
|
|
404
528
|
createLingualMcpServer,
|
|
529
|
+
normalizeReasoningArg,
|
|
405
530
|
resolveMcpLlmConfig,
|
|
406
|
-
|
|
531
|
+
resolveMode,
|
|
532
|
+
runLingualMcpServer,
|
|
533
|
+
stripVocabSlots
|
|
407
534
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lingual-mcp",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
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
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|