@lefine/mcp 0.1.0 → 0.2.7

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2026 Better i18n
3
+ Copyright (c) 2026 Lefine
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -6,7 +6,7 @@ website pages, and make localized videos, with you approving anything that goes
6
6
  ## Sign in
7
7
 
8
8
  ```sh
9
- npx @lefine/cli login
9
+ npx lefine login
10
10
  ```
11
11
 
12
12
  Or set `LEFINE_TOKEN` to a key from Lefine, Settings > API keys. To let the agent reach Content,
@@ -19,7 +19,7 @@ Studio or your connected apps, make the key there and tick them under "Also reac
19
19
  ```json
20
20
  {
21
21
  "mcpServers": {
22
- "lefine": { "command": "npx", "args": ["-y", "@lefine/mcp"] }
22
+ "lefine": { "command": "npx", "args": ["-y", "lefine", "mcp"] }
23
23
  }
24
24
  }
25
25
  ```
@@ -47,7 +47,7 @@ Five tools, whatever your plan:
47
47
  | `lefine_write` | Run an action that writes drafts. Nothing goes live. |
48
48
  | `lefine_publish` | Run an action that goes live or spends credits. It asks you first. |
49
49
 
50
- Every action, with what it needs: [docs/mcp-actions.md](https://github.com/lefinehq/lefine/blob/main/docs/mcp-actions.md).
50
+ Every action, with what it needs: run `npx lefine actions` (add words to filter, e.g. `npx lefine actions content`).
51
51
 
52
52
  The tools live on Lefine's server, so a new action reaches you without updating this package.
53
53
 
@@ -58,3 +58,12 @@ The tools live on Lefine's server, so a new action reaches you without updating
58
58
  - `lefine-mcp --version`, `lefine-mcp --help`.
59
59
 
60
60
  Logs go to stderr; stdout carries only MCP messages.
61
+
62
+ ## Two tools for coding agents
63
+
64
+ `npx lefine mcp` (and this alias) add two tools next to the server's, answered on your machine:
65
+
66
+ - `lefine_find_similar_key`: keys whose name or source text is like the one you want, closest first. Agents call it first.
67
+ - `lefine_add_key`: adds one key with its source text, and refuses with the reason when the key exists in any namespace,
68
+ the same text already has a key, the namespace does not exist (`newNamespace: true` to make one), or the text is not
69
+ valid ICU. A new key is not live until someone publishes.
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env node
2
+ // @lefine/mcp is `lefine mcp` now. This name keeps working for configs that already say `npx -y @lefine/mcp`.
3
+ import { readFileSync } from "node:fs";
4
+ import { createRequire } from "node:module";
5
+ import { dirname, join } from "node:path";
6
+ import { pathToFileURL } from "node:url";
7
+
8
+ const manifest = createRequire(import.meta.url).resolve("lefine/package.json");
9
+ const { bin } = JSON.parse(readFileSync(manifest, "utf-8"));
10
+ process.argv.splice(2, 0, "mcp");
11
+ await import(pathToFileURL(join(dirname(manifest), bin.lefine)).href);
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@lefine/mcp",
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",
3
+ "version": "0.2.7",
4
+ "description": "Lefine as an MCP server for Claude Desktop, Cursor and other agents (same as `npx lefine mcp`)",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "bin": {
8
- "lefine-mcp": "./dist/lefine-mcp.js"
8
+ "lefine-mcp": "./bin/lefine-mcp.js"
9
9
  },
10
10
  "files": [
11
- "dist",
11
+ "bin",
12
12
  "README.md",
13
13
  "LICENSE"
14
14
  ],
@@ -17,7 +17,7 @@
17
17
  },
18
18
  "repository": {
19
19
  "type": "git",
20
- "url": "https://github.com/lefinehq/oss.git",
20
+ "url": "git+https://github.com/lefinehq/sdk.git",
21
21
  "directory": "packages/lefine-mcp"
22
22
  },
23
23
  "homepage": "https://lefine.ai",
@@ -30,16 +30,12 @@
30
30
  "claude"
31
31
  ],
32
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"
33
+ "check:package": "bunx publint@0.3.25 --strict"
41
34
  },
42
35
  "engines": {
43
36
  "node": ">=20"
37
+ },
38
+ "dependencies": {
39
+ "lefine": "^0.8.1"
44
40
  }
45
41
  }
@@ -1,63 +0,0 @@
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
- }
@@ -1,117 +0,0 @@
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
- }
@@ -1,46 +0,0 @@
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
- });