@verbaly/mcp 0.78.0 → 0.80.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 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-D3wZuQbS.js";
2
+ import { t as createVerbalyMcp } from "./server-DLz42N1C.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-D3wZuQbS.js";
1
+ export { t as createVerbalyMcp } from "./server-DLz42N1C.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
- // src/server.ts
7
- const { version } = createRequire(import.meta.url)("../package.json");
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
- function createVerbalyMcp(options = {}) {
77
- const server = new McpServer({
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): the config file, the catalog files and their JSON, the bundler plugin for the detected framework, the generated types, files the parser could not read, t imported from a package that never exports it, orphan keys, and every failure `verbaly check` would report. Run this first when something does not work. Read-only.",
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: { readOnlyHint: true }
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
- server.registerTool("verbaly_wrap", {
205
- title: "Wrap hardcoded JSX text",
206
- 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. Reports only unless write is set. Text it cannot wrap safely (a sentence split across markup, an expression rendering JSX) is listed as needing a human and never rewritten. A file that does not bind t is never written either, because the rewrite would not compile: those come back in blocked, with whether the file is a client component, so you can add the binding and run again.",
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
- write: z.boolean().optional().describe("Apply the rewrites instead of only reporting")
121
+ locales: z.array(z.string()).optional().describe("Target locales (default: all)")
210
122
  },
211
123
  outputSchema: {
212
- files: z.number().describe("JSX/TSX files scanned"),
213
- write: z.boolean(),
214
- changed: z.array(z.string()).describe("Files the rewrite touched, or would touch"),
215
- wrapped: z.array(z.object({
216
- file: z.string(),
217
- line: z.number(),
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
- }, guarded(async ({ root, write }) => {
235
- const cfg = await config(root);
236
- const result = await wrapProject(cfg, { write });
237
- const blocked = new Set(result.blocked.map((entry) => entry.file));
238
- const done = result.changed.filter((file) => !blocked.has(file));
239
- const texts = result.wrapped.filter((entry) => !blocked.has(entry.file));
240
- 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`];
241
- for (const entry of write ? texts : result.wrapped) {
242
- const attr = entry.kind === "attribute" ? `${entry.attribute} -> ` : "";
243
- lines.push(` ${entry.file}:${entry.line} ${attr}"${entry.text}"`);
244
- }
245
- if (result.skipped.length > 0) {
246
- lines.push(" needs a human:");
247
- for (const entry of result.skipped) lines.push(` ${entry.file}:${entry.line} "${entry.text}" (${entry.reason})`);
248
- }
249
- if (result.blocked.length > 0) {
250
- lines.push(` nothing written in ${counted(result.blocked.length, "file")} with no t in scope:`);
251
- for (const entry of result.blocked) {
252
- const how = entry.client ? "\"use client\", so const t = useT()" : "no \"use client\"";
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). Writes catalog files unless dryRun is set. prune drops keys no longer referenced in the code, translations included.",
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
- }, guarded(async ({ root, prune, dryRun }) => {
311
- const cfg = await config(root);
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
- server.registerTool("verbaly_status", {
371
- title: "Translation coverage",
372
- description: "Translation coverage of the Verbaly project: total messages, translated count per locale, machine translations awaiting review (drafts) and translations written for an older source text (outdated). Read-only.",
373
- inputSchema: { root: rootInput },
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
- messages: z.number().describe("Messages the project has, source catalog plus code"),
376
- source: z.string().describe("Source locale"),
377
- locales: z.array(z.object({
378
- locale: z.string(),
379
- translated: z.number(),
380
- total: z.number(),
381
- drafts: z.number().describe("Machine translations awaiting human review"),
382
- broken: z.number().describe("Present but not rendering what the source renders"),
383
- outdated: z.number().describe("Translated from an older source text: update them, or a human keeps them")
384
- })),
385
- stateProblem: z.string().optional().describe("The state file could not be read, so drafts and outdated are counted as zero")
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: { readOnlyHint: true }
388
- }, guarded(async ({ root }) => {
389
- const cfg = await config(root);
390
- const registry = await extractProject(cfg);
391
- const { state, problem } = readState(cfg);
392
- const result = status(cfg, loadCatalogs(cfg), registry, state.drafts, state.fingerprints);
393
- const body = formatStatusResult(result);
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: "List missing translations, unknown keys, keys written with two texts (collisions: every place shows the first text) and translations that exist but cannot render what the source renders (a dropped {param}, a lost rich tag, a flattened plural block), the same gate `verbaly check` runs in CI. Warnings never fail the gate and are listed too: an incomplete plural set for the locale, keys a translation carries that the source catalog does not (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). Optionally also lists machine translations awaiting review. Read-only.",
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: { readOnlyHint: true }
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: Claude, needs @anthropic-ai/sdk and ANTHROPIC_API_KEY). New translations are saved as drafts awaiting human review (`verbaly review`), which no tool here can approve. A batch the provider never answers is reported in failed and leaves everything else written, so a retry only asks for what is left. dryRun lists what would be translated without calling the provider.",
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
- }, guarded(async ({ root, locales, dryRun }) => {
485
- const cfg = await config(root);
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 });
@@ -508,8 +456,8 @@ function createVerbalyMcp(options = {}) {
508
456
  };
509
457
  return reply(lines.length === 0 ? "nothing to translate" : lines.join("\n"), data);
510
458
  }
511
- const written = {};
512
- const kept = {};
459
+ const written = [];
460
+ const kept = [];
513
461
  const writes = [];
514
462
  for (const [locale, keys] of Object.entries(result.translated)) {
515
463
  const catalog = catalogs[locale] ?? {};
@@ -522,15 +470,21 @@ function createVerbalyMcp(options = {}) {
522
470
  text: catalog[key]
523
471
  }))
524
472
  });
525
- if (landed.length > 0) written[locale] = landed;
473
+ if (landed.length > 0) written.push({
474
+ locale,
475
+ keys: landed
476
+ });
526
477
  const left = keys.filter((key) => !landed.includes(key));
527
- if (left.length > 0) kept[locale] = left;
478
+ if (left.length > 0) kept.push({
479
+ locale,
480
+ keys: left
481
+ });
528
482
  }
529
483
  if (writes.length > 0) recordTranslations(cfg, catalogs[cfg.sourceLocale] ?? {}, writes);
530
484
  const data = {
531
485
  dryRun: false,
532
- translated: byLocale(written),
533
- kept: byLocale(kept),
486
+ translated: written,
487
+ kept,
534
488
  invalid: byLocale(result.invalid),
535
489
  failed: result.failed,
536
490
  pending: []
@@ -544,9 +498,74 @@ function createVerbalyMcp(options = {}) {
544
498
  if (data.translated.length > 0) lines.push("drafts await human review: verbaly review (--approve accepts them)");
545
499
  return reply(lines.join("\n"), data);
546
500
  }));
501
+ }
502
+ // src/tools/wrap.ts
503
+ function registerWrap(server, ctx) {
504
+ server.registerTool("verbaly_wrap", {
505
+ title: "Wrap hardcoded JSX text",
506
+ 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.",
507
+ inputSchema: {
508
+ root: rootInput,
509
+ write: z.boolean().optional().describe("Apply the rewrites instead of only reporting")
510
+ },
511
+ outputSchema: {
512
+ files: z.number().describe("JSX/TSX files scanned"),
513
+ write: z.boolean(),
514
+ changed: z.array(z.string()).describe("Files the rewrite touched, or would touch"),
515
+ wrapped: z.array(z.object({
516
+ file: z.string(),
517
+ line: z.number(),
518
+ text: z.string(),
519
+ kind: z.enum(["text", "attribute"]),
520
+ attribute: z.string().optional()
521
+ })),
522
+ skipped: z.array(z.object({
523
+ file: z.string(),
524
+ line: z.number(),
525
+ text: z.string(),
526
+ reason: z.string()
527
+ })),
528
+ blocked: z.array(z.object({
529
+ file: z.string(),
530
+ texts: z.number(),
531
+ client: z.boolean()
532
+ }))
533
+ },
534
+ annotations: writes(true)
535
+ }, ctx.guarded(async ({ root, write }) => {
536
+ const cfg = await ctx.config(root);
537
+ const result = await wrapProject(cfg, { write });
538
+ const blocked = new Set(result.blocked.map((entry) => entry.file));
539
+ const done = result.changed.filter((file) => !blocked.has(file));
540
+ const texts = result.wrapped.filter((entry) => !blocked.has(entry.file));
541
+ 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`];
542
+ for (const entry of write ? texts : result.wrapped) {
543
+ const attr = entry.kind === "attribute" ? `${entry.attribute} -> ` : "";
544
+ lines.push(` ${entry.file}:${entry.line} ${attr}"${entry.text}"`);
545
+ }
546
+ if (result.skipped.length > 0) {
547
+ lines.push(" needs a human:");
548
+ for (const entry of result.skipped) lines.push(` ${entry.file}:${entry.line} "${entry.text}" (${entry.reason})`);
549
+ }
550
+ if (result.blocked.length > 0) {
551
+ lines.push(` nothing written in ${counted(result.blocked.length, "file")} with no t in scope:`);
552
+ for (const entry of result.blocked) {
553
+ const how = entry.client ? "\"use client\", so const t = useT()" : "no \"use client\"";
554
+ lines.push(` ${entry.file} ${counted(entry.texts, "text")}, ${how}`);
555
+ }
556
+ lines.push(" next: bind t there, run verbaly_wrap with write again, then verbaly_extract");
557
+ } else if (write && done.length > 0) lines.push(" next: run verbaly_extract");
558
+ return reply(lines.join("\n"), {
559
+ ...result,
560
+ write: write === true
561
+ });
562
+ }));
563
+ }
564
+ // src/tools/write-drafts.ts
565
+ function registerWriteDrafts(server, ctx) {
547
566
  server.registerTool("verbaly_write_drafts", {
548
567
  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 `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 runs `verbaly review --approve`.",
568
+ 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
569
  inputSchema: {
551
570
  root: rootInput,
552
571
  locale: z.string().describe("Target locale, one of the project's non-source locales"),
@@ -561,9 +580,10 @@ function createVerbalyMcp(options = {}) {
561
580
  kept: z.array(z.string()).describe("Already translated, left as they were (overwrite replaces them)"),
562
581
  invalid: z.array(z.string()).describe("Rejected: empty, or the params, tags or plural cases were not preserved"),
563
582
  unknown: z.array(z.string()).describe("Not in the source catalog, so nothing was written")
564
- }
565
- }, guarded(async ({ root, locale, entries, overwrite }) => {
566
- const cfg = await config(root);
583
+ },
584
+ annotations: writes(true)
585
+ }, ctx.guarded(async ({ root, locale, entries, overwrite }) => {
586
+ const cfg = await ctx.config(root);
567
587
  const registry = await extractProject(cfg);
568
588
  const result = writeDrafts(cfg, locale, entries, {
569
589
  overwrite,
@@ -576,43 +596,90 @@ function createVerbalyMcp(options = {}) {
576
596
  if (result.unknown.length > 0) lines.push(`${locale}: ${counted(result.unknown.length, "unknown key")} not in the source catalog: ${result.unknown.join(", ")}`);
577
597
  return reply(lines.length > 0 ? lines.join("\n") : "nothing to save", { ...result });
578
598
  }));
579
- server.registerTool("verbaly_drafts", {
580
- title: "Machine translations awaiting review",
581
- 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.",
582
- inputSchema: {
583
- root: rootInput,
584
- locales: z.array(z.string()).optional().describe("Target locales (default: all)")
585
- },
586
- outputSchema: {
587
- total: z.number(),
588
- entries: z.array(z.object({
589
- locale: z.string(),
590
- key: z.string(),
591
- source: z.string().describe("What the message says in the source locale"),
592
- translated: z.string().describe("What the provider wrote, still unreviewed")
593
- }))
594
- },
595
- annotations: { readOnlyHint: true }
596
- }, guarded(async ({ root, locales }) => {
597
- const cfg = await config(root);
598
- const catalogs = loadCatalogs(cfg);
599
- const source = shippedCatalogs(cfg, catalogs, await extractProject(cfg))[cfg.sourceLocale] ?? {};
600
- const pending = effectiveDrafts(loadState(cfg).drafts, catalogs);
601
- const wanted = locales ?? cfg.locales;
602
- const entries = Object.entries(pending).filter(([locale]) => wanted.includes(locale)).flatMap(([locale, keys]) => keys.map((key) => ({
603
- locale,
604
- key,
605
- source: source[key] ?? "",
606
- translated: catalogs[locale]?.[key] ?? ""
607
- })));
608
- const body = entries.length ? entries.map((e) => `[${e.locale}] ${e.key}
609
- source: ${e.source}
610
- draft: ${e.translated}`).join("\n") : "nothing awaiting review";
611
- return reply(body, {
612
- total: entries.length,
613
- entries
614
- });
615
- }));
599
+ }
600
+ // src/server.ts
601
+ const { version } = createRequire(import.meta.url)("../package.json");
602
+ function createVerbalyMcp(options = {}) {
603
+ const server = new McpServer({
604
+ name: "verbaly",
605
+ version
606
+ });
607
+ const config = (root) => loadConfig(root ?? options.root ?? process.cwd());
608
+ const guarded = (run) => async (args) => {
609
+ try {
610
+ return await run(args);
611
+ } catch (error) {
612
+ return {
613
+ content: [{
614
+ type: "text",
615
+ text: error instanceof Error ? error.message : String(error)
616
+ }],
617
+ isError: true
618
+ };
619
+ }
620
+ };
621
+ server.registerResource("verbaly-config", "verbaly://config", {
622
+ title: "Project shape",
623
+ 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.",
624
+ mimeType: "application/json"
625
+ }, async (uri) => {
626
+ const cfg = await config();
627
+ const shape = {
628
+ root: cfg.root,
629
+ sourceLocale: cfg.sourceLocale,
630
+ locales: cfg.locales,
631
+ localesDeclared: cfg.localesDeclared,
632
+ dir: cfg.dir,
633
+ routing: cfg.routing,
634
+ include: cfg.include
635
+ };
636
+ return { contents: [{
637
+ uri: uri.href,
638
+ mimeType: "application/json",
639
+ text: JSON.stringify(shape, null, 2)
640
+ }] };
641
+ });
642
+ server.registerResource("verbaly-catalog", new ResourceTemplate("verbaly://catalog/{locale}", { list: async () => {
643
+ return { resources: (await config()).locales.map((locale) => ({
644
+ name: `${locale} catalog`,
645
+ uri: `verbaly://catalog/${locale}`,
646
+ mimeType: "application/json"
647
+ })) };
648
+ } }), {
649
+ title: "Locale catalog",
650
+ 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.",
651
+ mimeType: "application/json"
652
+ }, async (uri, { locale }) => {
653
+ const cfg = await config();
654
+ const name = String(locale);
655
+ if (!cfg.locales.includes(name)) {
656
+ const have = cfg.locales.join(", ");
657
+ throw new Error(`[verbaly] unknown locale "${name}": the project has ${have}`);
658
+ }
659
+ const registry = await extractProject(cfg);
660
+ const catalog = shippedCatalogs(cfg, loadCatalogs(cfg), registry, { newKeys: false })[name] ?? {};
661
+ return { contents: [{
662
+ uri: uri.href,
663
+ mimeType: "application/json",
664
+ text: JSON.stringify(catalog, null, 2)
665
+ }] };
666
+ });
667
+ const ctx = {
668
+ root: options.root,
669
+ config,
670
+ guarded
671
+ };
672
+ for (const register of [
673
+ registerInit,
674
+ registerDoctor,
675
+ registerWrap,
676
+ registerExtract,
677
+ registerStatus,
678
+ registerMissing,
679
+ registerTranslate,
680
+ registerWriteDrafts,
681
+ registerDrafts
682
+ ]) register(server, ctx);
616
683
  return server;
617
684
  }
618
685
  export { createVerbalyMcp as t };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@verbaly/mcp",
3
- "version": "0.78.0",
3
+ "version": "0.80.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.78.0",
52
+ "@verbaly/compiler": "^0.80.0",
53
53
  "zod": "^4.6.7"
54
54
  },
55
55
  "devDependencies": {