@verbaly/mcp 0.78.0 → 0.79.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/README.md +1 -0
- package/dist/cli.js +1 -1
- package/dist/index.js +1 -1
- package/dist/{server-D3wZuQbS.js → server-DJkry04G.js} +301 -240
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
<p align="center">
|
|
8
8
|
<a href="https://www.npmjs.com/package/@verbaly/mcp"><img src="https://img.shields.io/npm/v/@verbaly/mcp?logo=npm&color=cb3837" alt="npm version" /></a>
|
|
9
9
|
<a href="https://github.com/AronSoto/verbaly/blob/develop/LICENSE"><img src="https://img.shields.io/npm/l/@verbaly/mcp?color=blue" alt="MIT" /></a>
|
|
10
|
+
<a href="https://glama.ai/mcp/servers/AronSoto/verbaly"><img src="https://glama.ai/mcp/servers/AronSoto/verbaly/badges/score.svg" alt="verbaly MCP server on Glama" /></a>
|
|
10
11
|
</p>
|
|
11
12
|
|
|
12
13
|
---
|
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { t as createVerbalyMcp } from "./server-
|
|
2
|
+
import { t as createVerbalyMcp } from "./server-DJkry04G.js";
|
|
3
3
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
4
|
import { parseArgs } from "node:util";
|
|
5
5
|
// src/cli.ts
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as createVerbalyMcp } from "./server-
|
|
1
|
+
export { t as createVerbalyMcp } from "./server-DJkry04G.js";
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
2
|
import { McpServer, ResourceTemplate } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
3
|
import { check, collectOrigins, counted, doctor, effectiveDrafts, extractProject, formatCheckResult, formatCheckWarnings, formatDoctorEntry, formatDoctorHealth, formatFinding, formatStatusResult, formatTranslateFailures, init, loadCatalogs, loadConfig, loadState, mergeTranslations, readState, recordTranslations, resolveProvider, shippedCatalogs, status, syncProject, translateCatalogs, wrapProject, writeDrafts } from "@verbaly/compiler";
|
|
4
|
-
import { relative } from "node:path";
|
|
5
4
|
import { z } from "zod";
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
import { relative } from "node:path";
|
|
6
|
+
// src/tools/shared.ts
|
|
8
7
|
const reply = (body, data) => ({
|
|
9
8
|
content: [{
|
|
10
9
|
type: "text",
|
|
@@ -12,6 +11,18 @@ const reply = (body, data) => ({
|
|
|
12
11
|
}],
|
|
13
12
|
structuredContent: data
|
|
14
13
|
});
|
|
14
|
+
const READS = {
|
|
15
|
+
readOnlyHint: true,
|
|
16
|
+
openWorldHint: false
|
|
17
|
+
};
|
|
18
|
+
function writes(destructiveHint, openWorldHint = false) {
|
|
19
|
+
return {
|
|
20
|
+
readOnlyHint: false,
|
|
21
|
+
destructiveHint,
|
|
22
|
+
idempotentHint: true,
|
|
23
|
+
openWorldHint
|
|
24
|
+
};
|
|
25
|
+
}
|
|
15
26
|
const rootInput = z.string().optional().describe("Project root holding verbaly.config (defaults to the server working directory)");
|
|
16
27
|
const perLocale = z.array(z.object({
|
|
17
28
|
locale: z.string(),
|
|
@@ -73,113 +84,11 @@ function relativeCheck(root, result) {
|
|
|
73
84
|
}))
|
|
74
85
|
};
|
|
75
86
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
name: "verbaly",
|
|
79
|
-
version
|
|
80
|
-
});
|
|
81
|
-
const config = (root) => loadConfig(root ?? options.root ?? process.cwd());
|
|
82
|
-
const guarded = (run) => async (args) => {
|
|
83
|
-
try {
|
|
84
|
-
return await run(args);
|
|
85
|
-
} catch (error) {
|
|
86
|
-
return {
|
|
87
|
-
content: [{
|
|
88
|
-
type: "text",
|
|
89
|
-
text: error instanceof Error ? error.message : String(error)
|
|
90
|
-
}],
|
|
91
|
-
isError: true
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
server.registerResource("verbaly-config", "verbaly://config", {
|
|
96
|
-
title: "Project shape",
|
|
97
|
-
description: "The resolved Verbaly config: source locale, every locale, the catalog directory and where the language lives in the url. Read this before reasoning about anything else in the project.",
|
|
98
|
-
mimeType: "application/json"
|
|
99
|
-
}, async (uri) => {
|
|
100
|
-
const cfg = await config();
|
|
101
|
-
const shape = {
|
|
102
|
-
root: cfg.root,
|
|
103
|
-
sourceLocale: cfg.sourceLocale,
|
|
104
|
-
locales: cfg.locales,
|
|
105
|
-
localesDeclared: cfg.localesDeclared,
|
|
106
|
-
dir: cfg.dir,
|
|
107
|
-
routing: cfg.routing,
|
|
108
|
-
include: cfg.include
|
|
109
|
-
};
|
|
110
|
-
return { contents: [{
|
|
111
|
-
uri: uri.href,
|
|
112
|
-
mimeType: "application/json",
|
|
113
|
-
text: JSON.stringify(shape, null, 2)
|
|
114
|
-
}] };
|
|
115
|
-
});
|
|
116
|
-
server.registerResource("verbaly-catalog", new ResourceTemplate("verbaly://catalog/{locale}", { list: async () => {
|
|
117
|
-
return { resources: (await config()).locales.map((locale) => ({
|
|
118
|
-
name: `${locale} catalog`,
|
|
119
|
-
uri: `verbaly://catalog/${locale}`,
|
|
120
|
-
mimeType: "application/json"
|
|
121
|
-
})) };
|
|
122
|
-
} }), {
|
|
123
|
-
title: "Locale catalog",
|
|
124
|
-
description: "Every message of one locale, keyed the way the runtime sees them: a nested catalog arrives flattened, a text the code owns reads as the code has it, and an empty value means untranslated. This is the only way to read what a message actually says.",
|
|
125
|
-
mimeType: "application/json"
|
|
126
|
-
}, async (uri, { locale }) => {
|
|
127
|
-
const cfg = await config();
|
|
128
|
-
const name = String(locale);
|
|
129
|
-
if (!cfg.locales.includes(name)) {
|
|
130
|
-
const have = cfg.locales.join(", ");
|
|
131
|
-
throw new Error(`[verbaly] unknown locale "${name}": the project has ${have}`);
|
|
132
|
-
}
|
|
133
|
-
const registry = await extractProject(cfg);
|
|
134
|
-
const catalog = shippedCatalogs(cfg, loadCatalogs(cfg), registry, { newKeys: false })[name] ?? {};
|
|
135
|
-
return { contents: [{
|
|
136
|
-
uri: uri.href,
|
|
137
|
-
mimeType: "application/json",
|
|
138
|
-
text: JSON.stringify(catalog, null, 2)
|
|
139
|
-
}] };
|
|
140
|
-
});
|
|
141
|
-
server.registerTool("verbaly_init", {
|
|
142
|
-
title: "Set up Verbaly in a project",
|
|
143
|
-
description: "Create the config file and the locale catalogs, and detect the bundler or meta-framework so the answer names the package to add and the line to wire (what `verbaly init` does). Writes files, and a file already there is kept rather than overwritten. Run this when doctor says there is no config.",
|
|
144
|
-
inputSchema: {
|
|
145
|
-
root: rootInput,
|
|
146
|
-
dir: z.string().optional().describe("Directory for the catalogs (default: locales)"),
|
|
147
|
-
sourceLocale: z.string().optional().describe("The language you write in (default: en)"),
|
|
148
|
-
locales: z.array(z.string()).optional().describe("Every locale, source included")
|
|
149
|
-
},
|
|
150
|
-
outputSchema: {
|
|
151
|
-
created: z.array(z.string()).describe("Files written, relative to the project root"),
|
|
152
|
-
skipped: z.array(z.string()).describe("Files already there, left untouched"),
|
|
153
|
-
host: z.string().optional().describe("Bundler or meta-framework detected from the dependencies"),
|
|
154
|
-
configFile: z.string(),
|
|
155
|
-
next: z.array(z.string()).describe("What a human still has to do, in order"),
|
|
156
|
-
renamed: z.array(z.object({
|
|
157
|
-
from: z.string(),
|
|
158
|
-
to: z.string()
|
|
159
|
-
})).describe("Locales written with the hyphen a locale tag takes (pt_BR became pt-BR)"),
|
|
160
|
-
refused: z.array(z.string()).describe("Locales left out: not a locale tag, and no sure way to fix one"),
|
|
161
|
-
found: z.string().optional().describe("Catalogs the project already had, which the new config points at")
|
|
162
|
-
}
|
|
163
|
-
}, guarded(async ({ root, dir, sourceLocale, locales }) => {
|
|
164
|
-
const result = await init({
|
|
165
|
-
root: root ?? options.root,
|
|
166
|
-
dir,
|
|
167
|
-
sourceLocale,
|
|
168
|
-
locales
|
|
169
|
-
});
|
|
170
|
-
const lines = [];
|
|
171
|
-
if (result.created.length) lines.push(`created: ${result.created.join(", ")}`);
|
|
172
|
-
if (result.skipped.length) lines.push(`kept (already there): ${result.skipped.join(", ")}`);
|
|
173
|
-
for (const { from, to } of result.renamed) lines.push(`wrote ${to} for ${from}`);
|
|
174
|
-
for (const locale of result.refused) lines.push(`left out "${locale}": it is not a locale tag, use one like es or pt-BR`);
|
|
175
|
-
if (result.found) lines.push(`catalogs: ${result.found}, kept where they already are`);
|
|
176
|
-
if (result.host) lines.push(`detected: ${result.host}`);
|
|
177
|
-
lines.push(...result.next.map((step, i) => `${i + 1}. ${step}`));
|
|
178
|
-
return reply(lines.join("\n"), { ...result });
|
|
179
|
-
}));
|
|
87
|
+
// src/tools/doctor.ts
|
|
88
|
+
function registerDoctor(server, ctx) {
|
|
180
89
|
server.registerTool("verbaly_doctor", {
|
|
181
90
|
title: "Diagnose the setup",
|
|
182
|
-
description: "Diagnose a Verbaly project end to end (what `verbaly doctor` does)
|
|
91
|
+
description: "Diagnose a Verbaly project end to end (what `verbaly doctor` does). It checks the config file, the catalogs and their JSON, the bundler plugin for the detected framework, the generated types, files the parser could not read, a t imported from a package that never exports it, orphan keys, and every failure `verbaly check` would report, and it reports them all at once instead of stopping at the first. Run it first when something does not work. Read-only. For the missing or broken translations themselves, use verbaly_missing.",
|
|
183
92
|
inputSchema: { root: rootInput },
|
|
184
93
|
outputSchema: {
|
|
185
94
|
ok: z.boolean().describe("False when an entry is an error, which is when the CLI exits 1"),
|
|
@@ -194,74 +103,59 @@ function createVerbalyMcp(options = {}) {
|
|
|
194
103
|
fix: z.string().optional().describe("What to run or change, when there is one")
|
|
195
104
|
}))
|
|
196
105
|
},
|
|
197
|
-
annotations:
|
|
198
|
-
}, guarded(async ({ root }) => {
|
|
199
|
-
const cfg = await config(root);
|
|
106
|
+
annotations: READS
|
|
107
|
+
}, ctx.guarded(async ({ root }) => {
|
|
108
|
+
const cfg = await ctx.config(root);
|
|
200
109
|
const result = await doctor(cfg);
|
|
201
110
|
const head = `${counted(result.entries.length, "check")}, ${formatDoctorHealth(result)}`;
|
|
202
111
|
return reply([head, ...result.entries.map(formatDoctorEntry)].join("\n"), { ...result });
|
|
203
112
|
}));
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
113
|
+
}
|
|
114
|
+
// src/tools/drafts.ts
|
|
115
|
+
function registerDrafts(server, ctx) {
|
|
116
|
+
server.registerTool("verbaly_drafts", {
|
|
117
|
+
title: "Machine translations awaiting review",
|
|
118
|
+
description: "Every machine translation still waiting for a human, each with the source text and what the provider wrote, so a person can read both and decide. Read-only. Approving is deliberately not a tool here and never will be: a machine translation is unreviewed by definition, so accepting one is `verbaly review --approve`, run by a human. For how many drafts each locale has, verbaly_status is enough; verbaly_missing lists them next to the gate.",
|
|
207
119
|
inputSchema: {
|
|
208
120
|
root: rootInput,
|
|
209
|
-
|
|
121
|
+
locales: z.array(z.string()).optional().describe("Target locales (default: all)")
|
|
210
122
|
},
|
|
211
123
|
outputSchema: {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
text: z.string(),
|
|
219
|
-
kind: z.enum(["text", "attribute"]),
|
|
220
|
-
attribute: z.string().optional()
|
|
221
|
-
})),
|
|
222
|
-
skipped: z.array(z.object({
|
|
223
|
-
file: z.string(),
|
|
224
|
-
line: z.number(),
|
|
225
|
-
text: z.string(),
|
|
226
|
-
reason: z.string()
|
|
227
|
-
})),
|
|
228
|
-
blocked: z.array(z.object({
|
|
229
|
-
file: z.string(),
|
|
230
|
-
texts: z.number(),
|
|
231
|
-
client: z.boolean()
|
|
124
|
+
total: z.number(),
|
|
125
|
+
entries: z.array(z.object({
|
|
126
|
+
locale: z.string(),
|
|
127
|
+
key: z.string(),
|
|
128
|
+
source: z.string().describe("What the message says in the source locale"),
|
|
129
|
+
translated: z.string().describe("What the provider wrote, still unreviewed")
|
|
232
130
|
}))
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
const
|
|
237
|
-
const
|
|
238
|
-
const
|
|
239
|
-
const
|
|
240
|
-
const
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
lines.push(` ${entry.file} ${counted(entry.texts, "text")}, ${how}`);
|
|
254
|
-
}
|
|
255
|
-
lines.push(" next: bind t there, run verbaly_wrap with write again, then verbaly_extract");
|
|
256
|
-
} else if (write && done.length > 0) lines.push(" next: run verbaly_extract");
|
|
257
|
-
return reply(lines.join("\n"), {
|
|
258
|
-
...result,
|
|
259
|
-
write: write === true
|
|
131
|
+
},
|
|
132
|
+
annotations: READS
|
|
133
|
+
}, ctx.guarded(async ({ root, locales }) => {
|
|
134
|
+
const cfg = await ctx.config(root);
|
|
135
|
+
const catalogs = loadCatalogs(cfg);
|
|
136
|
+
const source = shippedCatalogs(cfg, catalogs, await extractProject(cfg))[cfg.sourceLocale] ?? {};
|
|
137
|
+
const pending = effectiveDrafts(loadState(cfg).drafts, catalogs);
|
|
138
|
+
const wanted = locales ?? cfg.locales;
|
|
139
|
+
const entries = Object.entries(pending).filter(([locale]) => wanted.includes(locale)).flatMap(([locale, keys]) => keys.map((key) => ({
|
|
140
|
+
locale,
|
|
141
|
+
key,
|
|
142
|
+
source: source[key] ?? "",
|
|
143
|
+
translated: catalogs[locale]?.[key] ?? ""
|
|
144
|
+
})));
|
|
145
|
+
const body = entries.length ? entries.map((e) => `[${e.locale}] ${e.key}
|
|
146
|
+
source: ${e.source}
|
|
147
|
+
draft: ${e.translated}`).join("\n") : "nothing awaiting review";
|
|
148
|
+
return reply(body, {
|
|
149
|
+
total: entries.length,
|
|
150
|
+
entries
|
|
260
151
|
});
|
|
261
152
|
}));
|
|
153
|
+
}
|
|
154
|
+
// src/tools/extract.ts
|
|
155
|
+
function registerExtract(server, ctx) {
|
|
262
156
|
server.registerTool("verbaly_extract", {
|
|
263
157
|
title: "Extract messages",
|
|
264
|
-
description: "Scan the source files, add new messages to the locale catalogs and refresh the generated types (what `verbaly extract` does).
|
|
158
|
+
description: "Scan the source files, add new messages to the locale catalogs and refresh the generated types (what `verbaly extract` does). It writes the catalogs unless dryRun is set, and with the same code a second run changes nothing. prune also drops keys the code no longer references, translations included, and waits while any source file fails to parse. In a project without Verbaly, run verbaly_init first; for text still hardcoded in JSX, verbaly_wrap.",
|
|
265
159
|
inputSchema: {
|
|
266
160
|
root: rootInput,
|
|
267
161
|
prune: z.boolean().optional().describe("Drop keys no longer referenced (deletes their translations)"),
|
|
@@ -306,9 +200,10 @@ function createVerbalyMcp(options = {}) {
|
|
|
306
200
|
from: z.string().optional(),
|
|
307
201
|
merged: z.boolean().optional()
|
|
308
202
|
}).optional().describe("This run created verbaly.lock, moved an older state file (from) into it, or rewrote it whole after a merge conflict (merged): it belongs in git with the catalogs, so tell the user to commit it")
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
|
|
203
|
+
},
|
|
204
|
+
annotations: writes(true)
|
|
205
|
+
}, ctx.guarded(async ({ root, prune, dryRun }) => {
|
|
206
|
+
const cfg = await ctx.config(root);
|
|
312
207
|
const result = await syncProject(cfg, {
|
|
313
208
|
prune,
|
|
314
209
|
dryRun
|
|
@@ -367,38 +262,55 @@ function createVerbalyMcp(options = {}) {
|
|
|
367
262
|
if (result.stateProblem) lines.push(`${result.stateProblem}, so drafts and outdated translations were not updated`);
|
|
368
263
|
return reply(lines.join("\n"), data);
|
|
369
264
|
}));
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
265
|
+
}
|
|
266
|
+
// src/tools/init.ts
|
|
267
|
+
function registerInit(server, ctx) {
|
|
268
|
+
server.registerTool("verbaly_init", {
|
|
269
|
+
title: "Set up Verbaly in a project",
|
|
270
|
+
description: "Create the config file and the locale catalogs, and detect the bundler or meta-framework so the answer names the package to add and the line to wire (what `verbaly init` does). A file already there is kept, never overwritten, so running it again is safe. Use it when verbaly_doctor finds no config; once the project is set up, verbaly_doctor is the one to run.",
|
|
271
|
+
inputSchema: {
|
|
272
|
+
root: rootInput,
|
|
273
|
+
dir: z.string().optional().describe("Directory for the catalogs (default: locales)"),
|
|
274
|
+
sourceLocale: z.string().optional().describe("The language you write in (default: en)"),
|
|
275
|
+
locales: z.array(z.string()).optional().describe("Every locale, source included")
|
|
276
|
+
},
|
|
374
277
|
outputSchema: {
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
278
|
+
created: z.array(z.string()).describe("Files written, relative to the project root"),
|
|
279
|
+
skipped: z.array(z.string()).describe("Files already there, left untouched"),
|
|
280
|
+
host: z.string().optional().describe("Bundler or meta-framework detected from the dependencies"),
|
|
281
|
+
configFile: z.string(),
|
|
282
|
+
next: z.array(z.string()).describe("What a human still has to do, in order"),
|
|
283
|
+
renamed: z.array(z.object({
|
|
284
|
+
from: z.string(),
|
|
285
|
+
to: z.string()
|
|
286
|
+
})).describe("Locales written with the hyphen a locale tag takes (pt_BR became pt-BR)"),
|
|
287
|
+
refused: z.array(z.string()).describe("Locales left out: not a locale tag, and no sure way to fix one"),
|
|
288
|
+
found: z.string().optional().describe("Catalogs the project already had, which the new config points at")
|
|
386
289
|
},
|
|
387
|
-
annotations:
|
|
388
|
-
}, guarded(async ({ root }) => {
|
|
389
|
-
const
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
return reply(problem ? `${body}\n${problem}, so drafts and outdated are not counted` : body, {
|
|
395
|
-
...result,
|
|
396
|
-
...problem && { stateProblem: problem }
|
|
290
|
+
annotations: writes(false)
|
|
291
|
+
}, ctx.guarded(async ({ root, dir, sourceLocale, locales }) => {
|
|
292
|
+
const result = await init({
|
|
293
|
+
root: root ?? ctx.root,
|
|
294
|
+
dir,
|
|
295
|
+
sourceLocale,
|
|
296
|
+
locales
|
|
397
297
|
});
|
|
298
|
+
const lines = [];
|
|
299
|
+
if (result.created.length) lines.push(`created: ${result.created.join(", ")}`);
|
|
300
|
+
if (result.skipped.length) lines.push(`kept (already there): ${result.skipped.join(", ")}`);
|
|
301
|
+
for (const { from, to } of result.renamed) lines.push(`wrote ${to} for ${from}`);
|
|
302
|
+
for (const locale of result.refused) lines.push(`left out "${locale}": it is not a locale tag, use one like es or pt-BR`);
|
|
303
|
+
if (result.found) lines.push(`catalogs: ${result.found}, kept where they already are`);
|
|
304
|
+
if (result.host) lines.push(`detected: ${result.host}`);
|
|
305
|
+
lines.push(...result.next.map((step, i) => `${i + 1}. ${step}`));
|
|
306
|
+
return reply(lines.join("\n"), { ...result });
|
|
398
307
|
}));
|
|
308
|
+
}
|
|
309
|
+
// src/tools/missing.ts
|
|
310
|
+
function registerMissing(server, ctx) {
|
|
399
311
|
server.registerTool("verbaly_missing", {
|
|
400
312
|
title: "Missing and broken translations",
|
|
401
|
-
description: "
|
|
313
|
+
description: "The gate `verbaly check` runs in CI, as lists: missing translations, unknown keys, keys written with two texts (collisions: every place shows the first text) and translations that cannot render what the source renders. A dropped {param}, a lost rich tag or a flattened plural block is that last kind. Warnings never fail the gate and are listed too: an incomplete plural set for the locale, keys only a translation has (extra), texts the code and the source catalog disagree on (divergent: the text in the code ships) and translations written for an older source text (outdated). With drafts set, it also lists the machine translations awaiting review. Read-only. For counts use verbaly_status, to review drafts with their source text verbaly_drafts, and for setup problems verbaly_doctor.",
|
|
402
314
|
inputSchema: {
|
|
403
315
|
root: rootInput,
|
|
404
316
|
drafts: z.boolean().optional().describe("Also list machine translations awaiting human review")
|
|
@@ -438,9 +350,9 @@ function createVerbalyMcp(options = {}) {
|
|
|
438
350
|
unreviewed: perLocale,
|
|
439
351
|
stateProblem: z.string().optional().describe("The state file could not be read, so outdated translations are not listed")
|
|
440
352
|
},
|
|
441
|
-
annotations:
|
|
442
|
-
}, guarded(async ({ root, drafts }) => {
|
|
443
|
-
const cfg = await config(root);
|
|
353
|
+
annotations: READS
|
|
354
|
+
}, ctx.guarded(async ({ root, drafts }) => {
|
|
355
|
+
const cfg = await ctx.config(root);
|
|
444
356
|
const registry = await extractProject(cfg);
|
|
445
357
|
const catalogs = loadCatalogs(cfg);
|
|
446
358
|
const { state, problem } = drafts ? {
|
|
@@ -461,9 +373,44 @@ function createVerbalyMcp(options = {}) {
|
|
|
461
373
|
...problem && { stateProblem: problem }
|
|
462
374
|
});
|
|
463
375
|
}));
|
|
376
|
+
}
|
|
377
|
+
// src/tools/status.ts
|
|
378
|
+
function registerStatus(server, ctx) {
|
|
379
|
+
server.registerTool("verbaly_status", {
|
|
380
|
+
title: "Translation coverage",
|
|
381
|
+
description: "Translation coverage of the Verbaly project as numbers per locale: total messages, translated, machine translations awaiting review (drafts), broken, and translations written for an older source text (outdated). It scans the source like verbaly_extract but writes nothing. Read-only. For the entries behind the numbers, use verbaly_missing (what is missing or broken) or verbaly_drafts (each draft with its source text).",
|
|
382
|
+
inputSchema: { root: rootInput },
|
|
383
|
+
outputSchema: {
|
|
384
|
+
messages: z.number().describe("Messages the project has, source catalog plus code"),
|
|
385
|
+
source: z.string().describe("Source locale"),
|
|
386
|
+
locales: z.array(z.object({
|
|
387
|
+
locale: z.string(),
|
|
388
|
+
translated: z.number(),
|
|
389
|
+
total: z.number(),
|
|
390
|
+
drafts: z.number().describe("Machine translations awaiting human review"),
|
|
391
|
+
broken: z.number().describe("Present but not rendering what the source renders"),
|
|
392
|
+
outdated: z.number().describe("Translated from an older source text: update them, or a human keeps them")
|
|
393
|
+
})),
|
|
394
|
+
stateProblem: z.string().optional().describe("The state file could not be read, so drafts and outdated are counted as zero")
|
|
395
|
+
},
|
|
396
|
+
annotations: READS
|
|
397
|
+
}, ctx.guarded(async ({ root }) => {
|
|
398
|
+
const cfg = await ctx.config(root);
|
|
399
|
+
const registry = await extractProject(cfg);
|
|
400
|
+
const { state, problem } = readState(cfg);
|
|
401
|
+
const result = status(cfg, loadCatalogs(cfg), registry, state.drafts, state.fingerprints);
|
|
402
|
+
const body = formatStatusResult(result);
|
|
403
|
+
return reply(problem ? `${body}\n${problem}, so drafts and outdated are not counted` : body, {
|
|
404
|
+
...result,
|
|
405
|
+
...problem && { stateProblem: problem }
|
|
406
|
+
});
|
|
407
|
+
}));
|
|
408
|
+
}
|
|
409
|
+
// src/tools/translate.ts
|
|
410
|
+
function registerTranslate(server, ctx) {
|
|
464
411
|
server.registerTool("verbaly_translate", {
|
|
465
412
|
title: "Machine-translate missing entries",
|
|
466
|
-
description: "Fill missing translations with the configured provider (default
|
|
413
|
+
description: "Fill missing translations with the configured provider (what `verbaly translate` does). The default provider is Claude, which needs @anthropic-ai/sdk and ANTHROPIC_API_KEY. Every new translation is saved as a draft awaiting human review (`verbaly review`), which no tool here can approve. A batch the provider never answers is reported in failed and everything else stays written, so a retry only asks for what is left. dryRun lists what would be translated without calling the provider. To see what is missing first, use verbaly_missing; to save translations you wrote yourself, verbaly_write_drafts.",
|
|
467
414
|
inputSchema: {
|
|
468
415
|
root: rootInput,
|
|
469
416
|
locales: z.array(z.string()).optional().describe("Target locales (default: all)"),
|
|
@@ -480,9 +427,10 @@ function createVerbalyMcp(options = {}) {
|
|
|
480
427
|
error: z.string()
|
|
481
428
|
})).describe("Batches the provider never answered, safe to retry"),
|
|
482
429
|
pending: perLocale.describe("dryRun only: what would be translated")
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
|
|
430
|
+
},
|
|
431
|
+
annotations: writes(false, true)
|
|
432
|
+
}, ctx.guarded(async ({ root, locales, dryRun }) => {
|
|
433
|
+
const cfg = await ctx.config(root);
|
|
486
434
|
if (!dryRun) loadState(cfg);
|
|
487
435
|
const registry = await extractProject(cfg);
|
|
488
436
|
const catalogs = shippedCatalogs(cfg, loadCatalogs(cfg), registry, { newKeys: false });
|
|
@@ -544,9 +492,74 @@ function createVerbalyMcp(options = {}) {
|
|
|
544
492
|
if (data.translated.length > 0) lines.push("drafts await human review: verbaly review (--approve accepts them)");
|
|
545
493
|
return reply(lines.join("\n"), data);
|
|
546
494
|
}));
|
|
495
|
+
}
|
|
496
|
+
// src/tools/wrap.ts
|
|
497
|
+
function registerWrap(server, ctx) {
|
|
498
|
+
server.registerTool("verbaly_wrap", {
|
|
499
|
+
title: "Wrap hardcoded JSX text",
|
|
500
|
+
description: "Find hardcoded user-visible text in JSX/TSX files and wrap it in a t tagged template so the compiler can extract it (what `verbaly wrap` does). This is how an existing codebase is onboarded, and verbaly_extract then adds the wrapped texts to the catalogs. It only reports unless write is set, and text already wrapped is skipped, so running it again is safe. Text it cannot wrap safely (a sentence split across markup, an expression rendering JSX) is listed as needing a human. A file that does not bind t is never written, because the rewrite would not compile. It comes back in blocked, with whether it is a client component, so you can add the binding and run again.",
|
|
501
|
+
inputSchema: {
|
|
502
|
+
root: rootInput,
|
|
503
|
+
write: z.boolean().optional().describe("Apply the rewrites instead of only reporting")
|
|
504
|
+
},
|
|
505
|
+
outputSchema: {
|
|
506
|
+
files: z.number().describe("JSX/TSX files scanned"),
|
|
507
|
+
write: z.boolean(),
|
|
508
|
+
changed: z.array(z.string()).describe("Files the rewrite touched, or would touch"),
|
|
509
|
+
wrapped: z.array(z.object({
|
|
510
|
+
file: z.string(),
|
|
511
|
+
line: z.number(),
|
|
512
|
+
text: z.string(),
|
|
513
|
+
kind: z.enum(["text", "attribute"]),
|
|
514
|
+
attribute: z.string().optional()
|
|
515
|
+
})),
|
|
516
|
+
skipped: z.array(z.object({
|
|
517
|
+
file: z.string(),
|
|
518
|
+
line: z.number(),
|
|
519
|
+
text: z.string(),
|
|
520
|
+
reason: z.string()
|
|
521
|
+
})),
|
|
522
|
+
blocked: z.array(z.object({
|
|
523
|
+
file: z.string(),
|
|
524
|
+
texts: z.number(),
|
|
525
|
+
client: z.boolean()
|
|
526
|
+
}))
|
|
527
|
+
},
|
|
528
|
+
annotations: writes(true)
|
|
529
|
+
}, ctx.guarded(async ({ root, write }) => {
|
|
530
|
+
const cfg = await ctx.config(root);
|
|
531
|
+
const result = await wrapProject(cfg, { write });
|
|
532
|
+
const blocked = new Set(result.blocked.map((entry) => entry.file));
|
|
533
|
+
const done = result.changed.filter((file) => !blocked.has(file));
|
|
534
|
+
const texts = result.wrapped.filter((entry) => !blocked.has(entry.file));
|
|
535
|
+
const lines = [`${write ? "wrapped" : "would wrap"} ${write ? `${counted(texts.length, "text")} in ${counted(done.length, "file")}` : `${counted(result.wrapped.length, "text")} in ${counted(result.changed.length, "file")}`} of ${counted(result.files, "file")} scanned`];
|
|
536
|
+
for (const entry of write ? texts : result.wrapped) {
|
|
537
|
+
const attr = entry.kind === "attribute" ? `${entry.attribute} -> ` : "";
|
|
538
|
+
lines.push(` ${entry.file}:${entry.line} ${attr}"${entry.text}"`);
|
|
539
|
+
}
|
|
540
|
+
if (result.skipped.length > 0) {
|
|
541
|
+
lines.push(" needs a human:");
|
|
542
|
+
for (const entry of result.skipped) lines.push(` ${entry.file}:${entry.line} "${entry.text}" (${entry.reason})`);
|
|
543
|
+
}
|
|
544
|
+
if (result.blocked.length > 0) {
|
|
545
|
+
lines.push(` nothing written in ${counted(result.blocked.length, "file")} with no t in scope:`);
|
|
546
|
+
for (const entry of result.blocked) {
|
|
547
|
+
const how = entry.client ? "\"use client\", so const t = useT()" : "no \"use client\"";
|
|
548
|
+
lines.push(` ${entry.file} ${counted(entry.texts, "text")}, ${how}`);
|
|
549
|
+
}
|
|
550
|
+
lines.push(" next: bind t there, run verbaly_wrap with write again, then verbaly_extract");
|
|
551
|
+
} else if (write && done.length > 0) lines.push(" next: run verbaly_extract");
|
|
552
|
+
return reply(lines.join("\n"), {
|
|
553
|
+
...result,
|
|
554
|
+
write: write === true
|
|
555
|
+
});
|
|
556
|
+
}));
|
|
557
|
+
}
|
|
558
|
+
// src/tools/write-drafts.ts
|
|
559
|
+
function registerWriteDrafts(server, ctx) {
|
|
547
560
|
server.registerTool("verbaly_write_drafts", {
|
|
548
561
|
title: "Save translations an agent wrote",
|
|
549
|
-
description: "Save translations you wrote yourself, so neither a catalog nor the state file is ever edited by hand. Each one is checked the way
|
|
562
|
+
description: "Save translations you wrote yourself, so neither a catalog nor the state file is ever edited by hand. Each one is checked the way verbaly_translate checks a provider (params, rich tags and plural cases must survive), written only for keys the source catalog has, and marked as a draft awaiting human review. Existing translations are kept unless overwrite is set, which is how an outdated one gets rewritten. Approving is not a tool here: a human reads the drafts (verbaly_drafts lists them) and runs `verbaly review --approve`.",
|
|
550
563
|
inputSchema: {
|
|
551
564
|
root: rootInput,
|
|
552
565
|
locale: z.string().describe("Target locale, one of the project's non-source locales"),
|
|
@@ -561,9 +574,10 @@ function createVerbalyMcp(options = {}) {
|
|
|
561
574
|
kept: z.array(z.string()).describe("Already translated, left as they were (overwrite replaces them)"),
|
|
562
575
|
invalid: z.array(z.string()).describe("Rejected: empty, or the params, tags or plural cases were not preserved"),
|
|
563
576
|
unknown: z.array(z.string()).describe("Not in the source catalog, so nothing was written")
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
|
|
577
|
+
},
|
|
578
|
+
annotations: writes(true)
|
|
579
|
+
}, ctx.guarded(async ({ root, locale, entries, overwrite }) => {
|
|
580
|
+
const cfg = await ctx.config(root);
|
|
567
581
|
const registry = await extractProject(cfg);
|
|
568
582
|
const result = writeDrafts(cfg, locale, entries, {
|
|
569
583
|
overwrite,
|
|
@@ -576,43 +590,90 @@ function createVerbalyMcp(options = {}) {
|
|
|
576
590
|
if (result.unknown.length > 0) lines.push(`${locale}: ${counted(result.unknown.length, "unknown key")} not in the source catalog: ${result.unknown.join(", ")}`);
|
|
577
591
|
return reply(lines.length > 0 ? lines.join("\n") : "nothing to save", { ...result });
|
|
578
592
|
}));
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
593
|
+
}
|
|
594
|
+
// src/server.ts
|
|
595
|
+
const { version } = createRequire(import.meta.url)("../package.json");
|
|
596
|
+
function createVerbalyMcp(options = {}) {
|
|
597
|
+
const server = new McpServer({
|
|
598
|
+
name: "verbaly",
|
|
599
|
+
version
|
|
600
|
+
});
|
|
601
|
+
const config = (root) => loadConfig(root ?? options.root ?? process.cwd());
|
|
602
|
+
const guarded = (run) => async (args) => {
|
|
603
|
+
try {
|
|
604
|
+
return await run(args);
|
|
605
|
+
} catch (error) {
|
|
606
|
+
return {
|
|
607
|
+
content: [{
|
|
608
|
+
type: "text",
|
|
609
|
+
text: error instanceof Error ? error.message : String(error)
|
|
610
|
+
}],
|
|
611
|
+
isError: true
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
};
|
|
615
|
+
server.registerResource("verbaly-config", "verbaly://config", {
|
|
616
|
+
title: "Project shape",
|
|
617
|
+
description: "The resolved Verbaly config: source locale, every locale, the catalog directory and where the language lives in the url. Read this before reasoning about anything else in the project.",
|
|
618
|
+
mimeType: "application/json"
|
|
619
|
+
}, async (uri) => {
|
|
620
|
+
const cfg = await config();
|
|
621
|
+
const shape = {
|
|
622
|
+
root: cfg.root,
|
|
623
|
+
sourceLocale: cfg.sourceLocale,
|
|
624
|
+
locales: cfg.locales,
|
|
625
|
+
localesDeclared: cfg.localesDeclared,
|
|
626
|
+
dir: cfg.dir,
|
|
627
|
+
routing: cfg.routing,
|
|
628
|
+
include: cfg.include
|
|
629
|
+
};
|
|
630
|
+
return { contents: [{
|
|
631
|
+
uri: uri.href,
|
|
632
|
+
mimeType: "application/json",
|
|
633
|
+
text: JSON.stringify(shape, null, 2)
|
|
634
|
+
}] };
|
|
635
|
+
});
|
|
636
|
+
server.registerResource("verbaly-catalog", new ResourceTemplate("verbaly://catalog/{locale}", { list: async () => {
|
|
637
|
+
return { resources: (await config()).locales.map((locale) => ({
|
|
638
|
+
name: `${locale} catalog`,
|
|
639
|
+
uri: `verbaly://catalog/${locale}`,
|
|
640
|
+
mimeType: "application/json"
|
|
641
|
+
})) };
|
|
642
|
+
} }), {
|
|
643
|
+
title: "Locale catalog",
|
|
644
|
+
description: "Every message of one locale, keyed the way the runtime sees them: a nested catalog arrives flattened, a text the code owns reads as the code has it, and an empty value means untranslated. This is the only way to read what a message actually says.",
|
|
645
|
+
mimeType: "application/json"
|
|
646
|
+
}, async (uri, { locale }) => {
|
|
647
|
+
const cfg = await config();
|
|
648
|
+
const name = String(locale);
|
|
649
|
+
if (!cfg.locales.includes(name)) {
|
|
650
|
+
const have = cfg.locales.join(", ");
|
|
651
|
+
throw new Error(`[verbaly] unknown locale "${name}": the project has ${have}`);
|
|
652
|
+
}
|
|
653
|
+
const registry = await extractProject(cfg);
|
|
654
|
+
const catalog = shippedCatalogs(cfg, loadCatalogs(cfg), registry, { newKeys: false })[name] ?? {};
|
|
655
|
+
return { contents: [{
|
|
656
|
+
uri: uri.href,
|
|
657
|
+
mimeType: "application/json",
|
|
658
|
+
text: JSON.stringify(catalog, null, 2)
|
|
659
|
+
}] };
|
|
660
|
+
});
|
|
661
|
+
const ctx = {
|
|
662
|
+
root: options.root,
|
|
663
|
+
config,
|
|
664
|
+
guarded
|
|
665
|
+
};
|
|
666
|
+
for (const register of [
|
|
667
|
+
registerInit,
|
|
668
|
+
registerDoctor,
|
|
669
|
+
registerWrap,
|
|
670
|
+
registerExtract,
|
|
671
|
+
registerStatus,
|
|
672
|
+
registerMissing,
|
|
673
|
+
registerTranslate,
|
|
674
|
+
registerWriteDrafts,
|
|
675
|
+
registerDrafts
|
|
676
|
+
]) register(server, ctx);
|
|
616
677
|
return server;
|
|
617
678
|
}
|
|
618
679
|
export { createVerbalyMcp as t };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@verbaly/mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.79.0",
|
|
4
4
|
"description": "MCP server for Verbaly: diagnosis, onboarding, extraction, coverage and machine translation as tools for coding agents.",
|
|
5
5
|
"mcpName": "io.github.AronSoto/verbaly",
|
|
6
6
|
"keywords": [
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"@modelcontextprotocol/sdk": "^1.32.2",
|
|
52
|
-
"@verbaly/compiler": "^0.
|
|
52
|
+
"@verbaly/compiler": "^0.79.0",
|
|
53
53
|
"zod": "^4.6.7"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|