@lefine/mcp 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Better i18n
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,60 @@
1
- # Temporary Holding Version
1
+ # @lefine/mcp
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Lefine for AI agents. Claude, Cursor and other MCP clients can translate your app, edit and publish
4
+ website pages, and make localized videos, with you approving anything that goes live.
5
+
6
+ ## Sign in
7
+
8
+ ```sh
9
+ npx @lefine/cli login
10
+ ```
11
+
12
+ Or set `LEFINE_TOKEN` to a key from Lefine, Settings > API keys. To let the agent reach Content,
13
+ Studio or your connected apps, make the key there and tick them under "Also reach".
14
+
15
+ ## Add it to your client
16
+
17
+ **Claude Desktop** (`claude_desktop_config.json`), and any client that starts a local server:
18
+
19
+ ```json
20
+ {
21
+ "mcpServers": {
22
+ "lefine": { "command": "npx", "args": ["-y", "@lefine/mcp"] }
23
+ }
24
+ }
25
+ ```
26
+
27
+ **Claude, ChatGPT, Claude Code, Cursor, VS Code and other remote-capable clients** can skip this
28
+ package and connect to the server directly. They sign in to Lefine with OAuth, so there is no key to
29
+ copy:
30
+
31
+ ```sh
32
+ claude mcp add --transport http lefine https://dash.lefine.ai/v1/mcp
33
+ ```
34
+
35
+ In Claude, add the same URL under Settings > Connectors > Add custom connector. A key also works:
36
+ add `--header "Authorization: Bearer <key>"`.
37
+
38
+ ## What the agent gets
39
+
40
+ Five tools, whatever your plan:
41
+
42
+ | Tool | What it does |
43
+ |---|---|
44
+ | `lefine_context` | The workspace, the modules that are on, and what the key may do. |
45
+ | `lefine_find` | Find an action by words, with its input schema. |
46
+ | `lefine_read` | Run an action that only reads. |
47
+ | `lefine_write` | Run an action that writes drafts. Nothing goes live. |
48
+ | `lefine_publish` | Run an action that goes live or spends credits. It asks you first. |
49
+
50
+ Every action, with what it needs: [docs/mcp-actions.md](https://github.com/lefinehq/lefine/blob/main/docs/mcp-actions.md).
51
+
52
+ The tools live on Lefine's server, so a new action reaches you without updating this package.
53
+
54
+ ## Options
55
+
56
+ - `LEFINE_TOKEN`: the key to use (wins over the saved one).
57
+ - `LEFINE_API_URL`: another Lefine server. A saved key is only sent to the server it was saved for.
58
+ - `lefine-mcp --version`, `lefine-mcp --help`.
59
+
60
+ Logs go to stderr; stdout carries only MCP messages.
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Lefine credentials: `~/.lefine/credentials.json` (dir 0700, file 0600).
3
+ * `LEFINE_TOKEN` wins over the file so CI never needs one.
4
+ */
5
+ import { chmodSync, existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from "node:fs";
6
+ import { homedir } from "node:os";
7
+ import { join } from "node:path";
8
+ export const DEFAULT_API_URL = "https://dash.lefine.ai";
9
+ export const DEFAULT_CDN_URL = "https://cdn.lefine.ai";
10
+ /** Read per call so tests (and users) can point `LEFINE_HOME` elsewhere. */
11
+ const configDir = () => process.env.LEFINE_HOME || join(homedir(), ".lefine");
12
+ export const credentialsPath = () => join(configDir(), "credentials.json");
13
+ export function saveCredentials(creds) {
14
+ const dir = configDir();
15
+ mkdirSync(dir, { recursive: true, mode: 0o700 });
16
+ chmodSync(dir, 0o700);
17
+ const file = credentialsPath();
18
+ // `mode` only applies when the file is created; chmod covers an existing looser one.
19
+ writeFileSync(file, JSON.stringify(creds, null, 2) + "\n", { encoding: "utf-8", mode: 0o600 });
20
+ chmodSync(file, 0o600);
21
+ }
22
+ export function loadCredentials() {
23
+ const file = credentialsPath();
24
+ if (!existsSync(file))
25
+ return null;
26
+ try {
27
+ const parsed = JSON.parse(readFileSync(file, "utf-8"));
28
+ return typeof parsed.token === "string" && typeof parsed.apiUrl === "string"
29
+ ? parsed
30
+ : null;
31
+ }
32
+ catch {
33
+ return null;
34
+ }
35
+ }
36
+ export function clearCredentials() {
37
+ const file = credentialsPath();
38
+ if (!existsSync(file))
39
+ return false;
40
+ unlinkSync(file);
41
+ return true;
42
+ }
43
+ export const resolveApiUrl = (flag) => (flag || process.env.LEFINE_API_URL || DEFAULT_API_URL).replace(/\/+$/, "");
44
+ export function resolveLefineAuth(options) {
45
+ if (options.token) {
46
+ return { token: options.token, apiUrl: resolveApiUrl(options.apiUrl), source: "flag" };
47
+ }
48
+ if (process.env.LEFINE_TOKEN) {
49
+ return { token: process.env.LEFINE_TOKEN, apiUrl: resolveApiUrl(options.apiUrl), source: "env" };
50
+ }
51
+ const stored = loadCredentials();
52
+ if (stored) {
53
+ // A saved key is only ever sent to the server it was saved for. Any other
54
+ // origin (flag, env var) must not receive it.
55
+ const saved = stored.apiUrl.replace(/\/+$/, "");
56
+ const override = options.apiUrl || process.env.LEFINE_API_URL;
57
+ if (override && resolveApiUrl(override) !== saved) {
58
+ throw new Error(`This key belongs to ${saved}. Run \`lefine login --api-url ${resolveApiUrl(override)}\` to use another server.`);
59
+ }
60
+ return { token: stored.token, apiUrl: saved, source: "file" };
61
+ }
62
+ return null;
63
+ }
@@ -0,0 +1,117 @@
1
+ /**
2
+ * The Lefine MCP bridge: stdio on one side, Lefine's remote MCP server (POST /v1/mcp) on the other.
3
+ * For clients that only start local servers (Claude Desktop config, some IDEs). It adds the access key
4
+ * and forwards each message as it is; the server holds every tool and every rule, so the bridge never
5
+ * needs a release when an action is added.
6
+ *
7
+ * Both MCP eras pass through. A modern (2026-07-28) message names its version in `_meta`, and the bridge
8
+ * mirrors it in the MCP-Protocol-Version, Mcp-Method and Mcp-Name headers the server checks. A legacy
9
+ * message gets the version the `initialize` answer agreed on.
10
+ *
11
+ * stdout carries only JSON-RPC, one message per line; anything for people goes to stderr.
12
+ */
13
+ const NO_KEY = "Lefine is not signed in. Run `npx @lefine/cli login`, or set LEFINE_TOKEN to a key from Settings > API keys (tick Content or Studio there if the agent needs them).";
14
+ /** Header-safe ASCII, or the `=?base64?...?=` sentinel the spec defines for other values. */
15
+ function headerValue(value) {
16
+ if (/^[\x20-\x7e]*$/.test(value))
17
+ return value;
18
+ const bytes = new TextEncoder().encode(value);
19
+ return `=?base64?${Buffer.from(bytes).toString("base64")}?=`;
20
+ }
21
+ export function createBridge(deps) {
22
+ /** The legacy version `initialize` agreed on; sent on every later legacy request. */
23
+ let legacyVersion;
24
+ const reply = (id, code, message) => {
25
+ if (id === undefined || id === null)
26
+ return;
27
+ deps.write(JSON.stringify({ jsonrpc: "2.0", id, error: { code, message } }));
28
+ };
29
+ async function handle(line) {
30
+ const text = line.trim();
31
+ if (!text)
32
+ return;
33
+ let msg;
34
+ try {
35
+ msg = JSON.parse(text);
36
+ }
37
+ catch {
38
+ deps.write(JSON.stringify({ jsonrpc: "2.0", id: null, error: { code: -32700, message: "The message is not JSON." } }));
39
+ return;
40
+ }
41
+ // A response from the client (to a server request) has no method; this server never sends requests.
42
+ if (typeof msg.method !== "string")
43
+ return;
44
+ if (!deps.auth) {
45
+ reply(msg.id, -32001, NO_KEY);
46
+ return;
47
+ }
48
+ const meta = (msg.params?._meta ?? {});
49
+ const modernVersion = typeof meta["io.modelcontextprotocol/protocolVersion"] === "string" ? meta["io.modelcontextprotocol/protocolVersion"] : undefined;
50
+ const headers = {
51
+ "content-type": "application/json",
52
+ accept: "application/json, text/event-stream",
53
+ authorization: `Bearer ${deps.auth.token}`,
54
+ "user-agent": `lefine-mcp/${deps.clientVersion}`,
55
+ };
56
+ if (modernVersion) {
57
+ headers["mcp-protocol-version"] = modernVersion;
58
+ headers["mcp-method"] = msg.method;
59
+ const name = msg.params?.name ?? msg.params?.uri;
60
+ if (typeof name === "string")
61
+ headers["mcp-name"] = headerValue(name);
62
+ }
63
+ else if (legacyVersion && msg.method !== "initialize") {
64
+ headers["mcp-protocol-version"] = legacyVersion;
65
+ }
66
+ let res;
67
+ try {
68
+ res = await deps.fetch(`${deps.auth.apiUrl}/v1/mcp`, { method: "POST", headers, body: text });
69
+ }
70
+ catch {
71
+ reply(msg.id, -32603, `Could not reach Lefine at ${deps.auth.apiUrl}. Check the connection and try again.`);
72
+ return;
73
+ }
74
+ if (res.status === 202)
75
+ return;
76
+ const body = await res.text();
77
+ let parsed = null;
78
+ try {
79
+ parsed = body ? JSON.parse(body) : null;
80
+ }
81
+ catch {
82
+ parsed = null;
83
+ }
84
+ if (!parsed) {
85
+ reply(msg.id, -32603, `Lefine answered HTTP ${res.status} without a JSON-RPC message.`);
86
+ return;
87
+ }
88
+ if (msg.method === "initialize" && typeof parsed.result?.protocolVersion === "string")
89
+ legacyVersion = parsed.result.protocolVersion;
90
+ if (res.status === 401)
91
+ deps.log("lefine-mcp: the key was refused. Run `npx @lefine/cli login` again or check LEFINE_TOKEN.");
92
+ // The server answers some refusals (no key, bad JSON) before it reads the id; the client is waiting for its own.
93
+ if (parsed.id === null && msg.id !== undefined && msg.id !== null)
94
+ parsed = { ...parsed, id: msg.id };
95
+ deps.write(JSON.stringify(parsed));
96
+ }
97
+ return { handle };
98
+ }
99
+ /** Reads newline-delimited JSON-RPC from a stream and handles each message; messages may run concurrently. */
100
+ export async function runBridge(input, deps) {
101
+ const bridge = createBridge(deps);
102
+ const pending = new Set();
103
+ let buffer = "";
104
+ for await (const chunk of input) {
105
+ buffer += chunk.toString();
106
+ let at;
107
+ while ((at = buffer.indexOf("\n")) >= 0) {
108
+ const line = buffer.slice(0, at);
109
+ buffer = buffer.slice(at + 1);
110
+ const p = bridge.handle(line).finally(() => pending.delete(p));
111
+ pending.add(p);
112
+ }
113
+ }
114
+ if (buffer.trim())
115
+ pending.add(bridge.handle(buffer));
116
+ await Promise.all(pending);
117
+ }
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * `lefine-mcp`: Lefine's MCP server for clients that start a local process (Claude Desktop, IDE configs).
4
+ * It bridges stdio to https://dash.lefine.ai/v1/mcp with your key. Clients that speak remote MCP can
5
+ * use that URL directly instead.
6
+ *
7
+ * Key: LEFINE_TOKEN, else the one `lefine login` saved. No project env files are read, on purpose: a
8
+ * cloned project must not be able to redirect the key (same rule as the `lefine` CLI).
9
+ */
10
+ import { readFileSync } from "node:fs";
11
+ import { resolveLefineAuth } from "./lefine/credentials.js";
12
+ import { runBridge } from "./lefine/mcp-bridge.js";
13
+ const pkg = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf-8"));
14
+ const args = process.argv.slice(2);
15
+ if (args.includes("--version")) {
16
+ process.stdout.write(`${pkg.version}\n`);
17
+ process.exit(0);
18
+ }
19
+ if (args.includes("--help")) {
20
+ process.stderr.write([
21
+ "lefine-mcp: Lefine as a local MCP server (stdio).",
22
+ "",
23
+ "Sign in once: npx @lefine/cli login (or set LEFINE_TOKEN)",
24
+ 'Claude Desktop: { "mcpServers": { "lefine": { "command": "npx", "args": ["-y", "@lefine/mcp"] } } }',
25
+ "Remote clients can skip this and use https://dash.lefine.ai/v1/mcp with the header Authorization: Bearer <key>.",
26
+ "",
27
+ ].join("\n"));
28
+ process.exit(0);
29
+ }
30
+ let auth = null;
31
+ try {
32
+ const found = resolveLefineAuth({});
33
+ auth = found ? { token: found.token, apiUrl: found.apiUrl } : null;
34
+ }
35
+ catch (error) {
36
+ process.stderr.write(`lefine-mcp: ${error instanceof Error ? error.message : String(error)}\n`);
37
+ }
38
+ if (!auth)
39
+ process.stderr.write("lefine-mcp: not signed in. Run `npx @lefine/cli login` or set LEFINE_TOKEN.\n");
40
+ await runBridge(process.stdin, {
41
+ auth,
42
+ fetch,
43
+ write: (line) => process.stdout.write(`${line}\n`),
44
+ log: (line) => process.stderr.write(`${line}\n`),
45
+ clientVersion: pkg.version,
46
+ });
package/package.json CHANGED
@@ -1,6 +1,45 @@
1
1
  {
2
2
  "name": "@lefine/mcp",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Lefine as an MCP server for Claude Desktop, Cursor and other agents: localization, website content and localized videos",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "bin": {
8
+ "lefine-mcp": "./dist/lefine-mcp.js"
9
+ },
10
+ "files": [
11
+ "dist",
12
+ "README.md",
13
+ "LICENSE"
14
+ ],
15
+ "publishConfig": {
16
+ "access": "public"
17
+ },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "https://github.com/lefinehq/oss.git",
21
+ "directory": "packages/lefine-mcp"
22
+ },
23
+ "homepage": "https://lefine.ai",
24
+ "keywords": [
25
+ "lefine",
26
+ "mcp",
27
+ "model-context-protocol",
28
+ "i18n",
29
+ "localization",
30
+ "claude"
31
+ ],
32
+ "scripts": {
33
+ "build": "tsc",
34
+ "typecheck": "tsc --noEmit",
35
+ "clean": "rm -rf dist",
36
+ "prepublishOnly": "npm run clean && npm run build"
37
+ },
38
+ "devDependencies": {
39
+ "@types/node": "^20.19.43",
40
+ "typescript": "~5.9.2"
41
+ },
42
+ "engines": {
43
+ "node": ">=20"
44
+ }
45
+ }