lingual-mcp 0.1.0 → 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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "lingual-mcp",
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.",
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
- "require": "./dist/index.cjs"
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,cjs --dts --clean --no-splitting",
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,419 +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
- 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 DELETED
@@ -1,14 +0,0 @@
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 };